ModuleEnum.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * 顶部大模块定义
  3. * 与路由 meta.module、菜单 module 字段、useAppStore.activeModule 联动
  4. */
  5. export enum ModuleKey {
  6. HOME = 'home',
  7. OTR = 'otr',
  8. SALES = 'sales',
  9. PROJECT = 'project',
  10. SALARY = 'salary',
  11. WEBSITE = 'website',
  12. }
  13. export interface ModuleDefinition {
  14. key: ModuleKey
  15. /** 顶部 tab 显示文案 */
  16. title: string
  17. /** 用于路径反查的根前缀(如 /home /otr /salary) */
  18. path: string
  19. /** 点击 tab 时实际跳转的入口路径(默认为 path,可被 entry 覆盖) */
  20. entry?: string
  21. /** 是否本期已实现,false 走占位页 */
  22. implemented: boolean
  23. /** 顶部 tab 图标(element plus icon name 或 svg name),可选 */
  24. icon?: string
  25. /** 该模块名下的所有路径前缀(用于路径反查 module,仅 sales 需要因为它没有统一前缀)*/
  26. pathPrefixes?: string[]
  27. }
  28. export const MODULE_LIST: ModuleDefinition[] = [
  29. { key: ModuleKey.HOME, title: '首页', path: '/home', entry: '/home/dashboard', implemented: true },
  30. { key: ModuleKey.OTR, title: 'OTR', path: '/otr', entry: '/otr/target/mine', implemented: true },
  31. // sales 模块迁自 sp-sales-management,保留原始路径(/index, /clue/*, /customer/* 等),
  32. // 因此用 pathPrefixes 显式列出销售业务下所有顶级路径,用于反查 module。
  33. {
  34. key: ModuleKey.SALES,
  35. title: '销售',
  36. path: '/index',
  37. entry: '/index',
  38. implemented: true,
  39. pathPrefixes: [
  40. '/index',
  41. '/clue',
  42. '/customer',
  43. '/business',
  44. '/order',
  45. '/orderForm',
  46. '/email',
  47. '/finance',
  48. '/refundRecord',
  49. '/statistics',
  50. '/bulletin',
  51. '/task',
  52. '/target',
  53. '/layout/notice',
  54. '/system/updatePwd',
  55. '/user',
  56. ],
  57. },
  58. { key: ModuleKey.PROJECT, title: '项目', path: '/project', implemented: false },
  59. { key: ModuleKey.SALARY, title: '工资', path: '/salary', implemented: false },
  60. { key: ModuleKey.WEBSITE, title: '官网', path: '/website', implemented: false },
  61. ]
  62. /** 通过路径匹配模块(用于路由切换时反查所属模块;仅作 fallback,优先用 route.meta.module) */
  63. export function resolveModuleByPath(path: string): ModuleKey {
  64. if (!path) return ModuleKey.HOME
  65. // 优先精确/前缀匹配(包含 pathPrefixes,按长度倒序避免短前缀误匹配)
  66. const candidates: Array<{ key: ModuleKey; prefix: string }> = []
  67. for (const m of MODULE_LIST) {
  68. candidates.push({ key: m.key, prefix: m.path })
  69. if (m.pathPrefixes) {
  70. for (const p of m.pathPrefixes) candidates.push({ key: m.key, prefix: p })
  71. }
  72. }
  73. candidates.sort((a, b) => b.prefix.length - a.prefix.length)
  74. const hit = candidates.find(c => path === c.prefix || path.startsWith(c.prefix + '/'))
  75. return hit?.key ?? ModuleKey.HOME
  76. }
  77. /** 通过 key 取定义 */
  78. export function getModuleDefinition(key: ModuleKey): ModuleDefinition | undefined {
  79. return MODULE_LIST.find(m => m.key === key)
  80. }