diff --git a/src/components/AppLayout/AppLayout.vue b/src/components/AppLayout/AppLayout.vue index 4e06020..17e2771 100644 --- a/src/components/AppLayout/AppLayout.vue +++ b/src/components/AppLayout/AppLayout.vue @@ -60,6 +60,46 @@ function isActive(path: string): boolean { return path === '/' ? route.path === '/' : route.path.startsWith(path) } +/** + * 面包屑: 从当前 route.path 在菜单树里 DFS 追溯完整父级链 + * 返回 [一级目录, ..., 末级菜单], 不含"工作台"前缀(template 里单独拼) + * 找不到时 fallback 到 route.meta.title + */ +const breadcrumbItems = computed(() => { + const currentPath = route.path + // 工作台首页不显示中间层级 + if (currentPath === '/' || currentPath === '/dashboard') return [] + // DFS 找父级链 + function findChain(items: MenuItem[], target: string, chain: MenuItem[]): boolean { + for (const item of items) { + if (item.path === target || (item.path !== '/' && target.startsWith(item.path))) { + chain.push(item) + return true + } + if (item.children?.length) { + chain.push(item) + if (findChain(item.children, target, chain)) return true + chain.pop() + } + } + return false + } + const chain: MenuItem[] = [] + findChain(menuList.value, currentPath, chain) + const metaTitle = route.meta?.title as string | undefined + if (chain.length) { + const titles: string[] = chain.map(i => i.title) + const last = chain[chain.length - 1] + if (last.path !== currentPath) { + // 详情页: 命中的是父前缀, 追加 meta.title + return metaTitle ? [...titles, metaTitle] : titles + } + return titles + } + // 菜单树没命中 (如 /inquiry/:id 详情页), 用 meta.title 兜底 + return metaTitle ? [metaTitle] : [] +}) + const PARENT_GROUP: Record = { '概览': '概览', '业务': '业务', @@ -329,7 +369,7 @@ onMounted(loadBadges) 工作台 - {{ route.meta?.title || '' }} + {{ item }}