fix: workspace_tree 叶子判定——无子目录的目录标 is_leaf=true
原把所有目录硬编码 is_leaf:false,导致无子目录的目录(叶子)也被当成可展开的非叶子。 改为扫描子目录判断 has_subdir,is_leaf = not has_subdir。
This commit is contained in:
parent
d5ce25e553
commit
d5fc14ae1c
@ -50,12 +50,21 @@ for name in entries:
|
|||||||
if name.startswith('.') or name == '__pycache__':
|
if name.startswith('.') or name == '__pycache__':
|
||||||
continue
|
continue
|
||||||
if os.path.isdir(full):
|
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({
|
items.append({
|
||||||
"id": id_prefix + name,
|
"id": id_prefix + name,
|
||||||
"parentid": node_id,
|
"parentid": node_id,
|
||||||
"label": "📁 " + name,
|
"label": "📁 " + name,
|
||||||
"path": full,
|
"path": full,
|
||||||
"is_leaf": False
|
"is_leaf": not has_subdir
|
||||||
})
|
})
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user