From 25b8acdda66b9629ff0bb84eb95e4ee29e0f94b2 Mon Sep 17 00:00:00 2001 From: wx <645899409@qq.com> Date: Fri, 23 May 2025 14:16:01 +0800 Subject: [PATCH] =?UTF-8?q?update=201.=E4=BF=AE=E6=94=B9websocket=EF=BC=8C?= =?UTF-8?q?=E5=A4=9A=E7=AA=97=E5=8F=A3=E5=8F=AF=E4=BB=A5=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/socket.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/socket.ts b/src/utils/socket.ts index b0fb26c..196c875 100644 --- a/src/utils/socket.ts +++ b/src/utils/socket.ts @@ -57,7 +57,7 @@ export function useSocket(p = basicPath, hasTimestamp: boolean = true) { //onmessage拿到返回的心跳就说明连接正常 if (socket.value.readyState === WebSocket.OPEN) { //console.log('连接正常' + new Date().toLocaleString()); - socket.value.send('ping'); + socket.value.send(`ping/${path.value.substring(path.value.lastIndexOf('/') + 1)}${socket.value.time}`); } else { //console.log('连接断开'); init(); @@ -72,6 +72,7 @@ export function useSocket(p = basicPath, hasTimestamp: boolean = true) { }; function init() { + const date = new Date().getTime(); if (!t) { return router?.replace('/login'); } @@ -82,11 +83,12 @@ export function useSocket(p = basicPath, hasTimestamp: boolean = true) { // 实例化socket //判断是否需要时间戳 if (hasTimestamp) { - socket.value = new WebSocket(path.value + Date.now(), [t]); + socket.value = new WebSocket(path.value + date, [t]); } else { - socket.value = new WebSocket(path.value, [t]); + socket.value = new WebSocket(path.value + date, [t]); } + socket.value['time'] = date; socket.value.onclose = function () { reconnect(path.value); // //console.log('连接关闭', new Date().toLocaleString());