agent-pages.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. adminOnly: false,
  52. isChatPage: true,
  53. },
  54. {
  55. id: "internal-chat",
  56. label: "知识库测试",
  57. title: "知识库测试",
  58. Icon: Lightbulb,
  59. adminOnly: false,
  60. isChatPage: true,
  61. },
  62. {
  63. id: "knowledge",
  64. label: "知识库",
  65. title: "知识库",
  66. Icon: BookOpen,
  67. adminOnly: false,
  68. component: KnowledgePage,
  69. },
  70. {
  71. id: "faqs",
  72. label: "事件管理",
  73. title: "事件管理",
  74. Icon: ClipboardList,
  75. adminOnly: false,
  76. component: FAQsPage,
  77. },
  78. {
  79. id: "users",
  80. label: "用户管理",
  81. title: "用户管理",
  82. Icon: Users,
  83. adminOnly: true,
  84. component: UsersPage,
  85. },
  86. {
  87. id: "settings",
  88. label: "AI 配置",
  89. title: "AI 配置",
  90. Icon: Settings,
  91. adminOnly: false,
  92. component: SettingsPage,
  93. },
  94. ] as const;
  95. export type NavigationPage = (typeof AGENT_PAGES)[number]["id"];
  96. const VALID_PAGE_IDS = new Set<string>(AGENT_PAGES.map((p) => p.id));
  97. export function getPageFromSearchParams(searchParams: URLSearchParams | null): NavigationPage {
  98. const p = searchParams?.get("page") ?? null;
  99. if (p != null && VALID_PAGE_IDS.has(p)) return p as NavigationPage;
  100. return "dashboard";
  101. }
  102. export function getAgentPage(pageId: NavigationPage): AgentPageItem | undefined {
  103. return AGENT_PAGES.find((p) => p.id === pageId);
  104. }