|
@@ -607,6 +607,70 @@ var idTree = {
|
|
|
success = true;
|
|
|
return success;
|
|
|
};
|
|
|
+
|
|
|
+ Tree.prototype.m_upLevel = function (nodes) {//原先的父节点变成前一个节点,原先的兄弟节点变成子节点
|
|
|
+ let o_parent = nodes[0].parent;//原来的父节点
|
|
|
+ let o_next = o_parent.nextSibling;//父节点的下一节点
|
|
|
+ let o_pre = nodes[0].preSibling;
|
|
|
+ let o_children = o_parent.children;//旧的所有兄弟节点
|
|
|
+ let children = o_parent.parent?o_parent.parent.children:this.roots;//新的兄弟节点
|
|
|
+ let last;
|
|
|
+ let lastNext;//最后一个选中节点后面的所有兄弟节点变成最后一个节点的子节点
|
|
|
+ for(let i = 0; i<nodes.length;i++){
|
|
|
+ let index = children.indexOf(o_parent) + 1;
|
|
|
+ children.splice(index + i,0,nodes[i]);//往新的父节点的子节点插入节点
|
|
|
+ o_children.splice(nodes[i].siblingIndex(), 1);//旧的数组删除节点
|
|
|
+ if(i == 0){//第一个节点变成原来父节点的下一节点
|
|
|
+ o_parent.setNextSibling(nodes[i]);
|
|
|
+ if(o_pre) o_pre.setNextSibling(null); //第一个选中节点的前一节点的下一节点设置为空
|
|
|
+ }
|
|
|
+ nodes[i].setParent(o_parent.parent);
|
|
|
+ last = nodes[i];
|
|
|
+ lastNext = last.nextSibling;
|
|
|
+ }
|
|
|
+ last.setNextSibling(o_next);//最后一个选中的节点的下一个节点设置为原父节点的下一节点
|
|
|
+ if(lastNext){
|
|
|
+ let t_index = o_children.indexOf(lastNext);
|
|
|
+ for(let j = t_index;j <o_children.length;j++ ){//剩下的添加为最后一个选中节点的子节点
|
|
|
+ last.addChild(o_children[j]);
|
|
|
+ }
|
|
|
+ if(o_children.length > t_index) o_children.splice(t_index, o_children.length - t_index);//从原先的children中移除
|
|
|
+ }
|
|
|
+ if (o_parent.parent&& !o_parent.parent.expanded) o_parent.parent.setExpanded(true);
|
|
|
+ tools.sortTreeItems(this);
|
|
|
+ return true;
|
|
|
+ };
|
|
|
+ Tree.prototype.getUpLevelDatas = function (nodes) {
|
|
|
+ //getParentID
|
|
|
+ let o_parentID = nodes[0].getParentID();
|
|
|
+ let o_children = nodes[0].parent.children;//旧的所有兄弟节点
|
|
|
+ let o_pre = nodes[0].preSibling;
|
|
|
+ let new_parentID = nodes[0].parent.getParentID();
|
|
|
+ let o_nextID = nodes[0].parent.getNextSiblingID();
|
|
|
+ let dataMap = {},updateDatas=[],lastID,lastNext;
|
|
|
+ for(let i = 0; i<nodes.length;i++){
|
|
|
+ if(i == 0){
|
|
|
+ dataMap[o_parentID] = {"ID":o_parentID,"NextSiblingID":nodes[i].getID()};
|
|
|
+ if(o_pre) dataMap[o_pre.getID()] = {"ID":o_pre.getID(),"NextSiblingID":-1}; //nodes[i].preSibling.setNextSibling(null);
|
|
|
+ }
|
|
|
+ dataMap[nodes[i].getID()] = {"ID":nodes[i].getID(),"ParentID":new_parentID};
|
|
|
+ lastID = nodes[i].getID();
|
|
|
+ lastNext = nodes[i].nextSibling;
|
|
|
+ }
|
|
|
+ if(dataMap[lastID] !== undefined){
|
|
|
+ dataMap[lastID].NextSiblingID = o_nextID;
|
|
|
+ }
|
|
|
+ if(lastNext){
|
|
|
+ let t_index = o_children.indexOf(lastNext);
|
|
|
+ for(let j = t_index;j <o_children.length;j++ ){//剩下的添加为最后一个选中节点的子节点
|
|
|
+ dataMap[o_children[j].getID()] = {"ID":o_children[j].getID(),"ParentID":lastID};
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(let key in dataMap){
|
|
|
+ updateDatas.push({type: 'update', data:dataMap[key]});
|
|
|
+ }
|
|
|
+ return updateDatas;
|
|
|
+ };
|
|
|
Tree.prototype.m_downLevel = function (nodes) {
|
|
|
let pre = nodes[0].preSibling ; //第一个节点的前一节点,即会成为新的父节点
|
|
|
let next ;//最后一个节点的后一节点,会成为pre 的下一个节点
|
|
@@ -618,9 +682,7 @@ var idTree = {
|
|
|
children.splice(n.siblingIndex(), 1);
|
|
|
pre.addChild(n);
|
|
|
}
|
|
|
- if (!pre.expanded) {
|
|
|
- pre.setExpanded(true);
|
|
|
- }
|
|
|
+ if (!pre.expanded) pre.setExpanded(true);
|
|
|
pre.setNextSibling(next);
|
|
|
last.nextSibling = null;
|
|
|
tools.sortTreeItems(this);
|
|
@@ -645,7 +707,6 @@ var idTree = {
|
|
|
updateDatas.push({type: 'update', data:dataMap[key]});
|
|
|
}
|
|
|
return updateDatas;
|
|
|
-
|
|
|
};
|
|
|
|
|
|
Tree.prototype.getDeleteData = function (node) {
|