|
|
|
@ -79,6 +79,67 @@ export default { |
|
|
|
this.configStore.setAppInit(false); |
|
|
|
} |
|
|
|
}) |
|
|
|
wsApi.onMessage((cmd, msgInfo) => { |
|
|
|
if (cmd == 2) { |
|
|
|
// 异地登录 |
|
|
|
this.exit(); |
|
|
|
} else if (cmd == 3) { |
|
|
|
// 私聊消息 |
|
|
|
this.handlePrivateMessage(msgInfo); |
|
|
|
} else if (cmd == 4) { |
|
|
|
// 群聊消息 |
|
|
|
this.handleGroupMessage(msgInfo); |
|
|
|
} else if (cmd == 5) { |
|
|
|
// 系统消息 |
|
|
|
this.handleSystemMessage(msgInfo); |
|
|
|
} else if (cmd == 6) { |
|
|
|
// 新增:客服变更通知 |
|
|
|
this.handleCustomerChanged(msgInfo); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
// 处理客服变更 |
|
|
|
handleCustomerChanged(msgInfo) { |
|
|
|
console.log('客服已变更,刷新聊天记录:', msgInfo); |
|
|
|
|
|
|
|
// 刷新好友列表(会获取最新的客服信息) |
|
|
|
this.friendStore.loadFriend().then(() => { |
|
|
|
// 刷新聊天列表 |
|
|
|
this.chatStore.refreshChats(); |
|
|
|
|
|
|
|
// 如果当前正在聊天页面,重新加载消息 |
|
|
|
const pages = getCurrentPages(); |
|
|
|
const currentPage = pages[pages.length - 1]; |
|
|
|
|
|
|
|
if (currentPage.route === 'pages/chat/chat-box') { |
|
|
|
// 重新加载当前会话的消息 |
|
|
|
const targetId = currentPage.options.targetId; |
|
|
|
this.reloadChatMessages(targetId); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 重新加载聊天消息 |
|
|
|
reloadChatMessages(targetId) { |
|
|
|
// 找到对应的会话 |
|
|
|
const chat = this.chatStore.chats.find(c => |
|
|
|
c.targetId == targetId && c.type === 'PRIVATE' |
|
|
|
); |
|
|
|
|
|
|
|
if (chat) { |
|
|
|
// 清空消息 |
|
|
|
chat.messages = []; |
|
|
|
|
|
|
|
// 重新加载历史消息 |
|
|
|
this.$http({ |
|
|
|
url: `/message/private/history/${targetId}?full=true`, |
|
|
|
method: 'GET' |
|
|
|
}).then(messages => { |
|
|
|
messages.forEach(msg => { |
|
|
|
this.chatStore.insertMessage(msg, chat); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
}, |
|
|
|
loadStore() { |
|
|
|
return this.userStore.loadUser().then(() => { |
|
|
|
@ -144,6 +205,32 @@ export default { |
|
|
|
msg.selfSend = msg.sendId == this.userStore.userInfo.id; |
|
|
|
// 好友id |
|
|
|
let friendId = msg.selfSend ? msg.recvId : msg.sendId; |
|
|
|
// 检查是否为未知用户(只检查收到的消息) |
|
|
|
let existingFriend = this.friendStore.findFriend(friendId); |
|
|
|
if (!existingFriend && !msg.selfSend) { |
|
|
|
console.log("收到未知用户消息,刷新应用:", friendId); |
|
|
|
|
|
|
|
// 重新加载数据 |
|
|
|
this.loadStore().then(() => { |
|
|
|
// 刷新整个应用 |
|
|
|
// #ifdef H5 |
|
|
|
window.location.reload(); |
|
|
|
// #endif |
|
|
|
|
|
|
|
// #ifdef APP-PLUS |
|
|
|
plus.runtime.restart(); |
|
|
|
// #endif |
|
|
|
|
|
|
|
// #ifdef MP-WEIXIN |
|
|
|
// 小程序重新启动 |
|
|
|
uni.reLaunch({ |
|
|
|
url: '/pages/chat/chat' |
|
|
|
}); |
|
|
|
// #endif |
|
|
|
}); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
// 会话信息 |
|
|
|
let chatInfo = { |
|
|
|
type: 'PRIVATE', |
|
|
|
|