From 35718a6539a7607e5726c97b4ffb17d2557aab16 Mon Sep 17 00:00:00 2001 From: guy <141592Wc> Date: Tue, 30 May 2017 12:57:09 +0800 Subject: [PATCH] add --- bi/base.js | 29 +++---- bi/widget.js | 80 ++++++++++++++++--- docs/base.js | 29 +++---- docs/widget.js | 80 ++++++++++++++++--- src/base/tree/parttree.js | 29 +++---- .../abstract.treevaluechooser.js | 80 ++++++++++++++++--- 6 files changed, 243 insertions(+), 84 deletions(-) diff --git a/bi/base.js b/bi/base.js index 785c8ad4d0..0e20f47e8c 100644 --- a/bi/base.js +++ b/bi/base.js @@ -2249,32 +2249,27 @@ BI.PartTree = BI.inherit(BI.AsyncTree, { var self = this, o = this.options; var parentValues = BI.deepClone(treeNode.parentValues || self._getParentValues(treeNode)); var name = this._getNodeValue(treeNode); -// var values = parentValues.concat([name]); if (treeNode.checked === true) { BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments); } else { + //如果选中的值中不存在该值不处理 + var t = this.selectedValues; + var p = parentValues.concat(name); + for (var i = 0, len = p.length; i < len; i++) { + t = t[p[i]]; + if (t == null) { + return; + } + if (BI.isEmpty(t)) { + break; + } + } o.itemsCreator(BI.extend({}, o.paras, { type: BI.TreeView.REQ_TYPE_SELECT_DATA, selectedValues: this.selectedValues, notSelectedValue: name, parentValues: parentValues }), function (new_values) { - if (BI.isEqual(self.selectedValues, new_values)) { - var tNode = treeNode; - var pNode = self._getTree(new_values, parentValues); - if (pNode[name]) { - delete pNode[name]; - } - while (tNode != null && BI.isEmpty(pNode)) { - parentValues = parentValues.slice(0, parentValues.length - 1); - tNode = tNode.getParentNode(); - if (tNode != null) { - pNode = self._getTree(new_values, parentValues); - name = self._getNodeValue(tNode); - delete pNode[name]; - } - } - } self.selectedValues = new_values; BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments); }); diff --git a/bi/widget.js b/bi/widget.js index c8304eb1b0..0863124f01 100644 --- a/bi/widget.js +++ b/bi/widget.js @@ -17297,7 +17297,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree _reqSelectedTreeNode: function (op, callback) { var self = this; - var selectedValues = op.selectedValues; + var selectedValues = BI.deepClone(op.selectedValues); var notSelectedValue = op.notSelectedValue || {}; var keyword = op.keyword || ""; var parentValues = op.parentValues || []; @@ -17312,12 +17312,38 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree function dealWithSelectedValues(selectedValues) { - var p = BI.clone(parentValues); - p.push(notSelectedValue); + //存储的值中存在这个值就把它删掉 + if (canFindKey(selectedValues, parentValues.concat(notSelectedValue))) { + //如果搜索的值在父亲链中 + if (isSearchValueInParent(parentValues.concat(notSelectedValue))) { + var name = notSelectedValue; + var p = parentValues; + var pNode = getNode(selectedValues, parentValues); + if (pNode[name]) { + delete pNode[name]; + //递归删掉空父节点 + while (p.length > 0 && BI.isEmpty(pNode)) { + name = p[p.length - 1]; + p = p.slice(0, p.length - 1); + pNode = getNode(selectedValues, p); + delete pNode[name]; + } + } + } + } - if (isChild(selectedValues, p)) { - var result = []; - var finded = search(parentValues.length + 1, parentValues, notSelectedValue, result); + //存储的值中不存在这个值,但父亲节点是全选的情况 + if (isChild(selectedValues, parentValues.concat(notSelectedValue))) { + var result = [], finded = false; + var p = parentValues; + //如果parentValues中有匹配的值,说明搜索结果不在当前值下 + if (isSearchValueInParent(parentValues.concat(notSelectedValue))) { + finded = true; + p = parentValues.concat(notSelectedValue); + } else { + //从当前值开始搜 + finded = search(parentValues, notSelectedValue, result); + } if (finded === true) { var next = selectedValues; @@ -17353,7 +17379,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree } - function search(deep, parents, current, result) { + function search(parents, current, result) { var newParents = BI.clone(parents); newParents.push(current); if (self._isMatch(current, keyword)) { @@ -17366,7 +17392,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree var can = false; BI.each(children, function (i, child) { - if (search(deep + 1, newParents, child.value, result)) { + if (search(newParents, child.value, result)) { can = true; } else { notSearch.push(child.value); @@ -17382,6 +17408,38 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree return can; } + function isSearchValueInParent(parentValues) { + for (var i = 0, len = parentValues.length; i < len; i++) { + if (self._isMatch(parentValues[i], keyword)) { + return true; + } + } + return false; + } + + function getNode(selectedValues, parentValues) { + var pNode = selectedValues; + for (var i = 0, len = parentValues.length; i < len; i++) { + if (pNode == null) { + return null; + } + pNode = pNode[parentValues[i]]; + } + return pNode; + } + + function canFindKey(selectedValues, parents) { + var t = selectedValues; + for (var i = 0; i < parents.length; i++) { + var v = parents[i]; + t = t[v]; + if (t == null) { + return false; + } + } + return true; + } + function isChild(selectedValues, parents) { var t = selectedValues; for (var i = 0; i < parents.length; i++) { @@ -17390,11 +17448,11 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree return false; } t = t[v]; - if (t == null || BI.isEmpty(t)) { + if (BI.isEmpty(t)) { return true; } } - return true; + return false; } }, @@ -17598,7 +17656,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree var selectedValues = op.selectedValues || {}; var valueMap = {}; // if (judgeState(parentValues, selectedValues, checkState)) { - valueMap = dealWidthSelectedValue(parentValues, selectedValues); + valueMap = dealWidthSelectedValue(parentValues, selectedValues); // } var nodes = this._getChildren(parentValues); for (var i = (times - 1) * this._const.perPage; nodes[i] && i < times * this._const.perPage; i++) { diff --git a/docs/base.js b/docs/base.js index 785c8ad4d0..0e20f47e8c 100644 --- a/docs/base.js +++ b/docs/base.js @@ -2249,32 +2249,27 @@ BI.PartTree = BI.inherit(BI.AsyncTree, { var self = this, o = this.options; var parentValues = BI.deepClone(treeNode.parentValues || self._getParentValues(treeNode)); var name = this._getNodeValue(treeNode); -// var values = parentValues.concat([name]); if (treeNode.checked === true) { BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments); } else { + //如果选中的值中不存在该值不处理 + var t = this.selectedValues; + var p = parentValues.concat(name); + for (var i = 0, len = p.length; i < len; i++) { + t = t[p[i]]; + if (t == null) { + return; + } + if (BI.isEmpty(t)) { + break; + } + } o.itemsCreator(BI.extend({}, o.paras, { type: BI.TreeView.REQ_TYPE_SELECT_DATA, selectedValues: this.selectedValues, notSelectedValue: name, parentValues: parentValues }), function (new_values) { - if (BI.isEqual(self.selectedValues, new_values)) { - var tNode = treeNode; - var pNode = self._getTree(new_values, parentValues); - if (pNode[name]) { - delete pNode[name]; - } - while (tNode != null && BI.isEmpty(pNode)) { - parentValues = parentValues.slice(0, parentValues.length - 1); - tNode = tNode.getParentNode(); - if (tNode != null) { - pNode = self._getTree(new_values, parentValues); - name = self._getNodeValue(tNode); - delete pNode[name]; - } - } - } self.selectedValues = new_values; BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments); }); diff --git a/docs/widget.js b/docs/widget.js index c8304eb1b0..0863124f01 100644 --- a/docs/widget.js +++ b/docs/widget.js @@ -17297,7 +17297,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree _reqSelectedTreeNode: function (op, callback) { var self = this; - var selectedValues = op.selectedValues; + var selectedValues = BI.deepClone(op.selectedValues); var notSelectedValue = op.notSelectedValue || {}; var keyword = op.keyword || ""; var parentValues = op.parentValues || []; @@ -17312,12 +17312,38 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree function dealWithSelectedValues(selectedValues) { - var p = BI.clone(parentValues); - p.push(notSelectedValue); + //存储的值中存在这个值就把它删掉 + if (canFindKey(selectedValues, parentValues.concat(notSelectedValue))) { + //如果搜索的值在父亲链中 + if (isSearchValueInParent(parentValues.concat(notSelectedValue))) { + var name = notSelectedValue; + var p = parentValues; + var pNode = getNode(selectedValues, parentValues); + if (pNode[name]) { + delete pNode[name]; + //递归删掉空父节点 + while (p.length > 0 && BI.isEmpty(pNode)) { + name = p[p.length - 1]; + p = p.slice(0, p.length - 1); + pNode = getNode(selectedValues, p); + delete pNode[name]; + } + } + } + } - if (isChild(selectedValues, p)) { - var result = []; - var finded = search(parentValues.length + 1, parentValues, notSelectedValue, result); + //存储的值中不存在这个值,但父亲节点是全选的情况 + if (isChild(selectedValues, parentValues.concat(notSelectedValue))) { + var result = [], finded = false; + var p = parentValues; + //如果parentValues中有匹配的值,说明搜索结果不在当前值下 + if (isSearchValueInParent(parentValues.concat(notSelectedValue))) { + finded = true; + p = parentValues.concat(notSelectedValue); + } else { + //从当前值开始搜 + finded = search(parentValues, notSelectedValue, result); + } if (finded === true) { var next = selectedValues; @@ -17353,7 +17379,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree } - function search(deep, parents, current, result) { + function search(parents, current, result) { var newParents = BI.clone(parents); newParents.push(current); if (self._isMatch(current, keyword)) { @@ -17366,7 +17392,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree var can = false; BI.each(children, function (i, child) { - if (search(deep + 1, newParents, child.value, result)) { + if (search(newParents, child.value, result)) { can = true; } else { notSearch.push(child.value); @@ -17382,6 +17408,38 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree return can; } + function isSearchValueInParent(parentValues) { + for (var i = 0, len = parentValues.length; i < len; i++) { + if (self._isMatch(parentValues[i], keyword)) { + return true; + } + } + return false; + } + + function getNode(selectedValues, parentValues) { + var pNode = selectedValues; + for (var i = 0, len = parentValues.length; i < len; i++) { + if (pNode == null) { + return null; + } + pNode = pNode[parentValues[i]]; + } + return pNode; + } + + function canFindKey(selectedValues, parents) { + var t = selectedValues; + for (var i = 0; i < parents.length; i++) { + var v = parents[i]; + t = t[v]; + if (t == null) { + return false; + } + } + return true; + } + function isChild(selectedValues, parents) { var t = selectedValues; for (var i = 0; i < parents.length; i++) { @@ -17390,11 +17448,11 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree return false; } t = t[v]; - if (t == null || BI.isEmpty(t)) { + if (BI.isEmpty(t)) { return true; } } - return true; + return false; } }, @@ -17598,7 +17656,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree var selectedValues = op.selectedValues || {}; var valueMap = {}; // if (judgeState(parentValues, selectedValues, checkState)) { - valueMap = dealWidthSelectedValue(parentValues, selectedValues); + valueMap = dealWidthSelectedValue(parentValues, selectedValues); // } var nodes = this._getChildren(parentValues); for (var i = (times - 1) * this._const.perPage; nodes[i] && i < times * this._const.perPage; i++) { diff --git a/src/base/tree/parttree.js b/src/base/tree/parttree.js index 6d4fe6f58b..625fed4e02 100644 --- a/src/base/tree/parttree.js +++ b/src/base/tree/parttree.js @@ -41,32 +41,27 @@ BI.PartTree = BI.inherit(BI.AsyncTree, { var self = this, o = this.options; var parentValues = BI.deepClone(treeNode.parentValues || self._getParentValues(treeNode)); var name = this._getNodeValue(treeNode); -// var values = parentValues.concat([name]); if (treeNode.checked === true) { BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments); } else { + //如果选中的值中不存在该值不处理 + var t = this.selectedValues; + var p = parentValues.concat(name); + for (var i = 0, len = p.length; i < len; i++) { + t = t[p[i]]; + if (t == null) { + return; + } + if (BI.isEmpty(t)) { + break; + } + } o.itemsCreator(BI.extend({}, o.paras, { type: BI.TreeView.REQ_TYPE_SELECT_DATA, selectedValues: this.selectedValues, notSelectedValue: name, parentValues: parentValues }), function (new_values) { - if (BI.isEqual(self.selectedValues, new_values)) { - var tNode = treeNode; - var pNode = self._getTree(new_values, parentValues); - if (pNode[name]) { - delete pNode[name]; - } - while (tNode != null && BI.isEmpty(pNode)) { - parentValues = parentValues.slice(0, parentValues.length - 1); - tNode = tNode.getParentNode(); - if (tNode != null) { - pNode = self._getTree(new_values, parentValues); - name = self._getNodeValue(tNode); - delete pNode[name]; - } - } - } self.selectedValues = new_values; BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments); }); diff --git a/src/component/treevaluechooser/abstract.treevaluechooser.js b/src/component/treevaluechooser/abstract.treevaluechooser.js index 57369bf246..40c6acfc9e 100644 --- a/src/component/treevaluechooser/abstract.treevaluechooser.js +++ b/src/component/treevaluechooser/abstract.treevaluechooser.js @@ -109,7 +109,7 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { _reqSelectedTreeNode: function (op, callback) { var self = this; - var selectedValues = op.selectedValues; + var selectedValues = BI.deepClone(op.selectedValues); var notSelectedValue = op.notSelectedValue || {}; var keyword = op.keyword || ""; var parentValues = op.parentValues || []; @@ -124,12 +124,38 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { function dealWithSelectedValues(selectedValues) { - var p = BI.clone(parentValues); - p.push(notSelectedValue); + //存储的值中存在这个值就把它删掉 + if (canFindKey(selectedValues, parentValues.concat(notSelectedValue))) { + //如果搜索的值在父亲链中 + if (isSearchValueInParent(parentValues.concat(notSelectedValue))) { + var name = notSelectedValue; + var p = parentValues; + var pNode = getNode(selectedValues, parentValues); + if (pNode[name]) { + delete pNode[name]; + //递归删掉空父节点 + while (p.length > 0 && BI.isEmpty(pNode)) { + name = p[p.length - 1]; + p = p.slice(0, p.length - 1); + pNode = getNode(selectedValues, p); + delete pNode[name]; + } + } + } + } - if (isChild(selectedValues, p)) { - var result = []; - var finded = search(parentValues.length + 1, parentValues, notSelectedValue, result); + //存储的值中不存在这个值,但父亲节点是全选的情况 + if (isChild(selectedValues, parentValues.concat(notSelectedValue))) { + var result = [], finded = false; + var p = parentValues; + //如果parentValues中有匹配的值,说明搜索结果不在当前值下 + if (isSearchValueInParent(parentValues.concat(notSelectedValue))) { + finded = true; + p = parentValues.concat(notSelectedValue); + } else { + //从当前值开始搜 + finded = search(parentValues, notSelectedValue, result); + } if (finded === true) { var next = selectedValues; @@ -165,7 +191,7 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { } - function search(deep, parents, current, result) { + function search(parents, current, result) { var newParents = BI.clone(parents); newParents.push(current); if (self._isMatch(current, keyword)) { @@ -178,7 +204,7 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { var can = false; BI.each(children, function (i, child) { - if (search(deep + 1, newParents, child.value, result)) { + if (search(newParents, child.value, result)) { can = true; } else { notSearch.push(child.value); @@ -194,6 +220,38 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { return can; } + function isSearchValueInParent(parentValues) { + for (var i = 0, len = parentValues.length; i < len; i++) { + if (self._isMatch(parentValues[i], keyword)) { + return true; + } + } + return false; + } + + function getNode(selectedValues, parentValues) { + var pNode = selectedValues; + for (var i = 0, len = parentValues.length; i < len; i++) { + if (pNode == null) { + return null; + } + pNode = pNode[parentValues[i]]; + } + return pNode; + } + + function canFindKey(selectedValues, parents) { + var t = selectedValues; + for (var i = 0; i < parents.length; i++) { + var v = parents[i]; + t = t[v]; + if (t == null) { + return false; + } + } + return true; + } + function isChild(selectedValues, parents) { var t = selectedValues; for (var i = 0; i < parents.length; i++) { @@ -202,11 +260,11 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { return false; } t = t[v]; - if (t == null || BI.isEmpty(t)) { + if (BI.isEmpty(t)) { return true; } } - return true; + return false; } }, @@ -410,7 +468,7 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { var selectedValues = op.selectedValues || {}; var valueMap = {}; // if (judgeState(parentValues, selectedValues, checkState)) { - valueMap = dealWidthSelectedValue(parentValues, selectedValues); + valueMap = dealWidthSelectedValue(parentValues, selectedValues); // } var nodes = this._getChildren(parentValues); for (var i = (times - 1) * this._const.perPage; nodes[i] && i < times * this._const.perPage; i++) {