From a81e3248e1b5ef2de2283dc854bfe058d8701c67 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Thu, 8 Aug 2019 18:17:00 +0800 Subject: [PATCH] =?UTF-8?q?BI-49588=20feat:=20=E8=A1=A5=E5=85=85=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E5=8D=95=E9=80=89=E4=B8=8B=E6=8B=89=E6=A0=91=E7=9A=84?= =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../multilayerselecttree.combo.js | 37 +++++++++++-------- .../multilayerselecttree.trigger.js | 29 ++++++++++++++- .../multilayersingletree.combo.js | 37 +++++++++++-------- .../multilayersingletree.trigger.js | 29 ++++++++++++++- 4 files changed, 98 insertions(+), 34 deletions(-) diff --git a/src/widget/multilayerselecttree/multilayerselecttree.combo.js b/src/widget/multilayerselecttree/multilayerselecttree.combo.js index 57e2d775e..bd12b25cf 100644 --- a/src/widget/multilayerselecttree/multilayerselecttree.combo.js +++ b/src/widget/multilayerselecttree/multilayerselecttree.combo.js @@ -91,23 +91,9 @@ BI.MultiLayerSelectTreeCombo = BI.inherit(BI.Widget, { }; }, - _getSyncConfig: function () { - var o = this.options; - var baseConfig = this._getBaseConfig(); - baseConfig.el = { - type: "bi.single_tree_trigger", - text: o.text, - height: o.height, - items: o.items, - value: o.value - }; - return baseConfig; - }, - - _getAsyncConfig: function () { + _getSearchConfig: function() { var self = this, o = this.options; - var config = this._getBaseConfig(); - return BI.extend(config, { + return { el: { type: "bi.multilayer_select_tree_trigger", allowEdit: o.allowEdit, @@ -157,9 +143,28 @@ BI.MultiLayerSelectTreeCombo = BI.inherit(BI.Widget, { self.trigger.stopEditing(); } }] + } + }, + + _getSyncConfig: function () { + var o = this.options; + var baseConfig = this._getBaseConfig(); + return BI.extend(baseConfig, o.allowEdit ? this._getSearchConfig() : { + el: { + type: "bi.single_tree_trigger", + text: o.text, + height: o.height, + items: o.items, + value: o.value + } }); }, + _getAsyncConfig: function () { + var config = this._getBaseConfig(); + return BI.extend(config, this._getSearchConfig()); + }, + setValue: function (v) { v = BI.isArray(v) ? v : [v]; this.combo.setValue(v); diff --git a/src/widget/multilayerselecttree/multilayerselecttree.trigger.js b/src/widget/multilayerselecttree/multilayerselecttree.trigger.js index c953bed7f..e91a6b413 100644 --- a/src/widget/multilayerselecttree/multilayerselecttree.trigger.js +++ b/src/widget/multilayerselecttree/multilayerselecttree.trigger.js @@ -14,6 +14,10 @@ BI.MultiLayerSelectTreeTrigger = BI.inherit(BI.Trigger, { render: function () { var self = this, o = this.options; + if(o.itemsCreator === BI.emptyFn) { + this.tree = new BI.Tree(); + this.tree.initTree(BI.deepClone(BI.Tree.treeFormat(BI.deepClone(o.items)))); + } var content = { type: "bi.htape", items: [ @@ -68,7 +72,7 @@ BI.MultiLayerSelectTreeTrigger = BI.inherit(BI.Trigger, { if(o.itemsCreator === BI.emptyFn) { var finding = BI.Func.getSearchResult(o.items, keyword); var matched = finding.match, find = finding.find; - callback(find.concat(matched)); + callback(self._fillTreeStructure4Search(find.concat(matched))); } else { callback(); } @@ -110,6 +114,29 @@ BI.MultiLayerSelectTreeTrigger = BI.inherit(BI.Trigger, { }; }, + // 将搜索到的节点进行补充,构造成一棵完整的树 + _fillTreeStructure4Search: function (leaves) { + var result = BI.map(leaves, "id"); + var queue = leaves.reverse() || []; + while (BI.isNotEmptyArray(queue)) { + var node = queue.pop(); + var pNode = this.tree.search(this.tree.getRoot(), node.pId, "id"); + if (pNode != null) { + queue.push(pNode); + result.push(pNode.id); + } + } + var nodes = []; + BI.each(this.options.items, function (idx, item) { + if(BI.contains(result, item.id)) { + nodes.push(BI.extend({}, item, { + open: true + })) + } + }); + return nodes; + }, + _digest: function (v) { var o = this.options; return o.valueFormatter(v) || o.text; diff --git a/src/widget/multilayersingletree/multilayersingletree.combo.js b/src/widget/multilayersingletree/multilayersingletree.combo.js index f3b3c10d5..4745c85a8 100644 --- a/src/widget/multilayersingletree/multilayersingletree.combo.js +++ b/src/widget/multilayersingletree/multilayersingletree.combo.js @@ -94,23 +94,9 @@ BI.MultiLayerSingleTreeCombo = BI.inherit(BI.Widget, { }; }, - _getSyncConfig: function () { - var o = this.options; - var baseConfig = this._getBaseConfig(); - baseConfig.el = { - type: "bi.single_tree_trigger", - text: o.text, - height: o.height, - items: o.items, - value: o.value - }; - return baseConfig; - }, - - _getAsyncConfig: function () { + _getSearchConfig: function() { var self = this, o = this.options; - var config = this._getBaseConfig(); - return BI.extend(config, { + return { el: { type: "bi.multilayer_single_tree_trigger", allowEdit: o.allowEdit, @@ -160,9 +146,28 @@ BI.MultiLayerSingleTreeCombo = BI.inherit(BI.Widget, { self.trigger.stopEditing(); } }] + } + }, + + _getSyncConfig: function () { + var o = this.options; + var baseConfig = this._getBaseConfig(); + return BI.extend(baseConfig, o.allowEdit ? this._getSearchConfig() : { + el: { + type: "bi.single_tree_trigger", + text: o.text, + height: o.height, + items: o.items, + value: o.value + } }); }, + _getAsyncConfig: function () { + var config = this._getBaseConfig(); + return BI.extend(config, this._getSearchConfig()); + }, + setValue: function (v) { v = BI.isArray(v) ? v : [v]; this.combo.setValue(v); diff --git a/src/widget/multilayersingletree/multilayersingletree.trigger.js b/src/widget/multilayersingletree/multilayersingletree.trigger.js index 46a2a219f..08e855204 100644 --- a/src/widget/multilayersingletree/multilayersingletree.trigger.js +++ b/src/widget/multilayersingletree/multilayersingletree.trigger.js @@ -14,6 +14,10 @@ BI.MultiLayerSingleTreeTrigger = BI.inherit(BI.Trigger, { render: function () { var self = this, o = this.options; + if(o.itemsCreator === BI.emptyFn) { + this.tree = new BI.Tree(); + this.tree.initTree(BI.deepClone(BI.Tree.treeFormat(BI.deepClone(o.items)))); + } var content = { type: "bi.htape", items: [ @@ -68,7 +72,7 @@ BI.MultiLayerSingleTreeTrigger = BI.inherit(BI.Trigger, { if(o.itemsCreator === BI.emptyFn) { var finding = BI.Func.getSearchResult(o.items, keyword); var matched = finding.match, find = finding.find; - callback(find.concat(matched)); + callback(self._fillTreeStructure4Search(find.concat(matched))); } else { callback(); } @@ -110,6 +114,29 @@ BI.MultiLayerSingleTreeTrigger = BI.inherit(BI.Trigger, { }; }, + // 将搜索到的节点进行补充,构造成一棵完整的树 + _fillTreeStructure4Search: function (leaves) { + var result = BI.map(leaves, "id"); + var queue = leaves.reverse() || []; + while (BI.isNotEmptyArray(queue)) { + var node = queue.pop(); + var pNode = this.tree.search(this.tree.getRoot(), node.pId, "id"); + if (pNode != null) { + queue.push(pNode); + result.push(pNode.id); + } + } + var nodes = []; + BI.each(this.options.items, function (idx, item) { + if(BI.contains(result, item.id)) { + nodes.push(BI.extend({}, item, { + open: true + })) + } + }); + return nodes; + }, + _digest: function (v) { var o = this.options; return o.valueFormatter(v) || o.text;