Files
dbx/apps/desktop/src/composables/useFlatTree.ts
T
zipgandstaff 1cd3406e94 修复驱动管理与侧边栏展开的前台显示问题
* 修复标签页切换和侧边栏展开滚动

* chore: rerun ci

---------

Co-authored-by: staff <staff@qimaos-MacBook-Pro.local>
2026-06-24 14:08:58 +08:00

32 lines
824 B
TypeScript

import type { TreeNode, TreeNodeType } from "@/types/database";
export const SIDEBAR_TREE_ROW_HEIGHT = 28;
export const SIDEBAR_TREE_SCROLL_BUFFER = 600;
export const SIDEBAR_TREE_PRERENDER_COUNT = 48;
export interface FlatTreeNode {
node: TreeNode;
depth: number;
id: string;
type: TreeNodeType;
}
function walk(children: TreeNode[], depth: number, result: FlatTreeNode[]) {
for (const node of children) {
result.push({ node, depth, id: node.id, type: node.type });
if (node.isExpanded && node.children) {
walk(node.children, depth + 1, result);
}
}
}
export function flattenTree(nodes: TreeNode[]): FlatTreeNode[] {
const result: FlatTreeNode[] = [];
walk(nodes, 0, result);
return result;
}
export function shouldVirtualizeFlatTree(count: number): boolean {
return count > 0;
}