import { lazy, type ReactNode } from "react"; import { Soon } from "./components/Soon"; // 路由注册表 —— 控制台的单一事实源:导航 + 内容都从这里派生。 // 新增页面 = 在此加一条;real 页面用 lazy 懒加载(代码分割)。 const DashboardPage = lazy(() => import("./pages/DashboardPage").then((m) => ({ default: m.DashboardPage }))); const UsagePage = lazy(() => import("./pages/UsagePage").then((m) => ({ default: m.UsagePage }))); const ModelsPage = lazy(() => import("./pages/ModelsPage").then((m) => ({ default: m.ModelsPage }))); const DatasourcesPage = lazy(() => import("./pages/DatasourcesPage").then((m) => ({ default: m.DatasourcesPage }))); const StatusPage = lazy(() => import("./pages/StatusPage").then((m) => ({ default: m.StatusPage }))); const EvalsPage = lazy(() => import("./pages/EvalsPage").then((m) => ({ default: m.EvalsPage }))); const TenantsPage = lazy(() => import("./pages/TenantsPage").then((m) => ({ default: m.TenantsPage }))); const GuardrailsPage = lazy(() => import("./pages/GuardrailsPage").then((m) => ({ default: m.GuardrailsPage }))); const PromptsPage = lazy(() => import("./pages/PromptsPage").then((m) => ({ default: m.PromptsPage }))); const AuditPage = lazy(() => import("./pages/AuditPage").then((m) => ({ default: m.AuditPage }))); export interface RouteDef { path: string; label: string; group: string; ready?: boolean; element: ReactNode; } export const routes: RouteDef[] = [ { path: "/dashboard", label: "概览", group: "分析", ready: true, element: , }, { path: "/usage", label: "计费 & 用量", group: "分析", ready: true, element: , }, { path: "/models", label: "模型", group: "配置", ready: true, element: , }, { path: "/datasources", label: "数据源 & RAG", group: "配置", ready: true, element: , }, { path: "/prompts", label: "提示词", group: "配置", ready: true, element: , }, { path: "/status", label: "服务状态", group: "运维", ready: true, element: , }, { path: "/evals", label: "自动评测", group: "运维", ready: true, element: , }, { path: "/audit", label: "审计 & 安全", group: "运维", ready: true, element: , }, { path: "/tenants", label: "租户 & 用户", group: "平台", ready: true, element: , }, { path: "/guardrails", label: "安全护栏", group: "平台", ready: true, element: , }, ]; export const defaultPath = "/dashboard"; // 派生分组导航(保持注册顺序)。 export function navGroups(): Array<{ group: string; items: RouteDef[] }> { const out: Array<{ group: string; items: RouteDef[] }> = []; for (const r of routes) { let g = out.find((x) => x.group === r.group); if (!g) { g = { group: r.group, items: [] }; out.push(g); } g.items.push(r); } return out; }