fix(F006-W18): 面包屑DFS修父菜单短路bug(集成管理>应用列表缺末级)
根因: resolveMenuItem 给父菜单 path = 第一个子菜单 path(如 集成管理.path = /openapi/app)。旧 DFS 用 path 前缀匹配短路命中父菜单, 不再递归子树, 导致 末级菜单标题丢失(只显示 工作台 > 集成管理, 缺 应用列表)。 修法: 父节点(有 children)优先递归子树, 子树没命中才考虑父节点 path 前缀 匹配(详情页场景)。叶子节点走 path 精确匹配。
This commit is contained in:
parent
978058c543
commit
a59c934fd7
@ -69,18 +69,28 @@ const breadcrumbItems = computed<string[]>(() => {
|
||||
const currentPath = route.path
|
||||
// 工作台首页不显示中间层级
|
||||
if (currentPath === '/' || currentPath === '/dashboard') return []
|
||||
// DFS 找父级链
|
||||
// DFS 找父级链: 父菜单(有 children)的 path 是第一个子菜单的 path(见
|
||||
// resolveMenuItem), 不能用 path 前缀短路命中父菜单, 必须先递归子树,
|
||||
// 子树没命中才考虑父菜单自身。
|
||||
function findChain(items: MenuItem[], target: string, chain: MenuItem[]): boolean {
|
||||
for (const item of items) {
|
||||
if (item.path === target || (item.path !== '/' && target.startsWith(item.path))) {
|
||||
// 叶子节点: path 精确匹配
|
||||
if (!item.children?.length) {
|
||||
if (item.path === target) {
|
||||
chain.push(item)
|
||||
return true
|
||||
}
|
||||
continue
|
||||
}
|
||||
// 父节点: 先递归子树
|
||||
chain.push(item)
|
||||
if (findChain(item.children, target, chain)) return true
|
||||
chain.pop()
|
||||
// 子树没命中, 看父节点自身 path 是否是 target 的前缀(详情页场景)
|
||||
if (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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user