From 54a76c6b4d1c9e8441686dae9c26e5c54c45dc04 Mon Sep 17 00:00:00 2001 From: "YUN-PC5\\user" Date: Wed, 22 Nov 2023 16:35:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=9A=E7=9F=A5=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E6=98=BE=E7=A4=BA=EF=BC=8C=E5=8F=AA=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=87=A0=E6=9D=A1=E6=B6=88=E6=81=AF=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=EF=BC=8C=E8=A7=A3=E5=86=B3token=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E5=90=8E=E5=8F=91=E8=AF=B7=E6=B1=82=E6=8A=A5401=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BC=9A=E5=A4=9A=E6=AC=A1=E5=BC=B9=E5=87=BA=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=8A=B6=E6=80=81=E5=B7=B2=E8=BF=87=E6=9C=9F=EF=BC=8C?= =?UTF-8?q?=E8=AF=B7=E9=87=8D=E6=96=B0=E7=99=BB=E5=BD=95=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/signalr/analysis.js | 13 +++++-------- src/store/modules/user.js | 3 ++- src/utils/request.js | 29 ++++++++++++++++++----------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/signalr/analysis.js b/src/signalr/analysis.js index 32858ec..b4abeed 100644 --- a/src/signalr/analysis.js +++ b/src/signalr/analysis.js @@ -26,17 +26,14 @@ export default { if (data.code == 200) { useSocketStore().setUnreadNoticeList(data.data.unReadNotifications) useSocketStore().setReadNoticeList(data.data.readNotifications) - data.data.unReadNotifications.forEach((ele) => { - const title = `来自${ele.create_name}的通知公告` + if (data.data.unReadNotifications.length > 0) { ElNotification({ - title: title, - message: ele.noticeContent, + title: import.meta.env.VITE_APP_TITLE, + message: `你有${data.data.unReadNotifications.length}条通知公告待查看`, type: 'success', - duration: 0, - dangerouslyUseHTMLString: true + duration: 0 }) - }) - webNotify({ title: import.meta.env.VITE_APP_TITLE, body: `你有${data.data.unReadNotifications.length}条通知公告待查看` }) + } } }) // 接受聊天数据 diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 39cf9dd..ddc76ef 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -12,7 +12,8 @@ const useUserStore = defineStore('user', { permissions: [], userId: 0, authSource: '', - userName: '' + userName: '', + lateFlag: 0 }), actions: { setAuthSource(source) { diff --git a/src/utils/request.js b/src/utils/request.js index 46c671f..64fb72c 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -49,19 +49,26 @@ service.interceptors.response.use( if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') { return res } - if (code == 401) { - ElMessageBox.confirm('登录状态已过期,请重新登录', '系统提示', { - confirmButtonText: '重新登录', - cancelButtonText: '取消', - type: 'warning' - }).then(() => { - useUserStore() - .logOut() + if (code === 401) { + if (useUserStore().lateFlag === 0) { + useUserStore().lateFlag++ + ElMessageBox.confirm('登录状态已过期,请重新登录', '系统提示', { + confirmButtonText: '重新登录', + cancelButtonText: '取消', + type: 'warning' + }) .then(() => { - location.href = import.meta.env.VITE_APP_ROUTER_PREFIX + 'index' + useUserStore().lateFlag = 0 + useUserStore() + .logOut() + .then(() => { + location.href = import.meta.env.VITE_APP_ROUTER_PREFIX + 'index' + }) }) - }) - + .catch(() => { + useUserStore().lateFlag = 0 + }) + } return Promise.reject('无效的会话,或者会话已过期,请重新登录。') } else if (code == 0 || code == 1 || code == 110 || code == 101 || code == 403 || code == 500 || code == 429) { ElMessage({