duy 8 miesięcy temu
rodzic
commit
9ded0e98a0
1 zmienionych plików z 10 dodań i 1 usunięć
  1. 10 1
      src/views/project/list/independent/index.vue

+ 10 - 1
src/views/project/list/independent/index.vue

@@ -4,7 +4,7 @@
             <template #left>
                 <hc-card scrollbar>
                     <h3 class="mb-2">引用元素表</h3>
-                    <ElTree v-if="isShowTree" :load="treeLoadNode" :props="treeProps" accordion highlight-current lazy @node-click="treeNodeTap" />
+                    <ElTree v-if="isShowTree" ref="treeRef" node-key="id" :load="treeLoadNode" :props="treeProps" accordion highlight-current lazy :default-expanded-keys="defaultExpandKey" @node-click="treeNodeTap" />
                 </hc-card>
             </template>
             <hc-card>
@@ -140,6 +140,11 @@ const refreshTree = () => {
 
     setTimeout(() => {
         isShowTree.value = true
+        nextTick(()=>{
+            defaultExpandKey.value.push(nodeInfo.value.id)
+            treeRef.value.setCurrentKey(nodeInfo.value.id)
+         
+        })
     }, 1000)
 }
 const treeLoadNode = async (node, resolve) => {
@@ -163,14 +168,18 @@ const treeLoadNode = async (node, resolve) => {
 
 //树节点被点击
 const nodeInfo = ref({})
+const defaultExpandKey = ref([])
+const treeRef = ref(null)
 const treeProps = {
     label: 'title',
     isLeaf: (item) => {
         return !item.hasChildren
     },
 }
+const curNode = ref({})
 const treeNodeTap = (data, node) => {
     nodeInfo.value = data
+    curNode.value = node
     searchForm.value.parentId = data.id
 
     if (node?.level === 1) {