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

@ -21,7 +21,7 @@ export function configAutoImport() {
'@vueuse/core', '@vueuse/core',
{ {
dayjs: [['default', 'dayjs']], dayjs: [['default', 'dayjs']],
'lodash-es': ['cloneDeep', 'omit', 'pick', 'union', 'isNumber', 'uniqBy'], 'lodash-es': ['cloneDeep', 'omit', 'pick', 'union', 'uniq', 'isNumber', 'uniqBy'],
'@/hooks': ['useModal'], '@/hooks': ['useModal'],
}, },
], ],

View File

@ -6,6 +6,5 @@ export function checkRoutePermission(routeName: string) {
if (!routeName) return false; if (!routeName) return false;
const route = allowAccessRoutes.find((route) => route.name === routeName); return allowAccessRoutes.includes(routeName);
return !!route;
} }

View File

@ -18,7 +18,7 @@ interface UserInfo {
interface UserState { interface UserState {
token: string; token: string;
userInfo: UserInfo | null; userInfo: UserInfo | null;
allowAccessRoutes: RouteRecordNormalized[]; allowAccessRoutes: string[];
// isLogin: boolean; // isLogin: boolean;
} }
@ -81,17 +81,18 @@ export const useUserStore = defineStore('user', {
getUserAllowAccessRoutes() { getUserAllowAccessRoutes() {
const sidebarStore = useSidebarStore(); const sidebarStore = useSidebarStore();
const menuList = sidebarStore.menuList; const menuList = sidebarStore.menuList;
const appRoutes = router.getRoutes(); const appRoutes = router.getRoutes();
appRoutes.forEach((route: any) => { appRoutes.forEach((route: any) => {
if (!route.meta?.requiresAuth) { if (!route.meta?.requiresAuth) {
this.allowAccessRoutes.push(route); this.allowAccessRoutes.push(route.name);
} }
}); });
const pushAllowAccessRoutes = (pathNames: string[]) => { 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); 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)); slsWithCatch('allowAccessRoutes', JSON.stringify(this.allowAccessRoutes));
}, },
}, },