feat: allowAccessRoutes只存name

This commit is contained in:
rd
2025-07-09 16:37:25 +08:00
parent d903230c14
commit e93cdcec11
3 changed files with 8 additions and 8 deletions

View File

@ -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);
}

View File

@ -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));
},
},