origin/apps/web/src/routes/index.tsx

199 lines
4.3 KiB
TypeScript
Raw Normal View History

2024-07-11 11:00:51 +08:00
import {
2024-12-30 08:26:40 +08:00
createBrowserRouter,
IndexRouteObject,
Link,
NonIndexRouteObject,
2024-07-11 11:00:51 +08:00
} from "react-router-dom";
2025-01-06 08:45:23 +08:00
import { RolePerms } from "@nice/common";
2024-07-22 10:07:05 +08:00
import ErrorPage from "../app/error";
2024-09-10 10:31:24 +08:00
import DepartmentAdminPage from "../app/admin/department/page";
import TermAdminPage from "../app/admin/term/page";
2024-12-30 08:26:40 +08:00
import StaffAdminPage from "../app/admin/staff/page";
import RoleAdminPage from "../app/admin/role/page";
import WithAuth from "../components/utils/with-auth";
import LoginPage from "../app/login";
import BaseSettingPage from "../app/admin/base-setting/page";
2024-12-31 15:57:32 +08:00
import { CourseEditorPage } from "../app/main/course/editor/page";
import { MainLayout } from "../components/layout/main/MainLayout";
2025-01-03 09:24:46 +08:00
import StudentCoursesPage from "../app/main/courses/student/page";
import InstructorCoursesPage from "../app/main/courses/instructor/page";
import HomePage from "../app/main/home/page";
2024-09-10 10:31:24 +08:00
interface CustomIndexRouteObject extends IndexRouteObject {
2024-12-30 08:26:40 +08:00
name?: string;
breadcrumb?: string;
2024-09-10 10:31:24 +08:00
}
2024-12-30 08:26:40 +08:00
interface CustomIndexRouteObject extends IndexRouteObject {
name?: string;
breadcrumb?: string;
2024-09-10 10:31:24 +08:00
}
2024-12-30 08:26:40 +08:00
export interface CustomNonIndexRouteObject extends NonIndexRouteObject {
name?: string;
children?: CustomRouteObject[];
breadcrumb?: string;
handle?: {
crumb: (data?: any) => void;
};
}
export type CustomRouteObject =
| CustomIndexRouteObject
| CustomNonIndexRouteObject;
export const routes: CustomRouteObject[] = [
{
path: "/",
errorElement: <ErrorPage />,
handle: {
crumb() {
return <Link to={"/"}></Link>;
},
},
children: [
2024-12-31 15:57:32 +08:00
{
2025-01-03 09:24:46 +08:00
element: <MainLayout></MainLayout>,
children: [
{
index: true,
element: <HomePage />
},
{
path: "courses",
children: [
{
path: "student",
element: <WithAuth><StudentCoursesPage /></WithAuth>
},
{
path: "instructor",
element: <WithAuth><InstructorCoursesPage /></WithAuth>
}
]
}
]
2024-12-31 15:57:32 +08:00
},
{
path: "course",
children: [{
2025-01-03 09:24:46 +08:00
path: ":id?/manage", // 使用 ? 表示 id 参数是可选的
element: <CourseEditorPage />
2024-12-31 15:57:32 +08:00
}]
},
2024-12-30 08:26:40 +08:00
{
path: "admin",
children: [
{
path: "base-setting",
element: (
<WithAuth
options={{
orPermissions: [
RolePerms.MANAGE_BASE_SETTING,
],
}}>
<BaseSettingPage></BaseSettingPage>
</WithAuth>
),
handle: {
crumb() {
return (
<Link to={"/admin/base-setting"}>
</Link>
);
},
},
},
{
path: "department",
breadcrumb: "单位管理",
element: (
<WithAuth
options={{
orPermissions: [RolePerms.MANAGE_ANY_DEPT],
}}>
<DepartmentAdminPage></DepartmentAdminPage>
</WithAuth>
),
handle: {
crumb() {
return (
<Link to={"/admin/department"}>
</Link>
);
},
},
},
{
path: "staff",
element: (
<WithAuth
options={{
orPermissions: [
RolePerms.MANAGE_ANY_STAFF,
RolePerms.MANAGE_DOM_STAFF,
],
}}>
<StaffAdminPage></StaffAdminPage>
</WithAuth>
),
handle: {
crumb() {
return (
<Link to={"/admin/staff"}></Link>
);
},
},
},
{
path: "term",
breadcrumb: "分类配置",
element: (
<WithAuth
options={{
orPermissions: [
RolePerms.MANAGE_ANY_TERM,
// RolePerms.MANAGE_DOM_TERM
],
}}>
<TermAdminPage></TermAdminPage>
</WithAuth>
),
handle: {
crumb() {
return <Link to={"/admin/term"}></Link>;
},
},
},
{
path: "role",
breadcrumb: "角色管理",
element: (
<WithAuth
options={{
orPermissions: [
RolePerms.MANAGE_ANY_ROLE,
RolePerms.MANAGE_DOM_ROLE,
],
}}>
<RoleAdminPage></RoleAdminPage>
</WithAuth>
),
handle: {
crumb() {
return <Link to={"/admin/role"}></Link>;
},
},
},
],
},
],
},
{
path: "/login",
breadcrumb: "登录",
element: <LoginPage></LoginPage>,
},
];
2024-09-09 18:48:07 +08:00
2024-09-10 10:31:24 +08:00
export const router = createBrowserRouter(routes);