fix: `getUserinfo` is compatible with empty roles data
修复getUserinfo接口数据未携带roles字段时登录失败的问题
This commit is contained in:
parent
d27633fb31
commit
1ddfc31c3c
|
|
@ -14,6 +14,7 @@ import { router } from '/@/router';
|
||||||
import { usePermissionStore } from '/@/store/modules/permission';
|
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';
|
||||||
|
|
||||||
interface UserState {
|
interface UserState {
|
||||||
userInfo: Nullable<UserInfo>;
|
userInfo: Nullable<UserInfo>;
|
||||||
|
|
@ -118,10 +119,15 @@ export const useUserStore = defineStore({
|
||||||
},
|
},
|
||||||
async getUserInfoAction(): Promise<UserInfo> {
|
async getUserInfoAction(): Promise<UserInfo> {
|
||||||
const userInfo = await getUserInfo();
|
const userInfo = await getUserInfo();
|
||||||
const { roles } = userInfo;
|
const { roles = [] } = userInfo;
|
||||||
|
if (isArray(roles)) {
|
||||||
const roleList = roles.map((item) => item.value) as RoleEnum[];
|
const roleList = roles.map((item) => item.value) as RoleEnum[];
|
||||||
this.setUserInfo(userInfo);
|
|
||||||
this.setRoleList(roleList);
|
this.setRoleList(roleList);
|
||||||
|
} else {
|
||||||
|
userInfo.roles = [];
|
||||||
|
this.setRoleList([]);
|
||||||
|
}
|
||||||
|
this.setUserInfo(userInfo);
|
||||||
return userInfo;
|
return userInfo;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue