mirror of
https://github.com/vbenjs/gf-vben-admin.git
synced 2025-01-24 04:10:20 +08:00
fix: warning in logout action
修复退出登录相关代码中的警告
This commit is contained in:
parent
73dc492b2a
commit
b3307fe283
@ -29,7 +29,7 @@ export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal')
|
||||
* @description: getUserInfo
|
||||
*/
|
||||
export function getUserInfo() {
|
||||
return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo });
|
||||
return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
|
||||
}
|
||||
|
||||
export function getPermCode() {
|
||||
|
@ -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<UserInfo>;
|
||||
@ -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<UserInfo> {
|
||||
async getUserInfoAction(): Promise<UserInfo | null> {
|
||||
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);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user