diff --git a/src/utils/websocket.ts b/src/utils/websocket.ts index 90e86bf..0d5e9ee 100644 --- a/src/utils/websocket.ts +++ b/src/utils/websocket.ts @@ -115,18 +115,18 @@ export const sendMsg = (data: any) => { // socket 接收数据 export const websocketonmessage = () => { websocket.onmessage = function (e: any) { - const msg = JSON.parse(e.data) as any; - if (msg.type === 'heartbeat') { + if (e.data.indexOf('heartbeat') > 0) { resetHeart(); } - if (msg.type === 'ping') { + if (e.data.indexOf('ping') > 0) { return; } addNotice({ - message: msg, + message: e.data, read: false, time: new Date().toLocaleString() }); - return msg; + ElMessage.success(e.data); + return e.data; }; }; diff --git a/src/views/index.vue b/src/views/index.vue index 40c88a8..3bb7396 100644 --- a/src/views/index.vue +++ b/src/views/index.vue @@ -99,7 +99,7 @@ import { initWebSocket } from '@/utils/websocket'; onMounted(() => { - initWebSocket("ws://"+window.location.host+import.meta.env.VITE_APP_BASE_API+"/resource/websocket"); + initWebSocket("ws://" + window.location.host + import.meta.env.VITE_APP_BASE_API + "/resource/websocket"); }); const goTarget = (url:string) => {