From 274d0664d943b4261268d30df059b5430662e91e Mon Sep 17 00:00:00 2001 From: lq Date: Mon, 9 Dec 2024 19:17:41 +0800 Subject: [PATCH] fix: route auth --- .../utils/src/helpers/generate-routes-frontend.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/utils/src/helpers/generate-routes-frontend.ts b/packages/utils/src/helpers/generate-routes-frontend.ts index dafc8a7d33a..75acf4956e1 100644 --- a/packages/utils/src/helpers/generate-routes-frontend.ts +++ b/packages/utils/src/helpers/generate-routes-frontend.ts @@ -21,13 +21,22 @@ async function generateRoutesByFrontend( // 如果有禁止访问的页面,将禁止访问的页面替换为403页面 return mapTree(finalRoutes, (route) => { - if (menuHasVisibleWithForbidden(route)) { + if (isForBidden(route, roles)) { route.component = forbiddenComponent; } return route; }); } +/** + * 判断是否禁止访问 + * @param route + * @returns + */ +function isForBidden (route: RouteRecordRaw, roles: string[]) { + return !!route.meta?.authority && !roles.some((role) => route.meta?.authority?.includes(role)); +} + /** * 判断路由是否有权限访问 * @param route