Explorar o código

复制树修改

duy hai 7 meses
pai
achega
5db600949b
Modificáronse 1 ficheiros con 23 adicións e 18 borrados
  1. 23 18
      src/views/project/debit/contract/components/unit/tree-form.vue

+ 23 - 18
src/views/project/debit/contract/components/unit/tree-form.vue

@@ -61,7 +61,7 @@
 
 <script setup>
 import { nextTick, ref, watch } from 'vue'
-import { arrToId, getArrValue, getRandom, isArrIndex, isArrItem } from 'js-fast-way'
+import { arrToId, arrUnion, getArrValue, getRandom, isArrItem } from 'js-fast-way'
 import unitApi from '~api/project/debit/contract/unit.js'
 import { useAppStore } from '~src/store'
 
@@ -293,10 +293,27 @@ const lefttreeProps = {
 const nodeElTreeClick = (data)=>{
 
 }
-const treeNodeCheck = (_, { checkedNodes, checkedKeys }) => {
-   console.log(checkedNodes, 'checkedNodes')
+// 递归函数来获取节点的所有父级对象
+const getAllParents = (tree, targetId, parents = [])=> {
+  for (const node of tree) {
+    if (node.id === targetId) {
+      return parents
+    }
+    if (node.children && node.children.length > 0) {
+      const parentCopy = [...parents]
+      parentCopy.push(node)
+      const result = getAllParents(node.children, targetId, parentCopy)
+      if (result) {
+        return result
+      }
+    }
+  }
+  return null
+}
+const treeNodeCheck = (checkdata, { checkedNodes, halfCheckedNodes }) => {
+   let allArr = arrUnion(halfCheckedNodes, checkedNodes)
     tableData.value = []
-    checkedNodes.forEach((item)=>{
+    allArr.forEach((item)=>{
         tableData.value.push(
             { nodeName: item.nodeName,
             startStake: '',
@@ -310,21 +327,7 @@ const treeNodeCheck = (_, { checkedNodes, checkedKeys }) => {
         )
     })
 
-    
-
     if (checkedNodes.length > 0 ) {
-        console.log(parentData.value, 'parentData')
-        tableData.value.unshift(
-            { nodeName: parentData.value.nodeName,
-            startStake: '',
-            endStake: '',
-            contractPicture: '',
-            isAddChildNode: parentData.value.isAddChildNode || 1,
-            id:parentData.value.id,
-            parentId:parentData.value.parentId,
-            isParent:isTable.value ? false : true,
-             },
-        )
         let alarr = tableData.value
              // 使用reduce方法进行去重
             const uniqueArray = alarr.reduce((acc, current) => {
@@ -340,6 +343,8 @@ const treeNodeCheck = (_, { checkedNodes, checkedKeys }) => {
             }, [])
         
             tableData.value = uniqueArray
+
+    
     }
   
 }