mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat(projects): add auth example
This commit is contained in:
@ -10,6 +10,7 @@ import { useSvgIcon } from '@/hooks/common/icon';
|
||||
* @param roles Roles
|
||||
*/
|
||||
export function filterAuthRoutesByRoles(routes: ElegantConstRoute[], roles: string[]) {
|
||||
// in static mode of auth route, the super admin role is defined in front-end
|
||||
const SUPER_ROLE = 'R_SUPER';
|
||||
|
||||
// if the user is super admin, then it is allowed to access all routes
|
||||
@ -30,9 +31,7 @@ function filterAuthRouteByRoles(route: ElegantConstRoute, roles: string[]) {
|
||||
const routeRoles = (route.meta && route.meta.roles) || [];
|
||||
|
||||
// if the route's "roles" is empty, then it is allowed to access
|
||||
if (!routeRoles.length) {
|
||||
return [route];
|
||||
}
|
||||
const isEmptyRoles = !routeRoles.length;
|
||||
|
||||
// if the user's role is included in the route's "roles", then it is allowed to access
|
||||
const hasPermission = routeRoles.some(role => roles.includes(role));
|
||||
@ -43,7 +42,7 @@ function filterAuthRouteByRoles(route: ElegantConstRoute, roles: string[]) {
|
||||
filterRoute.children = filterRoute.children.flatMap(item => filterAuthRouteByRoles(item, roles));
|
||||
}
|
||||
|
||||
return hasPermission ? [filterRoute] : [];
|
||||
return hasPermission || isEmptyRoles ? [filterRoute] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user