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; }, // 退出系统