From 845d21ca70631bcceabb6ad780a56bad5c155432 Mon Sep 17 00:00:00 2001 From: hi2hi Date: Wed, 4 Dec 2024 14:17:49 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=B7=BB=E5=8A=A0=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E7=84=A6=E7=82=B9=E4=BA=8B=E4=BB=B6=E7=9B=91=E5=90=AC?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=20WebSocket=20=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/App.vue b/src/App.vue index dbf15fc..a1bc78f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -15,6 +15,8 @@ import sleep from '@/utils/sleep'; import LayoutMain from './layout/main.vue'; import activeWebsocketService, { + wsService, + restart, msg, } from './ws'; @@ -43,9 +45,11 @@ async function wsReconnect() { if (stopReconnect) { return; } + stopReconnect = true; await sleep(1000); console.log('reconnect ws'); activeWebsocketService(); + stopReconnect = false; } onMounted(async () => { @@ -65,6 +69,13 @@ onMounted(async () => { store.dispatch('watchWsMsg'); }); activeWebsocketService(); + + // 监听窗口重新获得焦点 + window.addEventListener('focus', () => { + if (wsService.connected !== 1) { + restart(); + } + }); }); window.addEventListener('unhandledrejection', (event) => {