Browse Source

树结构更新逻辑优化

MaiXinRong 3 months ago
parent
commit
b8ca92f414
1 changed files with 16 additions and 7 deletions
  1. 16 7
      app/public/js/path_tree.js

+ 16 - 7
app/public/js/path_tree.js

@@ -325,13 +325,18 @@ const createNewPathTree = function (type, setting) {
         /**
          * 树结构根据显示排序
          */
-        sortTreeNode(isResort) {
+        sortTreeNode(isResort, isReturn) {
+            const resorts = [];
             const self = this;
+            if (isReturn) this.nodes.forEach((x, i) => { x.__org_tree_index = i });
             const addSortNodes = function (nodes) {
                 if (!nodes) { return }
                 for (let i = 0; i < nodes.length; i++) {
                     self.nodes.push(nodes[i]);
                     nodes[i].index = self.nodes.length - 1;
+                    if (isReturn && nodes[i].__org_tree_index !== undefined && nodes[i].__org_tree_index !== nodes[i].index) {
+                        resorts.push(nodes[i]);
+                    }
                     if (!isResort) {
                         nodes[i].children = self.getChildren(nodes[i]);
                     } else {
@@ -347,6 +352,7 @@ const createNewPathTree = function (type, setting) {
                 this.sortByOrder(this.children);
             }
             addSortNodes(this.children);
+            return resorts;
         }
         sortByOrder(datas) {
             const setting = this.setting;
@@ -790,9 +796,9 @@ const createNewPathTree = function (type, setting) {
                                 loadedData.push(this.getItems(node[this.setting.pid]));
                                 loadedData.push(this.getItems(data[this.setting.pid]));
                             }
-                            if (prop === this.setting.order) {
-                                loadedData = loadedData.concat(this.getPosterity(node));
-                            }
+                            // if (prop === this.setting.order) {
+                            //     loadedData = loadedData.concat(this.getPosterity(node));
+                            // }
                             node[prop] = data[prop];
                         }
                     }
@@ -808,7 +814,9 @@ const createNewPathTree = function (type, setting) {
                     this.children = this.getChildren(null);
                 }
             }
-            this.sortTreeNode(true);
+            const resortTreeNodes = this.sortTreeNode(true, true);
+            loadedData.push(...resortTreeNodes);
+            loadedData = _.uniq(loadedData);
             return loadedData;
         };
         /**
@@ -845,8 +853,8 @@ const createNewPathTree = function (type, setting) {
                         resortData.push(node);
                     }
                     const parent = this.getItems(node[this.setting.pid]);
-                    if (parent && resortData.indexOf(parent) === -1) {
-                        resortData.push(parent);
+                    if (parent) {
+                        if (resortData.indexOf(parent) === -1) resortData.push(parent);
                     } else {
                         resortData.push(this.setting.rootId);
                     }
@@ -899,6 +907,7 @@ const createNewPathTree = function (type, setting) {
             for (const node of freeDatas) {
                 removeArrayData(this.nodes, node);
             }
+            this.sortTreeNode(true);
             return freeDatas;
         };
         /**