From 1d5544d2dda6bab12ed1584413f22746430df739 Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Tue, 4 Nov 2025 10:02:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor(websocket):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=AE=A1=E6=97=B6=E5=99=A8=E7=B1=BB=E5=9E=8B=E5=A3=B0=E6=98=8E?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E4=BD=BF=E7=94=A8=20any=20=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/composables/websocket/useStomp.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/composables/websocket/useStomp.ts b/src/composables/websocket/useStomp.ts index 1f27872c..419b8400 100644 --- a/src/composables/websocket/useStomp.ts +++ b/src/composables/websocket/useStomp.ts @@ -41,9 +41,9 @@ export function useStomp(options: UseStompOptions = {}) { // 重连尝试次数 const reconnectCount = ref(0); // 重连计时器 - let reconnectTimer: any = null; + let reconnectTimer: ReturnType | null = null; // 连接超时计时器 - let connectionTimeoutTimer: any = null; + let connectionTimeoutTimer: ReturnType | null = null; // 存储所有订阅 const subscriptions = new Map(); @@ -105,8 +105,8 @@ export function useStomp(options: UseStompOptions = {}) { isConnected.value = true; isConnecting = false; reconnectCount.value = 0; - clearTimeout(connectionTimeoutTimer); - clearTimeout(reconnectTimer); + if (connectionTimeoutTimer) clearTimeout(connectionTimeoutTimer); + if (reconnectTimer) clearTimeout(reconnectTimer); console.log("WebSocket连接已建立"); }; @@ -255,7 +255,7 @@ export function useStomp(options: UseStompOptions = {}) { isConnecting = true; // 设置连接超时 - clearTimeout(connectionTimeoutTimer); + if (connectionTimeoutTimer) clearTimeout(connectionTimeoutTimer); connectionTimeoutTimer = setTimeout(() => { if (!isConnected.value && isConnecting) { console.warn("WebSocket连接超时");