소스 검색

复制树修改

duy 7 달 전
부모
커밋
5db600949b
1개의 변경된 파일23개의 추가작업 그리고 18개의 파일을 삭제
  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
+
+    
     }
   
 }