chore(auth): 解决ts 类型检查报错
This commit is contained in:
@@ -14,6 +14,10 @@ export namespace AuthApi {
|
|||||||
* 最后登录时间
|
* 最后登录时间
|
||||||
*/
|
*/
|
||||||
lastTime: string;
|
lastTime: string;
|
||||||
|
/**
|
||||||
|
* 角色列表
|
||||||
|
*/
|
||||||
|
role: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 登录接口返回值 */
|
/** 登录接口返回值 */
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ function setupAccessGuard(router: Router) {
|
|||||||
// 生成路由表
|
// 生成路由表
|
||||||
// 当前登录用户拥有的角色标识列表
|
// 当前登录用户拥有的角色标识列表
|
||||||
const userInfo = userStore.userInfo || (await authStore.fetchUserInfo());
|
const userInfo = userStore.userInfo || (await authStore.fetchUserInfo());
|
||||||
const userRoles = userInfo.roles ?? [];
|
const userRoles = userInfo?.roles ?? [];
|
||||||
|
|
||||||
// 生成菜单和路由
|
// 生成菜单和路由
|
||||||
const { accessibleMenus, accessibleRoutes } = await generateAccess({
|
const { accessibleMenus, accessibleRoutes } = await generateAccess({
|
||||||
@@ -109,7 +109,7 @@ function setupAccessGuard(router: Router) {
|
|||||||
accessStore.setIsAccessChecked(true);
|
accessStore.setIsAccessChecked(true);
|
||||||
const redirectPath = (from.query.redirect ??
|
const redirectPath = (from.query.redirect ??
|
||||||
(to.path === preferences.app.defaultHomePath
|
(to.path === preferences.app.defaultHomePath
|
||||||
? userInfo.homePath || preferences.app.defaultHomePath
|
? userInfo?.homePath || preferences.app.defaultHomePath
|
||||||
: to.fullPath)) as string;
|
: to.fullPath)) as string;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
// ]);
|
// ]);
|
||||||
|
|
||||||
userInfo = userEntity;
|
userInfo = userEntity;
|
||||||
|
userInfo.roles = userEntity.role ? [userEntity.role] : [];
|
||||||
|
|
||||||
userStore.setUserInfo(userInfo);
|
userStore.setUserInfo(userInfo);
|
||||||
// accessStore.setAccessCodes(accessCodes);
|
// accessStore.setAccessCodes(accessCodes);
|
||||||
|
|||||||
6
packages/@core/base/typings/src/basic.d.ts
vendored
6
packages/@core/base/typings/src/basic.d.ts
vendored
@@ -27,11 +27,15 @@ interface BasicUserInfo {
|
|||||||
/**
|
/**
|
||||||
* 用户角色
|
* 用户角色
|
||||||
*/
|
*/
|
||||||
role?: string;
|
roles?: string[];
|
||||||
/**
|
/**
|
||||||
* 用户状态
|
* 用户状态
|
||||||
*/
|
*/
|
||||||
state?: string;
|
state?: string;
|
||||||
|
/**
|
||||||
|
* 首页路径
|
||||||
|
*/
|
||||||
|
homePath?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClassType = Array<object | string> | object | string;
|
type ClassType = Array<object | string> | object | string;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ interface AccessState {
|
|||||||
/**
|
/**
|
||||||
* 用户角色
|
* 用户角色
|
||||||
*/
|
*/
|
||||||
userRoles: string;
|
userRoles: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,12 +22,12 @@ export const useUserStore = defineStore('core-user', {
|
|||||||
// 设置用户信息
|
// 设置用户信息
|
||||||
this.userInfo = userInfo;
|
this.userInfo = userInfo;
|
||||||
// 设置角色信息
|
// 设置角色信息
|
||||||
const roles = userInfo?.role ?? '';
|
const roles = userInfo?.roles ?? [];
|
||||||
// 存储信息到本地
|
// 存储信息到本地
|
||||||
localStorage.setItem('userInfo', JSON.stringify(userInfo));
|
localStorage.setItem('userInfo', JSON.stringify(userInfo));
|
||||||
this.setUserRoles(roles);
|
this.setUserRoles(roles);
|
||||||
},
|
},
|
||||||
setUserRoles(roles: string) {
|
setUserRoles(roles: string[]) {
|
||||||
this.userRoles = roles;
|
this.userRoles = roles;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user