feat: allowAccessRoutes只存name
This commit is contained in:
@ -6,6 +6,5 @@ export function checkRoutePermission(routeName: string) {
|
||||
|
||||
if (!routeName) return false;
|
||||
|
||||
const route = allowAccessRoutes.find((route) => route.name === routeName);
|
||||
return !!route;
|
||||
return allowAccessRoutes.includes(routeName);
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ interface UserInfo {
|
||||
interface UserState {
|
||||
token: string;
|
||||
userInfo: UserInfo | null;
|
||||
allowAccessRoutes: RouteRecordNormalized[];
|
||||
allowAccessRoutes: string[];
|
||||
// isLogin: boolean;
|
||||
}
|
||||
|
||||
@ -81,17 +81,18 @@ export const useUserStore = defineStore('user', {
|
||||
getUserAllowAccessRoutes() {
|
||||
const sidebarStore = useSidebarStore();
|
||||
const menuList = sidebarStore.menuList;
|
||||
|
||||
const appRoutes = router.getRoutes();
|
||||
|
||||
appRoutes.forEach((route: any) => {
|
||||
if (!route.meta?.requiresAuth) {
|
||||
this.allowAccessRoutes.push(route);
|
||||
this.allowAccessRoutes.push(route.name);
|
||||
}
|
||||
});
|
||||
|
||||
const pushAllowAccessRoutes = (pathNames: string[]) => {
|
||||
const matchedRoute = appRoutes.filter((route: any) => pathNames.includes(route.name));
|
||||
const matchedRoute = appRoutes
|
||||
.filter((route: any) => pathNames.includes(route.name))
|
||||
.map((route: any) => route.name);
|
||||
this.allowAccessRoutes.push(...matchedRoute);
|
||||
};
|
||||
|
||||
@ -105,7 +106,7 @@ export const useUserStore = defineStore('user', {
|
||||
}
|
||||
});
|
||||
|
||||
this.allowAccessRoutes = uniqBy(this.allowAccessRoutes, 'name');
|
||||
this.allowAccessRoutes = uniq(this.allowAccessRoutes);
|
||||
slsWithCatch('allowAccessRoutes', JSON.stringify(this.allowAccessRoutes));
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user