【功能完善】商城: 客服消息JSON 化

pull/584/head
puhui999 2024-11-10 18:09:22 +08:00
parent b9e1529623
commit 5e7afae972
1 changed files with 4 additions and 2 deletions

View File

@ -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)