zhongxiaoyu 2 anni fa
parent
commit
16af92c594
1 ha cambiato i file con 36 aggiunte e 0 eliminazioni
  1. 36 0
      src/utils/validate.js

+ 36 - 0
src/utils/validate.js

@@ -36,6 +36,7 @@ export function orgTree (str) {
 }
 
 // 岗位树构造
+<<<<<<< HEAD
 // export function translateDataToTreeAll (data, parentKey, parentIDKey) {
 //   let parent = data.filter((value) => Number(value[parentKey]) <= 0);// 父数据
 //   let children = data.filter((value) => Number(value[parentKey]) > 0);// 子数据
@@ -91,6 +92,41 @@ export function translateDataToTreeAll(arr, parentKey, key) {
     }
   })
   return result
+=======
+export function translateDataToTreeAll (data, parentKey, parentIDKey) {
+  let parent = data.filter((value) => Number(value[parentKey]) <= 0);// 父数据
+  let children = data.filter((value) => Number(value[parentKey]) > 0);// 子数据
+  //console.log('--parent', parent)
+  //console.log('--children', children)
+  let translator = (parent, children) => {
+    parent.forEach((parent) => {
+      parent.children = [];
+      children.forEach((current, index) => {
+        if (current[parentKey] === parent[parentIDKey]) {
+          const temp = JSON.parse(JSON.stringify(children));
+          temp.splice(index, 1);
+          translator([current], temp);
+          typeof parent.children !== "undefined"
+            ? parent.children.push(current)
+            : (parent.children = [current]);
+        }
+      });
+      // for (let i = 0; i < children.length;) {
+      //   if (children[i][parentKey] === parent[parentIDKey]) {
+      //     const temp = children.splice(i, 1)
+      //     typeof parent.children !== 'undefined'
+      //       ? parent.children.push(...temp)
+      //       : (parent.children = temp)
+      //     translator(temp, children)
+      //   } else {
+      //     i++
+      //   }
+      // }
+    });
+  };
+  translator(parent, children);
+  return parent;
+>>>>>>> 04ae07ca885de7a9cb5dc39ef96eca5b2292c339
 }
 
 export function deteleObject (obj) {