File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5757 <el-tree
5858 :data =" serverTree"
5959 node-key =" id"
60- default-expand-all
60+ : default-expanded-keys = " expandedKeys "
6161 :expand-on-click-node =" false"
6262 @node-click =" handleServerClick"
63+ @node-expand =" handleNodeExpand"
64+ @node-collapse =" handleNodeCollapse"
6365 >
6466 <template #default =" { node , data } " >
6567 <div class =" tree-node" >
@@ -182,6 +184,26 @@ const showEditServerDialog = ref(false)
182184const editingServerId = ref (null )
183185const editingServerName = ref (' ' )
184186
187+ // 分组展开状态持久化 (sessionStorage)
188+ const EXPANDED_KEYS_STORAGE_KEY = ' webssh_dashboard_expanded_keys'
189+ const expandedKeys = ref (JSON .parse (sessionStorage .getItem (EXPANDED_KEYS_STORAGE_KEY ) || ' []' ))
190+
191+ // 监听分组展开
192+ const handleNodeExpand = (data ) => {
193+ if (data .type === ' group' && ! expandedKeys .value .includes (data .id )) {
194+ expandedKeys .value .push (data .id )
195+ sessionStorage .setItem (EXPANDED_KEYS_STORAGE_KEY , JSON .stringify (expandedKeys .value ))
196+ }
197+ }
198+
199+ // 监听分组折叠
200+ const handleNodeCollapse = (data ) => {
201+ if (data .type === ' group' ) {
202+ expandedKeys .value = expandedKeys .value .filter (id => id !== data .id )
203+ sessionStorage .setItem (EXPANDED_KEYS_STORAGE_KEY , JSON .stringify (expandedKeys .value ))
204+ }
205+ }
206+
185207// 计算服务器树形数据
186208const serverTree = computed (() => {
187209 const groups = {}
You can’t perform that action at this time.
0 commit comments