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
|
* @description: getUserInfo
|
||||||
*/
|
*/
|
||||||
export function getUserInfo() {
|
export function getUserInfo() {
|
||||||
return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo });
|
return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPermCode() {
|
export function getPermCode() {
|
||||||
|
@ -15,6 +15,7 @@ import { usePermissionStore } from '/@/store/modules/permission';
|
|||||||
import { RouteRecordRaw } from 'vue-router';
|
import { RouteRecordRaw } from 'vue-router';
|
||||||
import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic';
|
import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic';
|
||||||
import { isArray } from '/@/utils/is';
|
import { isArray } from '/@/utils/is';
|
||||||
|
import { h } from 'vue';
|
||||||
|
|
||||||
interface UserState {
|
interface UserState {
|
||||||
userInfo: Nullable<UserInfo>;
|
userInfo: Nullable<UserInfo>;
|
||||||
@ -64,7 +65,7 @@ export const useUserStore = defineStore({
|
|||||||
this.roleList = roleList;
|
this.roleList = roleList;
|
||||||
setAuthCache(ROLES_KEY, roleList);
|
setAuthCache(ROLES_KEY, roleList);
|
||||||
},
|
},
|
||||||
setUserInfo(info: UserInfo) {
|
setUserInfo(info: UserInfo | null) {
|
||||||
this.userInfo = info;
|
this.userInfo = info;
|
||||||
this.lastUpdateTime = new Date().getTime();
|
this.lastUpdateTime = new Date().getTime();
|
||||||
setAuthCache(USER_INFO_KEY, info);
|
setAuthCache(USER_INFO_KEY, info);
|
||||||
@ -117,11 +118,12 @@ export const useUserStore = defineStore({
|
|||||||
router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw);
|
router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw);
|
||||||
permissionStore.setDynamicAddedRoute(true);
|
permissionStore.setDynamicAddedRoute(true);
|
||||||
}
|
}
|
||||||
goHome && (await router.replace(userInfo.homePath || PageEnum.BASE_HOME));
|
goHome && (await router.replace(userInfo?.homePath || PageEnum.BASE_HOME));
|
||||||
}
|
}
|
||||||
return userInfo;
|
return userInfo;
|
||||||
},
|
},
|
||||||
async getUserInfoAction(): Promise<UserInfo> {
|
async getUserInfoAction(): Promise<UserInfo | null> {
|
||||||
|
if (!this.getToken) return null;
|
||||||
const userInfo = await getUserInfo();
|
const userInfo = await getUserInfo();
|
||||||
const { roles = [] } = userInfo;
|
const { roles = [] } = userInfo;
|
||||||
if (isArray(roles)) {
|
if (isArray(roles)) {
|
||||||
@ -138,7 +140,7 @@ export const useUserStore = defineStore({
|
|||||||
* @description: logout
|
* @description: logout
|
||||||
*/
|
*/
|
||||||
async logout(goLogin = false) {
|
async logout(goLogin = false) {
|
||||||
if (this.token) {
|
if (this.getToken) {
|
||||||
try {
|
try {
|
||||||
await doLogout();
|
await doLogout();
|
||||||
} catch {
|
} catch {
|
||||||
@ -147,6 +149,7 @@ export const useUserStore = defineStore({
|
|||||||
}
|
}
|
||||||
this.setToken(undefined);
|
this.setToken(undefined);
|
||||||
this.setSessionTimeout(false);
|
this.setSessionTimeout(false);
|
||||||
|
this.setUserInfo(null);
|
||||||
goLogin && router.push(PageEnum.BASE_LOGIN);
|
goLogin && router.push(PageEnum.BASE_LOGIN);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -158,8 +161,8 @@ export const useUserStore = defineStore({
|
|||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
createConfirm({
|
createConfirm({
|
||||||
iconType: 'warning',
|
iconType: 'warning',
|
||||||
title: t('sys.app.logoutTip'),
|
title: () => h('span', t('sys.app.logoutTip')),
|
||||||
content: t('sys.app.logoutMessage'),
|
content: () => h('span', t('sys.app.logoutMessage')),
|
||||||
onOk: async () => {
|
onOk: async () => {
|
||||||
await this.logout(true);
|
await this.logout(true);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user