|
|
|
@ -42,7 +42,9 @@ export default { |
|
|
|
this.configStore.setAppInit(true); |
|
|
|
} |
|
|
|
}); |
|
|
|
// console.log(cmd, msgInfo); |
|
|
|
wsApi.onMessage((cmd, msgInfo) => { |
|
|
|
console.log(cmd, msgInfo); |
|
|
|
if (cmd == 2) { |
|
|
|
// 异地登录,强制下线 |
|
|
|
// uni.showModal({ |
|
|
|
@ -79,40 +81,17 @@ 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); |
|
|
|
// msgInfo 里自带:oldKfId 旧客服id、newKfId 新客服id |
|
|
|
const oldKfId = msgInfo.oldKfId; |
|
|
|
const newKfId = msgInfo.newKfId; |
|
|
|
|
|
|
|
// ========== 强制合并:旧客服所有消息 -> 新客服 ========== |
|
|
|
if (oldKfId && newKfId && oldKfId != newKfId) { |
|
|
|
const oldChat = this.chatStore.findChatByFriend(oldKfId); |
|
|
|
const newChat = this.chatStore.findChatByFriend(newKfId); |
|
|
|
|
|
|
|
if (oldChat && oldChat.messages.length > 0) { |
|
|
|
console.log('【开始强制合并】旧客服', oldKfId, '→ 新客服', newKfId); |
|
|
|
// 执行合并 |
|
|
|
this.chatStore.mergeOldCustomerToNew(oldKfId, newKfId); |
|
|
|
} |
|
|
|
@ -212,34 +191,40 @@ export default { |
|
|
|
}) |
|
|
|
}, |
|
|
|
handlePrivateMessage(msg) { |
|
|
|
// 标记这条消息是不是自己发的 |
|
|
|
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' |
|
|
|
if (!msg.selfSend) { |
|
|
|
let friend = this.friendStore.findFriend(friendId); |
|
|
|
if (!friend) { |
|
|
|
this.chatStore.forceMergeAllOldCustomerToNew(friendId); |
|
|
|
|
|
|
|
// 合并完成 → 强制刷新页面 |
|
|
|
uni.showToast({ |
|
|
|
title: "客服已更换,刷新中...", |
|
|
|
icon: "none", |
|
|
|
duration: 1500 |
|
|
|
}); |
|
|
|
// #endif |
|
|
|
}); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
// #ifdef H5 |
|
|
|
window.location.reload(); |
|
|
|
// #endif |
|
|
|
|
|
|
|
// #ifdef APP-PLUS |
|
|
|
plus.runtime.restart(); |
|
|
|
// #endif |
|
|
|
|
|
|
|
// #ifdef MP-WEIXIN |
|
|
|
uni.reLaunch({ |
|
|
|
url: '/pages/chat/chat' |
|
|
|
}); |
|
|
|
// #endif |
|
|
|
}, 800); |
|
|
|
|
|
|
|
// return; |
|
|
|
} |
|
|
|
} |
|
|
|
// 会话信息 |
|
|
|
let chatInfo = { |
|
|
|
@ -470,7 +455,6 @@ export default { |
|
|
|
return group; |
|
|
|
}, |
|
|
|
exit() { |
|
|
|
console.log("exit"); |
|
|
|
this.isExit = true; |
|
|
|
wsApi.close(3099); |
|
|
|
uni.removeStorageSync("loginInfo"); |
|
|
|
@ -543,7 +527,6 @@ export default { |
|
|
|
this.pullOfflineMessage(); |
|
|
|
this.configStore.setAppInit(true); |
|
|
|
}).catch((e) => { |
|
|
|
console.log(e); |
|
|
|
this.exit(); |
|
|
|
}) |
|
|
|
}, |
|
|
|
@ -585,14 +568,9 @@ export default { |
|
|
|
this.$nextTick(() => { |
|
|
|
const btn = document.querySelector('.btn-send'); |
|
|
|
if (btn) { |
|
|
|
console.log('按钮找到:', btn); |
|
|
|
// 获取所有事件监听器(需要浏览器支持) |
|
|
|
const listeners = getEventListeners?.(btn); |
|
|
|
console.log('按钮事件监听器:', listeners); |
|
|
|
|
|
|
|
// 手动绑定一个测试事件 |
|
|
|
btn.addEventListener('click', (e) => { |
|
|
|
console.log('原生点击事件触发'); |
|
|
|
this.sendTextMessage(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|