feat: Improve the front-end and back-end permission mode and useAccess

This commit is contained in:
vben
2024-07-06 13:28:08 +08:00
parent 4dbd13d48d
commit 37a4f971c8
27 changed files with 522 additions and 79 deletions

View File

@@ -29,6 +29,10 @@ interface BasicUserInfo {
}
interface AccessState {
/**
* 权限码
*/
accessCodes: string[];
/**
* 可访问的菜单列表
*/
@@ -60,6 +64,9 @@ interface AccessState {
*/
const useCoreAccessStore = defineStore('core-access', {
actions: {
setAccessCodes(codes: string[]) {
this.accessCodes = codes;
},
setAccessMenus(menus: MenuRecordRaw[]) {
this.accessMenus = menus;
},
@@ -84,6 +91,9 @@ const useCoreAccessStore = defineStore('core-access', {
},
},
getters: {
getAccessCodes(): string[] {
return this.accessCodes;
},
getAccessMenus(): MenuRecordRaw[] {
return this.accessMenus;
},
@@ -102,12 +112,16 @@ const useCoreAccessStore = defineStore('core-access', {
getUserRoles(): string[] {
return this.userRoles;
},
string(): string[] {
return this.accessCodes;
},
},
persist: {
// 持久化
paths: ['accessToken', 'refreshToken'],
paths: ['accessToken', 'refreshToken', 'accessCodes'],
},
state: (): AccessState => ({
accessCodes: [],
accessMenus: [],
accessRoutes: [],
accessToken: null,