tree: root only initially, click to expand

This commit is contained in:
p 2026-08-12 18:44:40 +08:00
parent 0a0260708a
commit ef39d586bb

View File

@ -1,4 +1,4 @@
# workspace_tree.dspy - 初始加载返回嵌套结构(根节点+children),展开时返回平级子节点 # workspace_tree.dspy - 初始只返回根节点(无children),靠点击展开
import os import os
@ -30,43 +30,18 @@ async with DBPools().sqlorContext(dbname) as sor:
if not ws_dir or not os.path.isdir(ws_dir): if not ws_dir or not os.path.isdir(ws_dir):
if not node_id: if not node_id:
return [{ return [{"id": "__root__", "parentid": "", "label": "📁 工作空间(不可用)", "path": ws_dir, "is_leaf": False}]
"id": "__root__",
"parentid": "",
"label": "📁 工作空间(不可用)",
"path": ws_dir,
"is_leaf": True
}]
return [] return []
# 初始加载:返回带 children 的嵌套结构 # 初始加载:只返回根节点
if not node_id: if not node_id:
root = { return [{
"id": "__root__", "id": "__root__",
"parentid": "", "parentid": "",
"label": "📁 " + os.path.basename(ws_dir), "label": "📁 " + os.path.basename(ws_dir),
"path": ws_dir, "path": ws_dir,
"is_leaf": False, "is_leaf": False
"children": [] }]
}
try:
entries = sorted(os.listdir(ws_dir))
except Exception:
entries = []
for name in entries:
full = os.path.join(ws_dir, name)
if name.startswith('.') or name == '__pycache__':
continue
if os.path.isdir(full):
root["children"].append({
"id": name,
"parentid": "__root__",
"label": "📁 " + name,
"path": full,
"is_leaf": False,
"children": []
})
return [root]
# 展开节点 # 展开节点
scan_path = ws_dir + '/' + node_id scan_path = ws_dir + '/' + node_id