From 82238f8f216703691a42c9d42e86b11c5d04552f Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 29 Apr 2025 17:10:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86=EF=BC=8C=E9=80=80=E5=87=BA?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/app.ts | 8 +++++++- src/store/modules/user.ts | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/store/modules/app.ts b/src/store/modules/app.ts index b2664c3a..72d9bbe6 100644 --- a/src/store/modules/app.ts +++ b/src/store/modules/app.ts @@ -3,7 +3,7 @@ import { CACHE_LOCAL_I18N, CACHE_SESSION_CRYPTO_API, } from '@/constants/cache-keys-constants'; -import { RESULT_CODE_SUCCESS } from '@/constants/result-constants'; +import { RESULT_CODE_EXCEPTION, RESULT_CODE_SUCCESS } from '@/constants/result-constants'; import { delAccessToken, delRefreshToken } from '@/plugins/auth-token'; import { parseUrlPath } from '@/plugins/file-static-url'; import { localGet, localSet } from '@/utils/cache-local-utils'; @@ -132,6 +132,12 @@ const useAppStore = defineStore('app', { localSet(CACHE_LOCAL_I18N, this.i18nDefault); } } + // 网络错误时退出登录状态 + if (res.code === RESULT_CODE_EXCEPTION) { + delAccessToken(); + delRefreshToken(); + window.location.reload(); + } return res; }, }, diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 7af89458..025b1729 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -8,7 +8,7 @@ import { setRefreshToken, } from '@/plugins/auth-token'; import { defineStore } from 'pinia'; -import { RESULT_CODE_SUCCESS } from '@/constants/result-constants'; +import { RESULT_CODE_EXCEPTION, RESULT_CODE_SUCCESS } from '@/constants/result-constants'; import { parseUrlPath } from '@/plugins/file-static-url'; /**用户信息类型 */ @@ -154,6 +154,12 @@ const useUserStore = defineStore('user', { this.forcePasswdChange = true; } } + // 网络错误时退出登录状态 + if (res.code === RESULT_CODE_EXCEPTION) { + delAccessToken(); + delRefreshToken(); + window.location.reload(); + } return res; }, // 退出系统