| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- /**
- * 顶部大模块定义
- * 与路由 meta.module、菜单 module 字段、useAppStore.activeModule 联动
- */
- export enum ModuleKey {
- HOME = 'home',
- OTR = 'otr',
- SALES = 'sales',
- PROJECT = 'project',
- SALARY = 'salary',
- WEBSITE = 'website',
- }
- export interface ModuleDefinition {
- key: ModuleKey
- /** 顶部 tab 显示文案 */
- title: string
- /** 用于路径反查的根前缀(如 /home /otr /salary) */
- path: string
- /** 点击 tab 时实际跳转的入口路径(默认为 path,可被 entry 覆盖) */
- entry?: string
- /** 是否本期已实现,false 走占位页 */
- implemented: boolean
- /** 顶部 tab 图标(element plus icon name 或 svg name),可选 */
- icon?: string
- /** 该模块名下的所有路径前缀(用于路径反查 module,仅 sales 需要因为它没有统一前缀)*/
- pathPrefixes?: string[]
- }
- export const MODULE_LIST: ModuleDefinition[] = [
- { key: ModuleKey.HOME, title: '首页', path: '/home', entry: '/home/dashboard', implemented: true },
- { key: ModuleKey.OTR, title: 'OTR', path: '/otr', entry: '/otr/target/mine', implemented: true },
- // sales 模块迁自 sp-sales-management,保留原始路径(/index, /clue/*, /customer/* 等),
- // 因此用 pathPrefixes 显式列出销售业务下所有顶级路径,用于反查 module。
- {
- key: ModuleKey.SALES,
- title: '销售',
- path: '/index',
- entry: '/index',
- implemented: true,
- pathPrefixes: [
- '/index',
- '/clue',
- '/customer',
- '/business',
- '/order',
- '/orderForm',
- '/email',
- '/finance',
- '/refundRecord',
- '/statistics',
- '/bulletin',
- '/task',
- '/target',
- '/layout/notice',
- '/system/updatePwd',
- '/user',
- ],
- },
- { key: ModuleKey.PROJECT, title: '项目', path: '/project', implemented: false },
- { key: ModuleKey.SALARY, title: '工资', path: '/salary', implemented: false },
- { key: ModuleKey.WEBSITE, title: '官网', path: '/website', implemented: false },
- ]
- /** 通过路径匹配模块(用于路由切换时反查所属模块;仅作 fallback,优先用 route.meta.module) */
- export function resolveModuleByPath(path: string): ModuleKey {
- if (!path) return ModuleKey.HOME
- // 优先精确/前缀匹配(包含 pathPrefixes,按长度倒序避免短前缀误匹配)
- const candidates: Array<{ key: ModuleKey; prefix: string }> = []
- for (const m of MODULE_LIST) {
- candidates.push({ key: m.key, prefix: m.path })
- if (m.pathPrefixes) {
- for (const p of m.pathPrefixes) candidates.push({ key: m.key, prefix: p })
- }
- }
- candidates.sort((a, b) => b.prefix.length - a.prefix.length)
- const hit = candidates.find(c => path === c.prefix || path.startsWith(c.prefix + '/'))
- return hit?.key ?? ModuleKey.HOME
- }
- /** 通过 key 取定义 */
- export function getModuleDefinition(key: ModuleKey): ModuleDefinition | undefined {
- return MODULE_LIST.find(m => m.key === key)
- }
|