From 5a416aa7efc3ae0447beb9aee7e90452cee75dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=97=AD=E6=B9=98?= <3423729430@qq.com> Date: Tue, 7 May 2024 10:44:12 +0000 Subject: [PATCH] =?UTF-8?q?update=20src/utils/websocket.ts.=20=E5=B0=86cle?= =?UTF-8?q?arInterval=E6=94=B9=E4=B8=BA(window=20as=20any).reliableClearIn?= =?UTF-8?q?terval?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周旭湘 <3423729430@qq.com> --- src/utils/websocket.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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; }; };