fix: workspace_tree 叶子判定——无子目录的目录标 is_leaf=true

原把所有目录硬编码 is_leaf:false,导致无子目录的目录(叶子)也被当成可展开的非叶子。
改为扫描子目录判断 has_subdir,is_leaf = not has_subdir。
This commit is contained in:
ymq 2026-08-15 01:40:08 +08:00
parent d5ce25e553
commit d5fc14ae1c

View File

@ -50,12 +50,21 @@ for name in entries:
if name.startswith('.') or name == '__pycache__':
continue
if os.path.isdir(full):
# 叶子判定:目录下是否还有子目录(排除隐藏目录)。无子目录 → 叶子(不可展开)
has_subdir = False
try:
for sub in os.listdir(full):
if not sub.startswith('.') and os.path.isdir(os.path.join(full, sub)):
has_subdir = True
break
except Exception:
pass
items.append({
"id": id_prefix + name,
"parentid": node_id,
"label": "📁 " + name,
"path": full,
"is_leaf": False
"is_leaf": not has_subdir
})
return items