From 63e7d3d5f51cca57089c2c581891d539be7e8039 Mon Sep 17 00:00:00 2001 From: chenchun Date: Tue, 5 Aug 2025 18:23:33 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E6=9B=B4=E6=96=B0=E4=B8=BB=E9=A2=982.?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Yi.Bbs.Vue3/src/App.vue | 2 +- Yi.Bbs.Vue3/src/utils/signalR.js | 62 ++++++++++++++-------------- Yi.Bbs.Vue3/src/views/home/Index.vue | 52 +++++++++++++++++++---- 3 files changed, 75 insertions(+), 41 deletions(-) diff --git a/Yi.Bbs.Vue3/src/App.vue b/Yi.Bbs.Vue3/src/App.vue index 6018d44c..a894ce1a 100644 --- a/Yi.Bbs.Vue3/src/App.vue +++ b/Yi.Bbs.Vue3/src/App.vue @@ -28,7 +28,7 @@ onMounted(async () => { //如果登录了,再连接消息通知 bbsNoticeSignalR(); - noticeSignalR(); + noticeSignalR(); }); diff --git a/Yi.Bbs.Vue3/src/utils/signalR.js b/Yi.Bbs.Vue3/src/utils/signalR.js index 3c7eb6a3..808a182f 100644 --- a/Yi.Bbs.Vue3/src/utils/signalR.js +++ b/Yi.Bbs.Vue3/src/utils/signalR.js @@ -4,41 +4,41 @@ import useAuths from "@/hooks/useAuths"; const { getToken } = useAuths(); export default { - SR: {}, - start(url,callFunc) { - const connection = new signalR.HubConnectionBuilder() - .withUrl(`${import.meta.env.VITE_APP_BASE_WS}/` + url, { - headers: { - Authorization: `Bearer ${getToken()}`, - }, - accessTokenFactory: () => { - // 返回授权 token - return `${getToken()}`; - }, - }) + SR: {}, + start(url, callFunc) { + const connection = new signalR.HubConnectionBuilder() + .withUrl(`${import.meta.env.VITE_APP_BASE_WS}/` + url, { + headers: { + Authorization: `Bearer ${getToken()}`, + }, + accessTokenFactory: () => { + // 返回授权 token + return `${getToken()}`; + }, + }) - .withAutomaticReconnect(new ForeverRetryPolicy()) //自动重新连接 - .configureLogging(signalR.LogLevel.Error) - .build(); - this.SR = connection; - // 断线重连 - connection.onclose(() => { - console.log("hub断开"); - }); + .withAutomaticReconnect(new ForeverRetryPolicy()) //自动重新连接 + .configureLogging(signalR.LogLevel.Error) + .build(); + this.SR = connection; + // 断线重连 + connection.onclose(() => { + console.log("hub断开"); + }); - connection.onreconnected(() => { - console.log("hub重新连接成功"); - }); - callFunc(connection); - // 启动 + connection.onreconnected(() => { + console.log("hub重新连接成功"); + }); + callFunc(connection); + // 启动 - this.SR.start(); - }, + this.SR.start(); + }, }; class ForeverRetryPolicy { - nextRetryDelayInMilliseconds(retryContext) { - return 1000*3; - } - + nextRetryDelayInMilliseconds(retryContext) { + return 1000 * 60; + } + } \ No newline at end of file diff --git a/Yi.Bbs.Vue3/src/views/home/Index.vue b/Yi.Bbs.Vue3/src/views/home/Index.vue index 9e2c34b0..77bf8245 100644 --- a/Yi.Bbs.Vue3/src/views/home/Index.vue +++ b/Yi.Bbs.Vue3/src/views/home/Index.vue @@ -43,7 +43,7 @@ margin: 10px auto;"> :isPublish="i.isDisableCreateDiscuss"/> -
+
@@ -106,7 +106,7 @@ margin: 10px auto;">
- + - +