|
@@ -231,12 +231,11 @@ const sendMessage = async (contentType) => {
|
|
|
}
|
|
|
|
|
|
const newMessage = {
|
|
|
+ ...currentUser.value,
|
|
|
conversationRecordId: currentUser.value.conversationRecordId,
|
|
|
msgContent: messageInput.value,
|
|
|
msgSendTime: dayjs(new Date().getTime()).format('YYYY-MM-DD HH:MM:SS'),
|
|
|
msgType: contentType == 'text' ? '1' : '2',//消息类型 1文字消息 2图片消息
|
|
|
- userId: userId.value,
|
|
|
- senderId: userId.value,
|
|
|
system: 3,
|
|
|
}
|
|
|
|
|
@@ -304,7 +303,7 @@ let ws = null;
|
|
|
|
|
|
|
|
|
const soketInit = () => {
|
|
|
- ws = userStore.user.ws;
|
|
|
+ ws = userStore.ws;
|
|
|
console.log("TCL: soketInit -> ws", ws)
|
|
|
try {
|
|
|
// //获取账户时,连接soket
|
|
@@ -327,11 +326,15 @@ const soketInit = () => {
|
|
|
// })
|
|
|
// 监听消息事件
|
|
|
ws.on('message', (res) => {
|
|
|
- console.log('收到消息:', res)
|
|
|
- const data = JSON.parse(res.data);
|
|
|
- console.log("TCL: soketInit -> data", data)
|
|
|
+ console.log('收到消息:', res,res.type === 'msgNew')
|
|
|
+ // const data = JSON.parse(res.data);
|
|
|
+
|
|
|
if (res.type === 'msgNew') {
|
|
|
- currentMessages.value.push({ ...res.data })
|
|
|
+ console.log("TCL: soketInit -> data", res.data)
|
|
|
+ messages.value.push(res.data)
|
|
|
+ nextTick(() => {
|
|
|
+ scrollToBottom()
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -342,7 +345,7 @@ const soketInit = () => {
|
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
|
- soketInit();
|
|
|
+
|
|
|
getMList();//获取用户列表
|
|
|
|
|
|
setTimeout(() => {
|
|
@@ -350,6 +353,7 @@ onMounted(() => {
|
|
|
if (messageList.value) {
|
|
|
messageList.value.addEventListener('scroll', handleScroll)
|
|
|
}
|
|
|
+ soketInit();
|
|
|
}, 500)
|
|
|
})
|
|
|
|