From 5e7afae972fe848719c1670bfa157d8777f57d17 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sun, 10 Nov 2024 18:09:22 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E3=80=91=E5=95=86=E5=9F=8E:=20=E5=AE=A2=E6=9C=8D=E6=B6=88?= =?UTF-8?q?=E6=81=AFJSON=20=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/mall/promotion/kefu/index.vue | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/views/mall/promotion/kefu/index.vue b/src/views/mall/promotion/kefu/index.vue index 35778766..553f69c2 100644 --- a/src/views/mall/promotion/kefu/index.vue +++ b/src/views/mall/promotion/kefu/index.vue @@ -16,6 +16,7 @@ import { KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation' import { getRefreshToken } from '@/utils/auth' import { useWebSocket } from '@vueuse/core' import { useMallKefuStore } from '@/store/modules/mall/kefu' +import { jsonParse } from '@/utils' defineOptions({ name: 'KeFu' }) @@ -30,6 +31,7 @@ const server = ref( ) // WebSocket 服务地址 /** 发起 WebSocket 连接 */ +// TODO puhui999: websocket 连接有点问题收不到消息 🤣 const { data, close, open } = useWebSocket(server.value, { autoReconnect: true, heartbeat: true @@ -45,9 +47,9 @@ watchEffect(() => { if (data.value === 'pong') { return } - // 2.1 解析 type 消息类型 const jsonMessage = JSON.parse(data.value) + console.log(jsonMessage) const type = jsonMessage.type if (!type) { message.error('未知的消息类型:' + data.value) @@ -65,7 +67,7 @@ watchEffect(() => { // 2.3 消息类型:KEFU_MESSAGE_ADMIN_READ if (type === WebSocketMessageTypeConstants.KEFU_MESSAGE_ADMIN_READ) { // 更新会话已读 - kefuStore.updateConversationStatus(JSON.parse(jsonMessage.content)) + kefuStore.updateConversationStatus(jsonParse(jsonMessage.content)) } } catch (error) { console.error(error)