workspace.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import type { ArticleType } from "./article";
  2. import { getRecentByUser } from "./recent";
  3. // 静态配置,前端维护,与 API 无关
  4. export type ModuleConfig = {
  5. key: string;
  6. title: string;
  7. titleZh: string;
  8. description: string;
  9. icon: string;
  10. path: string;
  11. color: string;
  12. bg: string;
  13. accent: string;
  14. };
  15. // API 只返回动态数据
  16. export type ModuleStats = {
  17. key: string;
  18. stats: string;
  19. };
  20. // 合并后传给组件
  21. export type ModuleItem = ModuleConfig & { stats: string };
  22. export type RecentItem = {
  23. id: string;
  24. title: string;
  25. subtitle: string;
  26. time: string;
  27. type: ArticleType;
  28. emoji: string;
  29. };
  30. // 静态配置写在前端
  31. export const MODULE_CONFIGS: ModuleConfig[] = [
  32. {
  33. key: "tipitaka",
  34. title: "Tipitaka",
  35. titleZh: "大藏经",
  36. description: "浏览与研读巴利文三藏经典,包含律藏、经藏与论藏。",
  37. icon: "BookOutlined",
  38. path: "/workspace/tipitaka/lib",
  39. color: "#b5854a",
  40. bg: "linear-gradient(135deg,rgba(253, 246, 236, 0.56) 0%,rgba(245, 230, 204, 0.51) 100%)",
  41. accent: "#8c6320",
  42. },
  43. {
  44. key: "article",
  45. title: "Article",
  46. titleZh: "文章",
  47. description: "撰写、整理与发布法义文章、学习笔记及研究报告。",
  48. icon: "FileTextOutlined",
  49. path: "/workspace/article",
  50. color: "#4a7fb5",
  51. bg: "linear-gradient(135deg,rgba(236, 243, 253, 0.52) 0%,rgba(204, 221, 245, 0.56) 100%)",
  52. accent: "#20508c",
  53. },
  54. {
  55. key: "task",
  56. title: "Task",
  57. titleZh: "任务",
  58. description: "管理个人修学计划、法务安排与日常待办事项。",
  59. icon: "CheckSquareOutlined",
  60. path: "/workspace/task",
  61. color: "#4ab58a",
  62. bg: "linear-gradient(135deg,rgba(236, 253, 246, 0.57) 0%,rgba(204, 240, 224, 0.57) 100%)",
  63. accent: "#1a7a56",
  64. },
  65. ];
  66. // API 只 fetch stats,TODO: 替换为真实接口
  67. export async function fetchModuleStats(): Promise<ModuleStats[]> {
  68. return [
  69. { key: "tipitaka", stats: "3 部 · 律经论" },
  70. { key: "article", stats: "24 篇文章" },
  71. { key: "task", stats: "5 项进行中" },
  72. ];
  73. }
  74. // 合并配置与动态数据
  75. export async function fetchModules(): Promise<ModuleItem[]> {
  76. const stats = await fetchModuleStats();
  77. const statsMap = Object.fromEntries(stats.map((s) => [s.key, s.stats]));
  78. return MODULE_CONFIGS.map((config) => ({
  79. ...config,
  80. stats: statsMap[config.key] ?? "",
  81. }));
  82. }
  83. export async function fetchRecentItems(userId: string): Promise<RecentItem[]> {
  84. const res = await getRecentByUser({ userId, pageSize: 10 });
  85. return res.data.rows.map((item) => ({
  86. id: item.article_id,
  87. title: item.title,
  88. subtitle: "Tipitaka · 律藏",
  89. time: item.updated_at,
  90. type: item.type,
  91. emoji: "📜",
  92. }));
  93. }