From 7b74e09d3064236f26783b70b385dbabc3cf4eb9 Mon Sep 17 00:00:00 2001 From: igophper <34326532+igophper@users.noreply.github.com> Date: Wed, 17 Jun 2026 12:36:23 +0800 Subject: [PATCH] fix: manage expanded node states in the tree view component (#13064) --- .../file-management/code-editor/index.vue | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/frontend/src/views/host/file-management/code-editor/index.vue b/frontend/src/views/host/file-management/code-editor/index.vue index ed4fcf29b..3b53896b1 100644 --- a/frontend/src/views/host/file-management/code-editor/index.vue +++ b/frontend/src/views/host/file-management/code-editor/index.vue @@ -147,6 +147,7 @@ @node-expand="handleNodeExpand" @node-collapse="handleNodeCollapse" class="monaco-editor-tree monaco-editor-background pt-2" + :default-expanded-keys="expandedNodeKeys" :height="treeHeight" :indent="6" :item-size="26" @@ -564,7 +565,20 @@ const rowRefs = ref(); const isCreate = ref('none'); const newFolder = ref(); const selectedParentNode = ref(null); -const expandedNodeIds = ref(new Set()); +const expandedNodeIds = ref>(new Set()); +const expandedNodeKeys = computed(() => Array.from(expandedNodeIds.value)); + +const addExpandedNode = (id: string) => { + expandedNodeIds.value.add(id); +}; + +const removeExpandedNode = (id: string) => { + expandedNodeIds.value.delete(id); +}; + +const resetExpandedNodes = () => { + expandedNodeIds.value = new Set(); +}; const toggleShow = () => { isShow.value = !isShow.value; @@ -1121,6 +1135,7 @@ const onOpen = async () => { }; const handleSearchResult = (res: ResultData) => { + resetExpandedNodes(); if (res.data.length > 0 && res.data[0].children) { treeData.value = res.data[0].children.map((item) => ({ ...item, @@ -1137,6 +1152,7 @@ const getRefresh = (path: string) => { search(path).then((res) => { treeData.value = res.data[0].children; loadedNodes.value = new Set(); + resetExpandedNodes(); isCreate.value = 'none'; currentPath.value = path; selectedParentNode.value = null; @@ -1250,6 +1266,7 @@ const getUpData = async () => { const response = await search(newPath); treeData.value = response.data[0]?.children || []; loadedNodes.value = new Set(); + resetExpandedNodes(); isCreate.value = 'none'; currentPath.value = newPath; selectedParentNode.value = null; @@ -1269,7 +1286,7 @@ const treeProps = { const handleNodeCollapse = (data: TreeNodeData, node: any) => { isCreate.value = 'none'; - expandedNodeIds.value.delete(data.id); + removeExpandedNode(data.id); const parentNode = node.parent; if (!parentNode) { @@ -1296,7 +1313,7 @@ const handleNodeExpand = (data: TreeNodeData, node: any) => { if (node.data.isDir && isCreate.value == 'none') { currentPath.value = node.data.path; selectedParentNode.value = node; - expandedNodeIds.value.add(node.data.id); + addExpandedNode(node.data.id); } search(data.path) .then((response) => {