From acfb43ad74ad3beee8501cddf04451d353c44078 Mon Sep 17 00:00:00 2001 From: yinq Date: Fri, 5 Jun 2026 16:10:46 +0800 Subject: [PATCH] =?UTF-8?q?1.1.57=20=E9=A6=96=E9=A1=B5=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/resolveMenuPath.ts | 67 +++ src/views/index.vue | 881 ++++++++++++++++++++++++++++++++++- 2 files changed, 947 insertions(+), 1 deletion(-) create mode 100644 src/utils/resolveMenuPath.ts diff --git a/src/utils/resolveMenuPath.ts b/src/utils/resolveMenuPath.ts new file mode 100644 index 0000000..55b2744 --- /dev/null +++ b/src/utils/resolveMenuPath.ts @@ -0,0 +1,67 @@ +import router from '@/router'; + +/** + * 菜单 component 与业务页 router.push 路径对照(与动态菜单 path 可能不一致时的兜底) + */ +const ROUTE_FALLBACK: Record = { + 'workflow/task/taskWaiting': '/task/taskWaiting', + 'workflow/task/taskFinish': '/task/taskFinish', + 'workflow/task/taskCopyList': '/task/taskCopyList', + 'workflow/task/myDocument': '/task/myDocument', + 'oa/erp/timesheetInfo/index': '/timesheet/timesheetInfo', + 'oa/erp/projectReport/index': '/project/projectReport', + 'oa/erp/projectInfo/index': '/project/projectInfo', + 'oa/erp/contractInfo/index': '/contract/contractInfo', + 'oa/erp/orderLedger/contractOrderTodoIndex': '/contract/contractOrderTodo', + 'system/notice/index': '/system/notice', + 'user/profile': '/user/profile' +}; + +/** + * 根据菜单 component 字段解析可跳转的路由 path(需在登录后、动态路由已注册) + */ +export function resolveMenuPath(component: string): string | null { + if (!component) { + return null; + } + const normalized = component.replace(/^\//, '').replace(/\.vue$/, ''); + const withoutIndex = normalized.replace(/\/index$/, ''); + + const fallback = ROUTE_FALLBACK[normalized] ?? ROUTE_FALLBACK[withoutIndex]; + if (fallback && router.getRoutes().some((r) => r.path === fallback)) { + return fallback; + } + + const segments = withoutIndex.split('/'); + const leaf = segments[segments.length - 1] || ''; + const leafShort = leaf.replace(/Index$/, ''); + + let bestPath: string | null = null; + let bestScore = 0; + + for (const route of router.getRoutes()) { + const path = route.path; + if (!path || path === '/' || path.includes('redirect') || path.includes(':')) { + continue; + } + let score = 0; + if (path === `/${withoutIndex}` || path === `/${normalized}`) { + score = 200; + } else if (path.endsWith(`/${leaf}`) || path.endsWith(`/${leafShort}`)) { + score = 150; + } else if (path.includes(leafShort) && leafShort.length > 4) { + score = 100; + } else if (segments.length > 1 && segments.every((s) => path.includes(s))) { + score = 80; + } + if (score > bestScore || (score === bestScore && bestPath && path.length < bestPath.length)) { + bestScore = score; + bestPath = path; + } + } + + if (bestPath) { + return bestPath; + } + return fallback ?? null; +} diff --git a/src/views/index.vue b/src/views/index.vue index 09dec91..b4e4f79 100644 --- a/src/views/index.vue +++ b/src/views/index.vue @@ -1,13 +1,892 @@