refactor: 系统管理页面重构和ts类型声明优化
Former-commit-id: 40263bbb072596ada41ef33d9170841e7e66cd01
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { PermissionState } from '@/types';
|
||||
import { PermissionState } from '@/types/store/permission';
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { defineStore } from 'pinia';
|
||||
import { constantRoutes } from '@/router';
|
||||
@@ -12,7 +12,7 @@ const hasPermission = (roles: string[], route: RouteRecordRaw) => {
|
||||
if (roles.includes('ROOT')) {
|
||||
return true;
|
||||
}
|
||||
return roles.some(role => {
|
||||
return roles.some((role) => {
|
||||
if (route.meta?.roles !== undefined) {
|
||||
return (route.meta.roles as string[]).includes(role);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ export const filterAsyncRoutes = (
|
||||
roles: string[]
|
||||
) => {
|
||||
const res: RouteRecordRaw[] = [];
|
||||
routes.forEach(route => {
|
||||
routes.forEach((route) => {
|
||||
const tmp = { ...route } as any;
|
||||
if (hasPermission(roles, tmp)) {
|
||||
if (tmp.component == 'Layout') {
|
||||
@@ -53,7 +53,7 @@ const usePermissionStore = defineStore({
|
||||
id: 'permission',
|
||||
state: (): PermissionState => ({
|
||||
routes: [],
|
||||
addRoutes: []
|
||||
addRoutes: [],
|
||||
}),
|
||||
actions: {
|
||||
setRoutes(routes: RouteRecordRaw[]) {
|
||||
@@ -63,18 +63,18 @@ const usePermissionStore = defineStore({
|
||||
generateRoutes(roles: string[]) {
|
||||
return new Promise((resolve, reject) => {
|
||||
listRoutes()
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
const asyncRoutes = response.data;
|
||||
const accessedRoutes = filterAsyncRoutes(asyncRoutes, roles);
|
||||
this.setRoutes(accessedRoutes);
|
||||
resolve(accessedRoutes);
|
||||
})
|
||||
.catch(error => {
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default usePermissionStore;
|
||||
|
||||
Reference in New Issue
Block a user