ZaiZai 1 年之前
父节点
当前提交
3d12a45ab8
共有 3 个文件被更改,包括 28 次插入3 次删除
  1. 23 1
      components/hc-tree/hc-tree.vue
  2. 1 1
      components/hc-tree/tree-node.vue
  3. 4 1
      pages/image/position.vue

+ 23 - 1
components/hc-tree/hc-tree.vue

@@ -18,7 +18,7 @@
 </template>
 
 <script setup>
-import {onMounted, ref} from 'vue'
+import {onMounted, ref, watch} from 'vue'
 import {getArrValue} from "js-fast-way";
 
 //参数
@@ -64,6 +64,10 @@ const props = defineProps({
         type: Boolean,
         default: false,
     },
+    autoExpandKey: {
+        type: Array,
+        default: () => ([]),
+    },
 })
 
 //节点数据
@@ -75,6 +79,7 @@ const isRadio = ref(props.radio)
 const isStrictly = ref(props.strictly)
 const isCounts = ref(props.counts)
 const currentNodeKey = ref(props.currentKey)
+const AutoExpandKeys = ref(props.autoExpandKey)
 
 //事件
 const emit = defineEmits(['load', 'nodeTap'])
@@ -89,6 +94,13 @@ onMounted(() => {
     })
 })
 
+//监听
+watch(() => [
+    props.autoExpandKey
+], ([keys]) => {
+    AutoExpandKeys.value = keys
+}, {deep: true})
+
 const treeLoadTap = (item) => {
     getLazyLoad(item)
 }
@@ -141,6 +153,16 @@ const setLazyLoad = (data, arr) => {
         if (data.level === 0) {
             nodeData.value = newNodeData
         }
+        //处理自动展开
+        //const keys = getArrValue(AutoExpandKeys.value)
+        /*if (keys.length === nodeItem.level) {
+            if (keys[nodeItem.level-1] === nodeItem.key) {
+                nodeItem.isExpand = true
+                emit('load', nodeItem, (loadData) => {
+                    setLazyLoad(nodeItem, loadData)
+                })
+            }
+        }*/
     }
 }
 

+ 1 - 1
components/hc-tree/tree-node.vue

@@ -71,7 +71,7 @@ const emit = defineEmits(['nodeLoad', 'nodeTap'])
 
 //变量
 const nodeItem = ref(props.item)
-
+console.log('nodeItem', nodeItem.value)
 //参数配置
 const isCheck = ref(props.check)
 const isRadio = ref(props.radio)

+ 4 - 1
pages/image/position.vue

@@ -15,7 +15,7 @@
 
         <template v-if="isNodeShow">
             <view class="relative" un-border-t="1 solid gray-2" v-if="typeIndex === 0">
-                <hc-tree counts @load="getAllLoad" @nodeTap="nodeAllTap"/>
+                <hc-tree counts :autoExpandKey="AllExpandKey" @load="getAllLoad" @nodeTap="nodeAllTap"/>
             </view>
             <view class="relative" un-border-t="1 solid gray-2" v-if="typeIndex === 1">
                 <hc-tree counts nodeKey="pKeyId" @load="getWorksLoad" @nodeTap="nodeAllTap"/>
@@ -70,6 +70,9 @@ onHide(() => {
 })
 
 //全部树
+const AllExpandKey = ref([
+    '1644218999308812288'
+])
 const getAllLoad = async (node, resolve) => {
     const { contractType } = contractInfo.value
     const { id, contractIdRelation } = getObjValue(node.data)