Commit 3cde9213 authored by heduo's avatar heduo

feat(hd): 角色权限处理

parent f4797a18
export enum RoleEnum {
// super admin
SUPER = 'super',
const RoleEnum = {
JS0000: ['super', 'supplier'],
JS0001: ['supplier'],
};
// tester
TEST = 'test',
}
// const RoleNameEnum = {
// JS0000: '系统管理员',
// JS0001: '供应商',
// };
export { RoleEnum };
......@@ -20,7 +20,7 @@ import { h } from 'vue';
interface UserState {
userInfo: GetUserInfoModel;
token?: string;
roleList: RoleEnum[];
roleList: [];
sessionTimeout?: boolean;
lastUpdateTime: number;
}
......@@ -57,8 +57,8 @@ export const useUserStore = defineStore({
getTmallabToken(): string {
return getAuthCache<string>(TMALLAB_TOKEN_KEY);
},
getRoleList(): RoleEnum[] {
return this.roleList.length > 0 ? this.roleList : getAuthCache<RoleEnum[]>(ROLES_KEY);
getRoleList(): [] {
return this.roleList.length > 0 ? this.roleList : getAuthCache<[]>(ROLES_KEY);
},
getSessionTimeout(): boolean {
return !!this.sessionTimeout;
......@@ -75,7 +75,7 @@ export const useUserStore = defineStore({
setTmallabToken(info: string | undefined) {
setAuthCache(TMALLAB_TOKEN_KEY, info);
},
setRoleList(roleList: RoleEnum[]) {
setRoleList(roleList: []) {
this.roleList = roleList;
setAuthCache(ROLES_KEY, roleList);
},
......@@ -155,8 +155,9 @@ export const useUserStore = defineStore({
}
const { roles = [] } = userInfo;
if (isArray(roles)) {
const roleList = roles.map((item) => item.value) as RoleEnum[];
this.setRoleList(roleList);
const role = userInfo.roleNum;
const roleList = Array.from(RoleEnum[role]);
this.setRoleList(roleList as []);
} else {
userInfo.roles = [];
this.setRoleList([]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment