From b3307fe2836fb6f9806d602d5bdb7e540c49f1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E6=9C=A8?= Date: Sat, 11 Sep 2021 11:08:34 +0800 Subject: [PATCH] fix: warning in logout action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复退出登录相关代码中的警告 --- src/api/sys/user.ts | 2 +- src/store/modules/user.ts | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/api/sys/user.ts b/src/api/sys/user.ts index da9f7a29..1e883b6d 100644 --- a/src/api/sys/user.ts +++ b/src/api/sys/user.ts @@ -29,7 +29,7 @@ export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') * @description: getUserInfo */ export function getUserInfo() { - return defHttp.get({ url: Api.GetUserInfo }); + return defHttp.get({ url: Api.GetUserInfo }, { errorMessageMode: 'none' }); } export function getPermCode() { diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 59d56b22..b0c43f8d 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -15,6 +15,7 @@ import { usePermissionStore } from '/@/store/modules/permission'; import { RouteRecordRaw } from 'vue-router'; import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic'; import { isArray } from '/@/utils/is'; +import { h } from 'vue'; interface UserState { userInfo: Nullable; @@ -64,7 +65,7 @@ export const useUserStore = defineStore({ this.roleList = roleList; setAuthCache(ROLES_KEY, roleList); }, - setUserInfo(info: UserInfo) { + setUserInfo(info: UserInfo | null) { this.userInfo = info; this.lastUpdateTime = new Date().getTime(); setAuthCache(USER_INFO_KEY, info); @@ -117,11 +118,12 @@ export const useUserStore = defineStore({ router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw); permissionStore.setDynamicAddedRoute(true); } - goHome && (await router.replace(userInfo.homePath || PageEnum.BASE_HOME)); + goHome && (await router.replace(userInfo?.homePath || PageEnum.BASE_HOME)); } return userInfo; }, - async getUserInfoAction(): Promise { + async getUserInfoAction(): Promise { + if (!this.getToken) return null; const userInfo = await getUserInfo(); const { roles = [] } = userInfo; if (isArray(roles)) { @@ -138,7 +140,7 @@ export const useUserStore = defineStore({ * @description: logout */ async logout(goLogin = false) { - if (this.token) { + if (this.getToken) { try { await doLogout(); } catch { @@ -147,6 +149,7 @@ export const useUserStore = defineStore({ } this.setToken(undefined); this.setSessionTimeout(false); + this.setUserInfo(null); goLogin && router.push(PageEnum.BASE_LOGIN); }, @@ -158,8 +161,8 @@ export const useUserStore = defineStore({ const { t } = useI18n(); createConfirm({ iconType: 'warning', - title: t('sys.app.logoutTip'), - content: t('sys.app.logoutMessage'), + title: () => h('span', t('sys.app.logoutTip')), + content: () => h('span', t('sys.app.logoutMessage')), onOk: async () => { await this.logout(true); },