|
@@ -275,11 +275,18 @@ const createNewPathTree = function (type, setting) {
|
|
|
// 树设置
|
|
|
this.setting = setting;
|
|
|
|
|
|
- if (this.setting.markFoldKey) {
|
|
|
+ this.hasMark = false;
|
|
|
+ if (this.setting.markExpandKey) {
|
|
|
+ const markStr = getLocalCache(this.setting.markExpandKey);
|
|
|
+ const markData = markStr ? markStr.split('|') : ['', ''];
|
|
|
+ this.hasMark = markData[0] === this.setting.markExpandSubKey;
|
|
|
+ this.markExpand = this.hasMark && markData[1] ? _.map(markData[1].split(','), _.toInteger) : [];
|
|
|
+
|
|
|
+ } else if (this.setting.markFoldKey) {
|
|
|
const markStr = getLocalCache(this.setting.markFoldKey);
|
|
|
const markData = markStr ? markStr.split('|') : ['', ''];
|
|
|
- this.markFold = markData[0] === this.setting.markFoldSubKey && markData[1]
|
|
|
- ? _.map(markData[1].split(','), _.toInteger) : [];
|
|
|
+ this.hasMark = markData[0] === this.setting.markFoldSubKey;
|
|
|
+ this.markFold = this.hasMark && markData[1] ? _.map(markData[1].split(','), _.toInteger) : [];
|
|
|
}
|
|
|
// if (this.setting.treeCacheKey) {
|
|
|
// localforage.getItem(this.setting.treeCacheKey).then(function (v) {
|
|
@@ -355,10 +362,25 @@ const createNewPathTree = function (type, setting) {
|
|
|
return a.order - b.order;
|
|
|
});
|
|
|
this.sortTreeNode(true);
|
|
|
- if (this.setting.autoExpand >= 0) this.expandByLevel(this.setting.autoExpand);
|
|
|
- if (this.setting.markFoldKey) this.expandByCustom(function (node) {
|
|
|
- return self.markFold.indexOf(node[self.setting.id]) === -1;
|
|
|
- });
|
|
|
+ if (this.hasMark) {
|
|
|
+ if (this.setting.markExpandKey) {
|
|
|
+ this.expandByCustom(node => {
|
|
|
+ return self.markExpand.indexOf(node[self.setting.id]) >= 0;
|
|
|
+ });
|
|
|
+ } else if (this.setting.markFoldKey) {
|
|
|
+ this.expandByCustom(function (node) {
|
|
|
+ return self.markFold.indexOf(node[self.setting.id]) === -1;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (this.setting.autoExpand >= 0) {
|
|
|
+ this.expandByLevel(this.setting.autoExpand);
|
|
|
+ for (const node of this.nodes) {
|
|
|
+ this._markExpandFold(node);
|
|
|
+ }
|
|
|
+ this._saveMarkExpandFold();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
getItemsByIndex(index) {
|
|
@@ -526,18 +548,29 @@ const createNewPathTree = function (type, setting) {
|
|
|
return node[this.setting.id];
|
|
|
};
|
|
|
|
|
|
- _markFold(node) {
|
|
|
- if (!this.setting.markFoldKey || !this.setting.markFoldSubKey) return;
|
|
|
- // if (!this.setting.treeCacheKey) return;
|
|
|
-
|
|
|
- if (!node.expanded) {
|
|
|
- if (this.markFold.indexOf(node[this.setting.id]) === -1) this.markFold.push(node[this.setting.id]);
|
|
|
- } else {
|
|
|
- if (this.markFold.indexOf(node[this.setting.id]) >= 0) this.markFold.splice(this.markFold.indexOf(node[this.setting.id]), 1);
|
|
|
+ _markExpandFold(node) {
|
|
|
+ if (this.setting.markExpandKey && this.setting.markExpandSubKey) {
|
|
|
+ if (node.expanded) {
|
|
|
+ if (this.markExpand.indexOf(node[this.setting.id]) === -1)
|
|
|
+ this.markExpand.push(node[this.setting.id]);
|
|
|
+ } else {
|
|
|
+ if (this.markExpand.indexOf(node[this.setting.id]) >= 0)
|
|
|
+ this.markExpand.splice(this.markExpand.indexOf(node[this.setting.id]), 1);
|
|
|
+ }
|
|
|
+ } else if (this.setting.markFoldKey && this.setting.markFoldSubKey) {
|
|
|
+ if (!node.expanded) {
|
|
|
+ if (this.markFold.indexOf(node[this.setting.id]) === -1)
|
|
|
+ this.markFold.push(node[this.setting.id]);
|
|
|
+ } else {
|
|
|
+ if (this.markFold.indexOf(node[this.setting.id]) >= 0)
|
|
|
+ this.markFold.splice(this.markFold.indexOf(node[this.setting.id]), 1);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- _saveMarkFold() {
|
|
|
- if (this.setting.markFoldKey && this.setting.markFoldSubKey) {
|
|
|
+ _saveMarkExpandFold() {
|
|
|
+ if (this.setting.markExpandKey && this.setting.markExpandSubKey) {
|
|
|
+ setLocalCache(this.setting.markExpandKey, this.setting.markExpandSubKey + '|' + this.markExpand.join(','));
|
|
|
+ } else if (this.setting.markFoldKey && this.setting.markFoldSubKey) {
|
|
|
setLocalCache(this.setting.markFoldKey, this.setting.markFoldSubKey + '|' + this.markFold.join(','));
|
|
|
}
|
|
|
// if (this.setting.treeCacheKey) {
|
|
@@ -570,9 +603,9 @@ const createNewPathTree = function (type, setting) {
|
|
|
*/
|
|
|
setExpanded(node, expanded) {
|
|
|
node.expanded = expanded;
|
|
|
- this._markFold(node);
|
|
|
+ this._markExpandFold(node);
|
|
|
this._refreshChildrenVisible(node);
|
|
|
- this._saveMarkFold();
|
|
|
+ this._saveMarkExpandFold();
|
|
|
};
|
|
|
/**
|
|
|
* 递归 设置节点展开状态
|
|
@@ -586,7 +619,7 @@ const createNewPathTree = function (type, setting) {
|
|
|
const expanded = checkFun(node);
|
|
|
if (node.expanded !== expanded) {
|
|
|
node.expanded = expanded;
|
|
|
- this._markFold(node);
|
|
|
+ this._markExpandFold(node);
|
|
|
}
|
|
|
node.visible = parent ? (parent.expanded && parent.visible) : true;
|
|
|
this._recursiveExpand(node.children, node, checkFun);
|
|
@@ -598,7 +631,7 @@ const createNewPathTree = function (type, setting) {
|
|
|
*/
|
|
|
expandByCustom(checkFun) {
|
|
|
this._recursiveExpand(this.children, null, checkFun);
|
|
|
- this._saveMarkFold();
|
|
|
+ this._saveMarkExpandFold();
|
|
|
}
|
|
|
/**
|
|
|
* 展开到第几层
|