mirror of
https://gitee.com/myxzgzs/boyue-ui-admin-vue3
synced 2025-08-08 16:32:43 +08:00
【缺陷修复】mall: 修复客服中心页面接收到消息时,重复调用了多次获取会话接口的问题
This commit is contained in:
parent
fef86bcc56
commit
39106843f3
@ -37,22 +37,22 @@ const { data, close, open } = useWebSocket(server.value, {
|
|||||||
})
|
})
|
||||||
|
|
||||||
/** 监听 WebSocket 数据 */
|
/** 监听 WebSocket 数据 */
|
||||||
watchEffect(() => {
|
watch(
|
||||||
if (!data.value) {
|
() => data.value,
|
||||||
return
|
(newData) => {
|
||||||
}
|
if (!newData) return
|
||||||
try {
|
try {
|
||||||
// 1. 收到心跳
|
// 1. 收到心跳
|
||||||
if (data.value === 'pong') {
|
if (newData === 'pong') return
|
||||||
return
|
|
||||||
}
|
|
||||||
// 2.1 解析 type 消息类型
|
// 2.1 解析 type 消息类型
|
||||||
const jsonMessage = JSON.parse(data.value)
|
const jsonMessage = JSON.parse(newData)
|
||||||
const type = jsonMessage.type
|
const type = jsonMessage.type
|
||||||
if (!type) {
|
if (!type) {
|
||||||
message.error('未知的消息类型:' + data.value)
|
message.error('未知的消息类型:' + newData)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.2 消息类型:KEFU_MESSAGE_TYPE
|
// 2.2 消息类型:KEFU_MESSAGE_TYPE
|
||||||
if (type === WebSocketMessageTypeConstants.KEFU_MESSAGE_TYPE) {
|
if (type === WebSocketMessageTypeConstants.KEFU_MESSAGE_TYPE) {
|
||||||
const message = JSON.parse(jsonMessage.content)
|
const message = JSON.parse(jsonMessage.content)
|
||||||
@ -62,6 +62,7 @@ watchEffect(() => {
|
|||||||
keFuChatBoxRef.value?.refreshMessageList(message)
|
keFuChatBoxRef.value?.refreshMessageList(message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.3 消息类型:KEFU_MESSAGE_ADMIN_READ
|
// 2.3 消息类型:KEFU_MESSAGE_ADMIN_READ
|
||||||
if (type === WebSocketMessageTypeConstants.KEFU_MESSAGE_ADMIN_READ) {
|
if (type === WebSocketMessageTypeConstants.KEFU_MESSAGE_ADMIN_READ) {
|
||||||
// 更新会话已读
|
// 更新会话已读
|
||||||
@ -70,7 +71,11 @@ watchEffect(() => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
|
{
|
||||||
|
immediate: false // 不立即执行
|
||||||
|
}
|
||||||
|
)
|
||||||
// ======================= WebSocket end =======================
|
// ======================= WebSocket end =======================
|
||||||
|
|
||||||
/** 加载指定会话的消息列表 */
|
/** 加载指定会话的消息列表 */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user