This commit is contained in:
2026-09-11 16:17:24 +08:00
parent 80e83a6668
commit ec7f76fede
18 changed files with 263 additions and 31 deletions
+35
View File
@@ -62,6 +62,41 @@ export function getFirstAccessiblePath(permissions: readonly string[]) {
return getNavigationLeaves(filterNavigationByPermissions(clientNavigation, permissions))[0]?.path ?? '/forbidden'
}
export interface ClientBreadcrumbItem {
title: string
path?: string
}
function findNavigationTrail(
nodes: readonly ClientNavigationNode[],
path: string,
parents: readonly ClientBreadcrumbItem[] = [],
): ClientBreadcrumbItem[] | undefined {
for (const node of nodes) {
if (isNavigationGroup(node)) {
const result = findNavigationTrail(node.children, path, [...parents, { title: node.title }])
if (result) return result
continue
}
if (node.path === path) return [...parents, { title: node.title, path: node.path }]
}
}
export function getRouteBreadcrumbs(path: string, currentTitle: string): ClientBreadcrumbItem[] {
const home: ClientBreadcrumbItem = { title: '首页', path: '/' }
if (path === '/') return [{ title: '首页' }]
const leaves = getNavigationLeaves(clientNavigation)
.filter((leaf) => leaf.path !== '/' && (path === leaf.path || path.startsWith(`${leaf.path}/`)))
.sort((left, right) => right.path.length - left.path.length)
const parentLeaf = leaves[0]
const trail = parentLeaf ? findNavigationTrail(clientNavigation, parentLeaf.path) ?? [] : []
const items = [home, ...trail]
if (items.at(-1)?.title !== currentTitle) items.push({ title: currentTitle })
if (items.length > 1) delete items.at(-1)!.path
return items
}
function findNavigationParentKeys(
nodes: readonly ClientNavigationNode[],
path: string,