feat: 树状视图路径压缩 - 单子节点文件夹自动合并
文件夹只有 1 个子节点时合并名称, 避免不必要的层级展开:
- a:b:c:d (单个 key) 直接显示为 a:b:c:d 而非 4 层嵌套
- a:b:c + a:b:d 仍展开为 a > b > {c, d} (b 有 2 个子节点)
- a:b:c + a:d:e 显示为 a > {b:c, d:e} (b/d 各 1 子节点, 合并)
This commit is contained in:
@@ -452,7 +452,27 @@ const treeData = computed<TreeNode[]>(() => {
|
||||
updateCounts(node)
|
||||
}
|
||||
|
||||
return root
|
||||
// Compress: merge folders that have exactly 1 child into a single node
|
||||
// e.g. a > b > c (single key "a:b:c") becomes one leaf "a:b:c"
|
||||
function compress(nodes: TreeNode[]): TreeNode[] {
|
||||
return nodes.map(node => {
|
||||
if (node.isLeaf) return node
|
||||
const children = compress(node.children)
|
||||
if (children.length === 1) {
|
||||
const child = children[0]
|
||||
return {
|
||||
name: node.name + separator + child.name,
|
||||
fullPath: child.fullPath,
|
||||
isLeaf: child.isLeaf,
|
||||
children: child.children,
|
||||
count: child.count,
|
||||
}
|
||||
}
|
||||
return { ...node, children }
|
||||
})
|
||||
}
|
||||
|
||||
return compress(root)
|
||||
})
|
||||
|
||||
function isFolderExpanded(path: string): boolean {
|
||||
|
||||
Reference in New Issue
Block a user