diff --git a/src/AuthRoute.tsx b/src/AuthRoute.tsx index fa7241d..0336fd1 100644 --- a/src/AuthRoute.tsx +++ b/src/AuthRoute.tsx @@ -1,7 +1,6 @@ import { PRODUCTION_NAME } from '@/constants/common.constants' import { getRedirectUrl } from '@/util/route' import { getLoginStatus, getVerifyStatus_async } from '@/util/auth' -import { Navigate } from 'react-router' const AuthRoute = () => { const [searchParams] = useSearchParams() diff --git a/src/global.d.ts b/src/global.d.ts index a950bd8..772a515 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -25,6 +25,7 @@ interface RouteJsonObject { menu?: boolean auth?: boolean permission?: boolean + operationCode?: string autoHide?: boolean children?: RouteJsonObject[] } diff --git a/src/pages/SystemFramework.tsx b/src/pages/SystemFramework.tsx index 6084d97..f0e616c 100644 --- a/src/pages/SystemFramework.tsx +++ b/src/pages/SystemFramework.tsx @@ -14,7 +14,8 @@ const SystemFramework = () => { {getSystemRouteJson().map((route) => { return ( - route.menu && ( + route.menu && + route.name && ( { text={route.name} key={route.id} > - {route.children?.map((subRoute) => ( - - ))} + {route.children?.map( + (subRoute) => + subRoute && + subRoute.name && ( + + ) + )} ) ) diff --git a/src/router/system.tsx b/src/router/system.tsx index 30f1f8e..58158e1 100644 --- a/src/router/system.tsx +++ b/src/router/system.tsx @@ -45,6 +45,7 @@ const system: RouteJsonObject[] = [ id: 'system-tools-index', component: lazy(() => import('@/pages/System/Tools')), name: '工具管理', + operationCode: 'system:tool:query:tool', menu: true, autoHide: true }, @@ -54,6 +55,7 @@ const system: RouteJsonObject[] = [ id: 'system-tools-template', component: lazy(() => import('@/pages/System/Tools/Template')), name: '模板管理', + operationCode: 'system:tool:query:template', menu: true, autoHide: true }, @@ -63,6 +65,7 @@ const system: RouteJsonObject[] = [ id: 'system-tools-base', component: lazy(() => import('@/pages/System/Tools/Base')), name: '基板管理', + operationCode: 'system:tool:query:base', menu: true, autoHide: true }, @@ -72,6 +75,7 @@ const system: RouteJsonObject[] = [ id: 'system-tools-category', component: lazy(() => import('@/pages/System/Tools/Category')), name: '类别管理', + operationCode: 'system:tool:query:category', menu: true, autoHide: true } diff --git a/src/util/route.tsx b/src/util/route.tsx index 0899079..caf8372 100644 --- a/src/util/route.tsx +++ b/src/util/route.tsx @@ -1,5 +1,4 @@ -import { RouteObject } from 'react-router' -import { hasPathPermission } from '@/util/auth' +import { hasPathPermission, hasPermission } from '@/util/auth' export const getRedirectUrl = (path: string, redirectUrl: string): string => { return `${path}?redirect=${encodeURIComponent(redirectUrl)}` @@ -18,12 +17,13 @@ export const getAuthRoute = ( route: RouteJsonObject[], parentPermission: boolean = false ): RouteJsonObject[] => { - return route + const temp = route .filter( (value) => value.path === '*' || !(value.permission || parentPermission) || - hasPathPermission(value.absolutePath) + (hasPathPermission(value.absolutePath) && + (!value.operationCode || hasPermission(value.operationCode))) ) .map((value) => { if (value.children) { @@ -31,6 +31,12 @@ export const getAuthRoute = ( } return value }) + temp.push({ + path: '', + absolutePath: '', + element: + }) + return temp } export const mapJsonToRoute = (jsonObject: RouteJsonObject[]): RouteObject[] => {