Optimize route
This commit is contained in:
@@ -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()
|
||||
|
||||
1
src/global.d.ts
vendored
1
src/global.d.ts
vendored
@@ -25,6 +25,7 @@ interface RouteJsonObject {
|
||||
menu?: boolean
|
||||
auth?: boolean
|
||||
permission?: boolean
|
||||
operationCode?: string
|
||||
autoHide?: boolean
|
||||
children?: RouteJsonObject[]
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ const SystemFramework = () => {
|
||||
<Sidebar.ItemList>
|
||||
{getSystemRouteJson().map((route) => {
|
||||
return (
|
||||
route.menu && (
|
||||
route.menu &&
|
||||
route.name && (
|
||||
<Sidebar.Item
|
||||
end={route.id === 'system' ? true : undefined}
|
||||
path={route.absolutePath}
|
||||
@@ -22,14 +23,18 @@ const SystemFramework = () => {
|
||||
text={route.name}
|
||||
key={route.id}
|
||||
>
|
||||
{route.children?.map((subRoute) => (
|
||||
<Sidebar.Item
|
||||
end
|
||||
path={subRoute.absolutePath}
|
||||
text={subRoute.name}
|
||||
key={subRoute.id}
|
||||
/>
|
||||
))}
|
||||
{route.children?.map(
|
||||
(subRoute) =>
|
||||
subRoute &&
|
||||
subRoute.name && (
|
||||
<Sidebar.Item
|
||||
end
|
||||
path={subRoute.absolutePath}
|
||||
text={subRoute.name}
|
||||
key={subRoute.id}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
</Sidebar.Item>
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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: <Navigate to={temp[0].absolutePath} replace />
|
||||
})
|
||||
return temp
|
||||
}
|
||||
|
||||
export const mapJsonToRoute = (jsonObject: RouteJsonObject[]): RouteObject[] => {
|
||||
|
||||
Reference in New Issue
Block a user