From 67a3239f971cac4bbba67a5be5f7e707e145dd0f Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Thu, 9 Jul 2020 17:00:39 +0800 Subject: [PATCH] =?UTF-8?q?BI-61057=20refactor:=20=E6=96=B0=E5=A2=9EgetAll?= =?UTF-8?q?Value=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 2 ++ .../abstract.treevaluechooser.js | 34 +++++++++++++++++-- .../combo.treevaluechooser.js | 4 +++ .../treevaluechooser/pane.treevaluechooser.js | 4 +++ .../valuechooser/combo.valuechooser.insert.js | 9 +++++ .../valuechooser/combo.valuechooser.js | 9 +++++ .../valuechooser/pane.valuechooser.js | 9 +++++ 7 files changed, 69 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index f2618763c..906151a9f 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,7 @@ # 更新日志 2.0(2020-07) +- 同步复选下拉及其面板新增getAllValue获取所有已选值 +- 同步复选下拉树及其面板新增getAllValue获取完整的选中树节点 - 修复date_picker最大值最小值与面板展示判断问题 - 复选下拉树和下拉列表添加showView和hideVIew方法 - number_editor支持自动检测数值与范围是否合法 diff --git a/src/component/treevaluechooser/abstract.treevaluechooser.js b/src/component/treevaluechooser/abstract.treevaluechooser.js index 788d072ef..79ec70629 100644 --- a/src/component/treevaluechooser/abstract.treevaluechooser.js +++ b/src/component/treevaluechooser/abstract.treevaluechooser.js @@ -783,5 +783,35 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { _getChildCount: function (parentValues) { return this._getChildren(parentValues).length; - } -}); \ No newline at end of file + }, + + buildCompleteTree: function (selectedValues) { + var self = this; + var result = {}; + + if (selectedValues !== null && !BI.isEmpty(selectedValues)) { + fill([], this.tree.getRoot(), selectedValues, result); + } + + return result; + + function fill(parentValues, node, selected, r) { + if (selected === null || BI.isEmpty(selected)) { + BI.each(node.getChildren(), function (i, child) { + var newParents = BI.clone(parentValues); + newParents.push(child.value); + r[child.value] = {}; + fill(newParents, child, null, r[child.value]); + }); + return; + } + BI.each(selected, function (k) { + var node = self._getTreeNode(parentValues, k); + var newParents = BI.clone(parentValues); + newParents.push(node.value); + r[k] = {}; + fill(newParents, node, selected[k], r[k]); + }); + } + }, +}); diff --git a/src/component/treevaluechooser/combo.treevaluechooser.js b/src/component/treevaluechooser/combo.treevaluechooser.js index 1fa1b3d27..9a90c7957 100644 --- a/src/component/treevaluechooser/combo.treevaluechooser.js +++ b/src/component/treevaluechooser/combo.treevaluechooser.js @@ -91,6 +91,10 @@ BI.TreeValueChooserCombo = BI.inherit(BI.AbstractTreeValueChooser, { return this.combo.getValue(); }, + getAllValue: function() { + return this.buildCompleteTree(this.combo.getValue()); + }, + populate: function (items) { this._initData(items); this.combo.populate.apply(this.combo, arguments); diff --git a/src/component/treevaluechooser/pane.treevaluechooser.js b/src/component/treevaluechooser/pane.treevaluechooser.js index 906ed682a..89f981f70 100644 --- a/src/component/treevaluechooser/pane.treevaluechooser.js +++ b/src/component/treevaluechooser/pane.treevaluechooser.js @@ -45,6 +45,10 @@ BI.TreeValueChooserPane = BI.inherit(BI.AbstractTreeValueChooser, { return this.pane.getValue(); }, + getAllValue: function() { + return this.buildCompleteTree(this.combo.getValue()); + }, + populate: function () { this.pane.populate.apply(this.pane, arguments); } diff --git a/src/component/valuechooser/combo.valuechooser.insert.js b/src/component/valuechooser/combo.valuechooser.insert.js index 6696b5feb..2589a85a4 100644 --- a/src/component/valuechooser/combo.valuechooser.insert.js +++ b/src/component/valuechooser/combo.valuechooser.insert.js @@ -77,6 +77,15 @@ BI.ValueChooserInsertCombo = BI.inherit(BI.AbstractValueChooser, { }; }, + getAllValue: function() { + var val = this.combo.getValue() || {}; + if (val.type === BI.Selection.Multi) { + return val.value || []; + } + + return BI.difference(BI.map(this.items, "value"), val.value || []); + }, + populate: function (items) { // 直接用combo的populate不会作用到AbstractValueChooser上 this.items = items; diff --git a/src/component/valuechooser/combo.valuechooser.js b/src/component/valuechooser/combo.valuechooser.js index d303f05bc..1cb49c6f5 100644 --- a/src/component/valuechooser/combo.valuechooser.js +++ b/src/component/valuechooser/combo.valuechooser.js @@ -81,6 +81,15 @@ BI.ValueChooserCombo = BI.inherit(BI.AbstractValueChooser, { }; }, + getAllValue: function() { + var val = this.combo.getValue() || {}; + if (val.type === BI.Selection.Multi) { + return val.value || []; + } + + return BI.difference(BI.map(this.items, "value"), val.value || []); + }, + populate: function (items) { // 直接用combo的populate不会作用到AbstractValueChooser上 this.items = items; diff --git a/src/component/valuechooser/pane.valuechooser.js b/src/component/valuechooser/pane.valuechooser.js index 143f8f8c9..c92c82879 100644 --- a/src/component/valuechooser/pane.valuechooser.js +++ b/src/component/valuechooser/pane.valuechooser.js @@ -49,6 +49,15 @@ BI.ValueChooserPane = BI.inherit(BI.AbstractValueChooser, { }; }, + getAllValue: function() { + var val = this.combo.getValue() || {}; + if (val.type === BI.Selection.Multi) { + return val.value || []; + } + + return BI.difference(BI.map(this.items, "value"), val.value || []); + }, + populate: function (items) { // 直接用combo的populate不会作用到AbstractValueChooser上 items && (this.items = items);