|
@@ -265,9 +265,8 @@ const createNewPathTree = function (type, setting) {
|
|
addSortNodes(nodes[i].children);
|
|
addSortNodes(nodes[i].children);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- self.nodes = [];
|
|
|
|
- this.children = this.getChildren(null);
|
|
|
|
- addSortNodes(this.getChildren(null));
|
|
|
|
|
|
+ this.nodes = [];
|
|
|
|
+ addSortNodes(this.children);
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* 加载数据(初始化), 并给数据添加部分树结构必须数据
|
|
* 加载数据(初始化), 并给数据添加部分树结构必须数据
|
|
@@ -280,19 +279,30 @@ const createNewPathTree = function (type, setting) {
|
|
this.datas = [];
|
|
this.datas = [];
|
|
this.children = [];
|
|
this.children = [];
|
|
// 加载全部数据
|
|
// 加载全部数据
|
|
|
|
+ datas.sort(function (a, b) {
|
|
|
|
+ return a.level - b.level;
|
|
|
|
+ });
|
|
for (const data of datas) {
|
|
for (const data of datas) {
|
|
const keyName = itemsPre + data[this.setting.id];
|
|
const keyName = itemsPre + data[this.setting.id];
|
|
if (!this.items[keyName]) {
|
|
if (!this.items[keyName]) {
|
|
- this.items[keyName] = JSON.parse(JSON.stringify(data));
|
|
|
|
- this.datas.push(this.items[keyName]);
|
|
|
|
|
|
+ const item = JSON.parse(JSON.stringify(data));
|
|
|
|
+ item.children = [];
|
|
|
|
+ item.expanded = true;
|
|
|
|
+ item.visible = true;
|
|
|
|
+ this.items[keyName] = item;
|
|
|
|
+ this.datas.push(item);
|
|
|
|
+ if (item[setting.pid] === setting.rootId) {
|
|
|
|
+ this.children.push(item);
|
|
|
|
+ } else {
|
|
|
|
+ const parent = this.getParent(item);
|
|
|
|
+ parent.children.push(item);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- this.sortTreeNode();
|
|
|
|
- for (const node of this.nodes) {
|
|
|
|
- //node.expanded = node.children.length > 0;
|
|
|
|
- node.expanded = true;
|
|
|
|
- node.visible = true;
|
|
|
|
- }
|
|
|
|
|
|
+ this.children.sort(function (a, b) {
|
|
|
|
+ return a.order - b.order;
|
|
|
|
+ });
|
|
|
|
+ this.sortTreeNode(true);
|
|
}
|
|
}
|
|
|
|
|
|
getItemsByIndex(index) {
|
|
getItemsByIndex(index) {
|
|
@@ -1223,6 +1233,18 @@ const createNewPathTree = function (type, setting) {
|
|
};
|
|
};
|
|
|
|
|
|
const treeCalc = {
|
|
const treeCalc = {
|
|
|
|
+ mapTreeNode: function (tree) {
|
|
|
|
+ let map = {}, maxLevel = 0;
|
|
|
|
+ for (const node of tree.nodes) {
|
|
|
|
+ let levelArr = map[node.level];
|
|
|
|
+ if (!levelArr) {
|
|
|
|
+ levelArr = [];
|
|
|
|
+ map[node.level] = levelArr;
|
|
|
|
+ }
|
|
|
|
+ levelArr.push(node);
|
|
|
|
+ }
|
|
|
|
+ return [maxLevel, map];
|
|
|
|
+ },
|
|
getMaxLevel: function (tree) {
|
|
getMaxLevel: function (tree) {
|
|
return Math.max.apply(Math, tree.datas.map(function(o) {return o.level}));
|
|
return Math.max.apply(Math, tree.datas.map(function(o) {return o.level}));
|
|
},
|
|
},
|
|
@@ -1256,8 +1278,14 @@ const treeCalc = {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
calculateAll: function (tree) {
|
|
calculateAll: function (tree) {
|
|
- for (let i = this.getMaxLevel(tree); i >= 0; i--) {
|
|
|
|
- this.calculateLevelNode(tree, i);
|
|
|
|
|
|
+ const [maxLevel, levelMap] = this.mapTreeNode(tree);
|
|
|
|
+ for (let i = maxLevel; i >= 0; i--) {
|
|
|
|
+ const levelNodes = levelMap[i];
|
|
|
|
+ if (levelNodes && levelNode.length > 0) {
|
|
|
|
+ for (const node of levelNodes) {
|
|
|
|
+ this.calculateNode(tree, node);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
calculateParent: function (tree, node) {
|
|
calculateParent: function (tree, node) {
|