feat: allowAccessRoutes只存name
This commit is contained in:
@ -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'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@ -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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user