diff --git a/CHANGELOG.zh_CN.md b/CHANGELOG.zh_CN.md index 2757cbcf5010f1e2ab05d586562e07f8943e8200..d8482205dca85d77a760267e4940316d2a091c4d 100644 --- a/CHANGELOG.zh_CN.md +++ b/CHANGELOG.zh_CN.md @@ -10,6 +10,7 @@ - **其它** - 修复部分封装组件在使用插槽时报错的问题 - 修复`useECharts`的`theme`参数不起作用的问题 + - 修复`Token`失效时,按 F5 刷新页面可能会出现页面加载异常的问题 ## 2.7.1(2021-08-16) diff --git a/src/router/guard/permissionGuard.ts b/src/router/guard/permissionGuard.ts index bbe28ef5aedab8c57802252230cf8ea78a19e118..09027b82d27c5a3b5f6614c6625cb36bd776fcd2 100644 --- a/src/router/guard/permissionGuard.ts +++ b/src/router/guard/permissionGuard.ts @@ -72,7 +72,12 @@ export function createPermissionGuard(router: Router) { // get userinfo while last fetch time is empty if (userStore.getLastUpdateTime === 0) { - await userStore.getUserInfoAction(); + try { + await userStore.getUserInfoAction(); + } catch (err) { + next(); + return; + } } if (permissionStore.getIsDynamicAddedRoute) { diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 67a6611ccc58c96b76f20ea16c001dd6ac8398aa..8b8a24bfaebc503abf467b42bd421ea287e44047 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -128,10 +128,12 @@ export const useUserStore = defineStore({ * @description: logout */ async logout(goLogin = false) { - try { - await doLogout(); - } catch { - console.log('注销Token失败'); + if (this.token) { + try { + await doLogout(); + } catch { + console.log('注销Token失败'); + } } this.setToken(undefined); this.setSessionTimeout(false); diff --git a/src/utils/http/axios/checkStatus.ts b/src/utils/http/axios/checkStatus.ts index 1c132ee766d497f0a2c79af57df38779dacfaad1..68c2ecfaf73f10d2ad4b42340d897295ea87dcd8 100644 --- a/src/utils/http/axios/checkStatus.ts +++ b/src/utils/http/axios/checkStatus.ts @@ -28,9 +28,9 @@ export function checkStatus( // Jump to the login page if not logged in, and carry the path of the current page // Return to the current page after successful login. This step needs to be operated on the login page. case 401: - errMessage = t('sys.api.errMsg401'); + userStore.setToken(undefined); + errMessage = msg || t('sys.api.errMsg401'); if (stp === SessionTimeoutProcessingEnum.PAGE_COVERAGE) { - userStore.setToken(undefined); userStore.setSessionTimeout(true); } else { userStore.logout(true);