diff --git a/src/utils/websocket.ts b/src/utils/websocket.ts index 8dac3ab..d319e4b 100644 --- a/src/utils/websocket.ts +++ b/src/utils/websocket.ts @@ -19,8 +19,10 @@ */ import { getToken } from '@/utils/auth'; -import { ElNotification } from 'element-plus'; import useNoticeStore from '@/store/modules/notice'; +import { ElNotification } from "element-plus"; + +const { addNotice } = useNoticeStore(); let socketUrl: any = ''; // socket地址 let websocket: any = null; // websocket 实例 @@ -71,7 +73,7 @@ export const websocketclose = () => { export const resetHeart = () => { socketHeart = 0; socketError = 0; - clearInterval(heartTime); + (window as any).reliableClearInterval(heartTime); sendSocketHeart(); }; @@ -97,7 +99,7 @@ export const sendSocketHeart = () => { // socket重连 export const reconnect = () => { if (socketError <= 2) { - clearInterval(heartTime); + (window as any).reliableClearInterval(heartTime); initWebSocket(socketUrl); socketError = socketError + 1; // eslint-disable-next-line prettier/prettier @@ -105,7 +107,7 @@ export const reconnect = () => { } else { // eslint-disable-next-line prettier/prettier console.log('重试次数已用完'); - clearInterval(heartTime); + (window as any).reliableClearInterval(heartTime); } }; @@ -123,7 +125,7 @@ export const websocketonmessage = () => { if (e.data.indexOf('ping') > 0) { return; } - useNoticeStore().addNotice({ + addNotice({ message: e.data, read: false, time: new Date().toLocaleString() @@ -133,7 +135,7 @@ export const websocketonmessage = () => { message: e.data, type: 'success', duration: 3000 - }); + }) return e.data; }; };