diff --git a/apps/dmp/src/components/Layout/Menu/index.tsx b/apps/dmp/src/components/Layout/Menu/index.tsx index 4b408c1..527b042 100644 --- a/apps/dmp/src/components/Layout/Menu/index.tsx +++ b/apps/dmp/src/components/Layout/Menu/index.tsx @@ -1,9 +1,10 @@ -import { MenuItem, RoleNameType, roleMenusMapping } from "./roleMenu.config"; +import { MenuItem, roleMenusMapping } from "./roleMenu.config"; import { UserService } from "@@/domain/User/UserService"; import { useEffect, useState } from "react"; import { observer } from "mobx-react-lite"; import { useNavigate } from "react-router"; import { Menu, Spin } from "antd"; +import { ROLE_NAME } from "@/constant"; export const useMenu = () => { const navigate = useNavigate(); @@ -20,7 +21,7 @@ export const useMenu = () => { let menuItems: MenuItem[] = []; for (const key in roleMenusMapping) if (roleNames.includes(key)) - menuItems = roleMenusMapping[key as RoleNameType]; + menuItems = roleMenusMapping[key as ROLE_NAME]; return ( navigate(e.key)} diff --git a/apps/dmp/src/components/Layout/Menu/roleMenu.config.tsx b/apps/dmp/src/components/Layout/Menu/roleMenu.config.tsx index 0c2ec39..c924dda 100644 --- a/apps/dmp/src/components/Layout/Menu/roleMenu.config.tsx +++ b/apps/dmp/src/components/Layout/Menu/roleMenu.config.tsx @@ -1,4 +1,4 @@ -import { ROLE_NAME } from "@/config"; +import { ROLE_NAME } from "@/constant"; import { CloudUploadOutlined, DatabaseOutlined, diff --git a/apps/dmp/src/modules/Admin/index.tsx b/apps/dmp/src/modules/Admin/index.tsx index 42ee0c7..6b44596 100644 --- a/apps/dmp/src/modules/Admin/index.tsx +++ b/apps/dmp/src/modules/Admin/index.tsx @@ -1,7 +1,14 @@ +import { Outlet } from "react-router"; + interface AdminDashboardProps { children?: JSX.Element; } export const AdminDashboard = (props: AdminDashboardProps) => { - return
AdminDashboard
; + return ( +
+

AdminDashboard

+ +
+ ); }; diff --git a/apps/dmp/src/modules/Annotator/index.tsx b/apps/dmp/src/modules/Annotator/index.tsx index 5da46fe..64431e2 100644 --- a/apps/dmp/src/modules/Annotator/index.tsx +++ b/apps/dmp/src/modules/Annotator/index.tsx @@ -1,7 +1,14 @@ +import { Outlet } from "react-router"; + interface AnnotatorDashBoardProps { children?: JSX.Element; } export const AnnotatorDashBoard = (props: AnnotatorDashBoardProps) => { - return
AnnotatorDashBoard
-} + return ( +
+

AnnotatorDashBoard

+ +
+ ); +}; diff --git a/apps/dmp/src/router/index.tsx b/apps/dmp/src/router/index.tsx index 61c02f4..ed62ee7 100644 --- a/apps/dmp/src/router/index.tsx +++ b/apps/dmp/src/router/index.tsx @@ -1,5 +1,12 @@ import { useDomain } from "@/hook/useDomain"; -import { BrowserRouter, Route, Routes, useLocation } from "react-router-dom"; +import { + BrowserRouter, + Route, + RouteObject, + Routes, + useLocation, + useRoutes, +} from "react-router-dom"; import { baseRoutes } from "./baseRoutes"; import { roleRoutes } from "./roleRoutes"; import { RouteGuard } from "./Guard"; @@ -33,15 +40,21 @@ export const RouterElements = observer(() => { ); if (currentRoute) document.title = currentRoute.title || defaultDocumentTitle; + /** + * 递归children + */ + const generateRoutes = (routes: (RouteObject & ExpandRouteProps)[]) => + routes.map((r) => ( + + {r.children && generateRoutes(r.children)} + + )); + return ( r.path!)}> - {currentRoutes.map((r) => ( - - ))} - {baseRoutes.map((r) => ( - - ))} + {generateRoutes(currentRoutes)} + {generateRoutes(baseRoutes)} ); diff --git a/apps/dmp/src/router/roleRoutes.tsx b/apps/dmp/src/router/roleRoutes.tsx index a16ec7b..36885b3 100644 --- a/apps/dmp/src/router/roleRoutes.tsx +++ b/apps/dmp/src/router/roleRoutes.tsx @@ -4,6 +4,8 @@ import { DicomUpload } from "@/modules/Admin/Dicom/Upload"; import { Navigate, RouteObject } from "react-router-dom"; import { ExpandRouteProps } from "."; import { ROLE_NAME } from "@/constant"; +import { AdminDashboard } from "@/modules/Admin"; +import { AnnotatorDashBoard } from "@/modules/Annotator"; export const roleRoutes: Record = { @@ -11,7 +13,21 @@ export const roleRoutes: Record = * 管理员 */ [ROLE_NAME.ADMIN]: [ - { path: "/", element: , title: "管理员" }, + { + path: "/", + element: , + title: "管理员", + children: [ + { + path: "/", + element: , + }, + { + path: "/list", + element: , + }, + ], + }, { path: "/list", element: , @@ -29,7 +45,8 @@ export const roleRoutes: Record = [ROLE_NAME.ANNOTATOR]: [ { path: "/", - element: , + // element: , + element: , title: "标注", }, {