update src/utils/websocket.ts.
将clearInterval改为(window as any).reliableClearInterval Signed-off-by: 周旭湘 <3423729430@qq.com>
This commit is contained in:
parent
4112779a86
commit
5a416aa7ef
@ -19,8 +19,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { getToken } from '@/utils/auth';
|
import { getToken } from '@/utils/auth';
|
||||||
import { ElNotification } from 'element-plus';
|
|
||||||
import useNoticeStore from '@/store/modules/notice';
|
import useNoticeStore from '@/store/modules/notice';
|
||||||
|
import { ElNotification } from "element-plus";
|
||||||
|
|
||||||
|
const { addNotice } = useNoticeStore();
|
||||||
|
|
||||||
let socketUrl: any = ''; // socket地址
|
let socketUrl: any = ''; // socket地址
|
||||||
let websocket: any = null; // websocket 实例
|
let websocket: any = null; // websocket 实例
|
||||||
@ -71,7 +73,7 @@ export const websocketclose = () => {
|
|||||||
export const resetHeart = () => {
|
export const resetHeart = () => {
|
||||||
socketHeart = 0;
|
socketHeart = 0;
|
||||||
socketError = 0;
|
socketError = 0;
|
||||||
clearInterval(heartTime);
|
(window as any).reliableClearInterval(heartTime);
|
||||||
sendSocketHeart();
|
sendSocketHeart();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -97,7 +99,7 @@ export const sendSocketHeart = () => {
|
|||||||
// socket重连
|
// socket重连
|
||||||
export const reconnect = () => {
|
export const reconnect = () => {
|
||||||
if (socketError <= 2) {
|
if (socketError <= 2) {
|
||||||
clearInterval(heartTime);
|
(window as any).reliableClearInterval(heartTime);
|
||||||
initWebSocket(socketUrl);
|
initWebSocket(socketUrl);
|
||||||
socketError = socketError + 1;
|
socketError = socketError + 1;
|
||||||
// eslint-disable-next-line prettier/prettier
|
// eslint-disable-next-line prettier/prettier
|
||||||
@ -105,7 +107,7 @@ export const reconnect = () => {
|
|||||||
} else {
|
} else {
|
||||||
// eslint-disable-next-line prettier/prettier
|
// eslint-disable-next-line prettier/prettier
|
||||||
console.log('重试次数已用完');
|
console.log('重试次数已用完');
|
||||||
clearInterval(heartTime);
|
(window as any).reliableClearInterval(heartTime);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -123,7 +125,7 @@ export const websocketonmessage = () => {
|
|||||||
if (e.data.indexOf('ping') > 0) {
|
if (e.data.indexOf('ping') > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
useNoticeStore().addNotice({
|
addNotice({
|
||||||
message: e.data,
|
message: e.data,
|
||||||
read: false,
|
read: false,
|
||||||
time: new Date().toLocaleString()
|
time: new Date().toLocaleString()
|
||||||
@ -133,7 +135,7 @@ export const websocketonmessage = () => {
|
|||||||
message: e.data,
|
message: e.data,
|
||||||
type: 'success',
|
type: 'success',
|
||||||
duration: 3000
|
duration: 3000
|
||||||
});
|
})
|
||||||
return e.data;
|
return e.data;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user