agent-pages.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. "use client";
  2. import dynamic from "next/dynamic";
  3. import type { ComponentType } from "react";
  4. import type { LucideIcon } from "lucide-react";
  5. import {
  6. MessageCircle,
  7. Lightbulb,
  8. BookOpen,
  9. ClipboardList,
  10. Users,
  11. Settings,
  12. } from "lucide-react";
  13. /** 嵌入在 dashboard 内的页面组件(懒加载) */
  14. const KnowledgePage = dynamic(
  15. () => import("@/app/agent/knowledge/page").then((mod) => ({ default: mod.default })),
  16. { ssr: false }
  17. );
  18. const FAQsPage = dynamic(
  19. () => import("@/app/agent/faqs/page").then((mod) => ({ default: mod.default })),
  20. { ssr: false }
  21. );
  22. const UsersPage = dynamic(
  23. () => import("@/app/agent/users/page").then((mod) => ({ default: mod.default })),
  24. { ssr: false }
  25. );
  26. const SettingsPage = dynamic(
  27. () => import("@/app/agent/settings/page").then((mod) => ({ default: mod.default })),
  28. { ssr: false }
  29. );
  30. export interface AgentPageItem {
  31. id: string;
  32. label: string;
  33. title: string;
  34. Icon: LucideIcon;
  35. adminOnly?: boolean;
  36. /** 对话类页面:展示会话列表 + 聊天区,无独立主内容 */
  37. isChatPage?: boolean;
  38. /** 非对话类页面的嵌入组件;对话类不填 */
  39. component?: ComponentType<{ embedded?: boolean }>;
  40. }
  41. /**
  42. * 客服端侧栏功能页配置(单一数据源)
  43. * 新增功能:在此数组增加一项即可,无需改 NavigationSidebar / DashboardShell 的罗列逻辑
  44. */
  45. export const AGENT_PAGES = [
  46. {
  47. id: "dashboard",
  48. label: "对话",
  49. title: "对话",
  50. Icon: MessageCircle,
  51. isChatPage: true,
  52. },
  53. {
  54. id: "internal-chat",
  55. label: "知识库测试",
  56. title: "知识库测试",
  57. Icon: Lightbulb,
  58. isChatPage: true,
  59. },
  60. {
  61. id: "knowledge",
  62. label: "知识库",
  63. title: "知识库",
  64. Icon: BookOpen,
  65. component: KnowledgePage,
  66. },
  67. {
  68. id: "faqs",
  69. label: "事件管理",
  70. title: "事件管理",
  71. Icon: ClipboardList,
  72. component: FAQsPage,
  73. },
  74. {
  75. id: "users",
  76. label: "用户管理",
  77. title: "用户管理",
  78. Icon: Users,
  79. adminOnly: true,
  80. component: UsersPage,
  81. },
  82. {
  83. id: "settings",
  84. label: "AI 配置",
  85. title: "AI 配置",
  86. Icon: Settings,
  87. component: SettingsPage,
  88. },
  89. ] as const;
  90. export type NavigationPage = (typeof AGENT_PAGES)[number]["id"];
  91. const VALID_PAGE_IDS = new Set(AGENT_PAGES.map((p) => p.id));
  92. export function getPageFromSearchParams(searchParams: URLSearchParams | null): NavigationPage {
  93. const p = searchParams?.get("page") ?? null;
  94. if (p && VALID_PAGE_IDS.has(p)) return p as NavigationPage;
  95. return "dashboard";
  96. }
  97. export function getAgentPage(pageId: NavigationPage): AgentPageItem | undefined {
  98. return AGENT_PAGES.find((p) => p.id === pageId);
  99. }