update src/utils/websocket.ts.

将clearInterval改为(window as any).reliableClearInterval

Signed-off-by: 周旭湘 <3423729430@qq.com>
This commit is contained in:
周旭湘 2024-05-07 10:44:12 +00:00 committed by Gitee
parent 4112779a86
commit 5a416aa7ef
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -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;
};
};