From 7daa9b11024b91840d876b8119aa6f8c19e6aec8 Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 21 Jun 2017 21:09:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bi/base.js | 2 +- bi/widget.js | 12 +- .../demo.multilayerselecttree.leveltree.js | 215 +++++++++++++++++ demo/js/config/component.js | 4 + docs/base.js | 2 +- docs/demo.js | 220 +++++++++++++++++- docs/widget.js | 12 +- src/base/single/button/button.basic.js | 2 +- src/widget/multiselect/multiselect.combo.js | 5 +- .../search/multiselect.search.loader.js | 3 +- src/widget/multiselectlist/multiselectlist.js | 4 +- 11 files changed, 462 insertions(+), 19 deletions(-) create mode 100644 demo/js/component/demo.multilayerselecttree.leveltree.js diff --git a/bi/base.js b/bi/base.js index c64eebd0b..16c2d1714 100644 --- a/bi/base.js +++ b/bi/base.js @@ -857,7 +857,7 @@ BI.BasicButton = BI.inherit(BI.Single, { setSelected: function (b) { var o = this.options; o.selected = b; - if (this.isSelected()) { + if (b) { this.handle().element.addClass("active"); } else { this.handle().element.removeClass("active"); diff --git a/bi/widget.js b/bi/widget.js index 9a0b7488b..fd9277951 100644 --- a/bi/widget.js +++ b/bi/widget.js @@ -9585,7 +9585,8 @@ BI.MultiSelectCombo = BI.inherit(BI.Single, { itemsCreator: function (op, callback) { o.itemsCreator(op, function (res) { if (op.times === 1 && BI.isNotNull(op.keywords)) { - self.trigger.setValue(self.getValue()); + //预防trigger内部把当前的storeValue改掉 + self.trigger.setValue(BI.deepClone(self.getValue())); } callback.apply(self, arguments); }); @@ -9638,7 +9639,7 @@ BI.MultiSelectCombo = BI.inherit(BI.Single, { assertShowValue(); }); } else { - self._join(this.getValue(), function () {//安徽省 北京 + self._join(this.getValue(), function () { assertShowValue(); }); } @@ -10431,7 +10432,8 @@ BI.MultiSelectSearchLoader = BI.inherit(BI.Widget, { }, setValue: function (v) { - this.storeValue = v; + //暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 + this.storeValue = BI.deepClone(v); this.button_group.setValue(v); }, @@ -10982,7 +10984,7 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { var assertShowValue = function () { BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); - self.trigger.setValue(self.storeValue); + // self.trigger.setValue(self.storeValue); }; this.adapter = BI.createWidget({ @@ -11034,7 +11036,7 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { action: function () { self._showSearcherPane(); self._setStartValue(""); - this.setValue(self.storeValue); + this.setValue(BI.deepClone(self.storeValue)); } }, { eventName: BI.Searcher.EVENT_STOP, diff --git a/demo/js/component/demo.multilayerselecttree.leveltree.js b/demo/js/component/demo.multilayerselecttree.leveltree.js new file mode 100644 index 000000000..c1a17ad95 --- /dev/null +++ b/demo/js/component/demo.multilayerselecttree.leveltree.js @@ -0,0 +1,215 @@ +/** + * guy + * 二级树 + * @class BI.PlatformLevelTree + * @extends BI.Select + */ +BI.PlatformLevelTree = BI.inherit(BI.Widget, { + props: { + baseCls: "platform-level-tree", + itemsCreator: BI.emptyFn + }, + + render: function () { + var self = this, o = this.options; + this.tree = BI.createWidget({ + type: "bi.custom_tree", + element: this, + expander: { + type: "bi.select_tree_expander", + isDefaultInit: false, + el: {}, + popup: { + type: "bi.custom_tree" + } + }, + + itemsCreator: function (op, callback) { + o.itemsCreator(op, function (items) { + callback(self._formatItems(items)) + }) + }, + + el: { + type: "bi.loader", + next: false, + el: { + type: "bi.button_tree", + chooseType: 0, + layouts: [{ + type: "bi.vertical" + }] + } + } + }); + this.tree.on(BI.CustomTree.EVENT_CHANGE, function () { + self.fireEvent(BI.PlatformLevelTree.EVENT_CHANGE, arguments); + }) + }, + + _formatItems: function (nodes) { + var self = this; + BI.each(nodes, function (i, node) { + var extend = {}; + if (node.isParent === true || BI.isNotEmptyArray(node.children)) { + switch (i) { + case 0 : + extend.type = "bi.multilayer_select_tree_first_plus_group_node"; + break; + case nodes.length - 1 : + extend.type = "bi.multilayer_select_tree_last_plus_group_node"; + break; + default : + extend.type = "bi.multilayer_select_tree_mid_plus_group_node"; + break; + } + BI.defaults(node, extend); + } else { + switch (i) { + case nodes.length - 1: + extend.type = "bi.multilayer_single_tree_last_tree_leaf_item"; + break; + default : + extend.type = "bi.multilayer_single_tree_mid_tree_leaf_item"; + } + BI.defaults(node, extend); + } + }); + return nodes; + }, + + populate: function () { + this.tree.populate(); + }, + + getValue: function () { + return this.tree.getValue(); + } +}); +BI.PlatformLevelTree.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.platform_level_tree", BI.PlatformLevelTree); + + +BI.DemoLevelTree = BI.inherit(BI.Widget, { + + render: function () { + var self = this; + return { + type: "bi.vtape", + items: [{ + el: { + type: "bi.platform_level_tree", + ref: function () { + self.tree = this; + }, + itemsCreator: function (op, callback) { + if (!op.node) {//根节点 + callback([{ + "id": 1, + "pId": 0, + text: "A", + value: 1, + isParent: true + }, { + "id": 2, + "pId": 0, + "text": "B", + value: 2, + isParent: true, + open: true, + }]) + } else { + if (op.node.id == 1) { + callback([ + { + "id": 11, + "pId": 1, + "text": "test11", + value: 11, + layer: 1, + isParent: true + }, + { + "id": 12, + "pId": 1, + "text": "test12", + value: 12, + layer: 1, + }, + { + "id": 13, + "pId": 1, + "text": "test13", + value: 13, + layer: 1, + }, + { + "id": 14, + "pId": 1, + "text": "test14", + value: 14, + layer: 1, + height: 35 + }, + { + "id": 15, + "pId": 1, + "text": "test15", + value: 15, + layer: 1, + }, + { + "id": 16, + "pId": 1, + "text": "test16", + value: 16, + layer: 1, + }, + {"id": 17, "pId": 1, "text": "test17", layer: 1, value: 17} + ]) + } else if (op.node.id == 2) { + callback([{ + "id": 21, + "pId": 2, + "text": "test21", + value: 21, + layer: 1, + }, + { + "id": 22, + "pId": 2, + "text": "test22", + value: 22, + layer: 1, + }]) + } else if (op.node.id == 11) { + callback([{ + "id": 111, + "pId": 11, + "text": "test111", + value: 111, + layer: 2, + }]) + } + } + } + } + }, { + el: { + type: "bi.button", + text: "确定", + handler: function () { + BI.Msg.toast(JSON.stringify(self.tree.getValue())); + } + }, + height: 25 + }] + + } + }, + + mounted: function () { + + } +}); +BI.shortcut("demo.platform_level_tree", BI.DemoLevelTree); \ No newline at end of file diff --git a/demo/js/config/component.js b/demo/js/config/component.js index 1815ca70a..755a60f95 100644 --- a/demo/js/config/component.js +++ b/demo/js/config/component.js @@ -20,4 +20,8 @@ Demo.COMPONENT_CONFIG = [{ pId: 5, text: "bi.tree_value_chooser_pane", value: "demo.tree_value_chooser_pane" +}, { + pId: 5, + text: "平台用", + value: "demo.platform_level_tree" }]; \ No newline at end of file diff --git a/docs/base.js b/docs/base.js index c64eebd0b..16c2d1714 100644 --- a/docs/base.js +++ b/docs/base.js @@ -857,7 +857,7 @@ BI.BasicButton = BI.inherit(BI.Single, { setSelected: function (b) { var o = this.options; o.selected = b; - if (this.isSelected()) { + if (b) { this.handle().element.addClass("active"); } else { this.handle().element.removeClass("active"); diff --git a/docs/demo.js b/docs/demo.js index 2f11c0973..abe7c4799 100644 --- a/docs/demo.js +++ b/docs/demo.js @@ -2618,7 +2618,221 @@ BI.shortcut("demo.center", Demo.Center);Demo.Func = BI.inherit(BI.Widget, { } }); BI.shortcut("demo.axis_chart", Demo.Func); -Demo.TreeValueChooser = BI.inherit(BI.Widget, { +/** + * guy + * 二级树 + * @class BI.PlatformLevelTree + * @extends BI.Select + */ +BI.PlatformLevelTree = BI.inherit(BI.Widget, { + props: { + baseCls: "platform-level-tree", + itemsCreator: BI.emptyFn + }, + + render: function () { + var self = this, o = this.options; + this.tree = BI.createWidget({ + type: "bi.custom_tree", + element: this, + expander: { + type: "bi.select_tree_expander", + isDefaultInit: false, + el: {}, + popup: { + type: "bi.custom_tree" + } + }, + + itemsCreator: function (op, callback) { + o.itemsCreator(op, function (items) { + callback(self._formatItems(items)) + }) + }, + + el: { + type: "bi.loader", + next: false, + el: { + type: "bi.button_tree", + chooseType: 0, + layouts: [{ + type: "bi.vertical" + }] + } + } + }); + this.tree.on(BI.CustomTree.EVENT_CHANGE, function () { + self.fireEvent(BI.PlatformLevelTree.EVENT_CHANGE, arguments); + }) + }, + + _formatItems: function (nodes) { + var self = this; + BI.each(nodes, function (i, node) { + var extend = {}; + if (node.isParent === true || BI.isNotEmptyArray(node.children)) { + switch (i) { + case 0 : + extend.type = "bi.multilayer_select_tree_first_plus_group_node"; + break; + case nodes.length - 1 : + extend.type = "bi.multilayer_select_tree_last_plus_group_node"; + break; + default : + extend.type = "bi.multilayer_select_tree_mid_plus_group_node"; + break; + } + BI.defaults(node, extend); + } else { + switch (i) { + case nodes.length - 1: + extend.type = "bi.multilayer_single_tree_last_tree_leaf_item"; + break; + default : + extend.type = "bi.multilayer_single_tree_mid_tree_leaf_item"; + } + BI.defaults(node, extend); + } + }); + return nodes; + }, + + populate: function () { + this.tree.populate(); + }, + + getValue: function () { + return this.tree.getValue(); + } +}); +BI.PlatformLevelTree.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.platform_level_tree", BI.PlatformLevelTree); + + +BI.DemoLevelTree = BI.inherit(BI.Widget, { + + render: function () { + var self = this; + return { + type: "bi.vtape", + items: [{ + el: { + type: "bi.platform_level_tree", + ref: function () { + self.tree = this; + }, + itemsCreator: function (op, callback) { + if (!op.node) {//根节点 + callback([{ + "id": 1, + "pId": 0, + text: "A", + value: 1, + isParent: true + }, { + "id": 2, + "pId": 0, + "text": "B", + value: 2, + isParent: true, + open: true, + }]) + } else { + if (op.node.id == 1) { + callback([ + { + "id": 11, + "pId": 1, + "text": "test11", + value: 11, + layer: 1, + isParent: true + }, + { + "id": 12, + "pId": 1, + "text": "test12", + value: 12, + layer: 1, + }, + { + "id": 13, + "pId": 1, + "text": "test13", + value: 13, + layer: 1, + }, + { + "id": 14, + "pId": 1, + "text": "test14", + value: 14, + layer: 1, + height: 35 + }, + { + "id": 15, + "pId": 1, + "text": "test15", + value: 15, + layer: 1, + }, + { + "id": 16, + "pId": 1, + "text": "test16", + value: 16, + layer: 1, + }, + {"id": 17, "pId": 1, "text": "test17", layer: 1, value: 17} + ]) + } else if (op.node.id == 2) { + callback([{ + "id": 21, + "pId": 2, + "text": "test21", + value: 21, + layer: 1, + }, + { + "id": 22, + "pId": 2, + "text": "test22", + value: 22, + layer: 1, + }]) + } else if (op.node.id == 11) { + callback([{ + "id": 111, + "pId": 11, + "text": "test111", + value: 111, + layer: 2, + }]) + } + } + } + } + }, { + el: { + type: "bi.button", + text: "确定", + handler: function () { + BI.Msg.toast(JSON.stringify(self.tree.getValue())); + } + }, + height: 25 + }] + + } + }, + + mounted: function () { + + } +}); +BI.shortcut("demo.platform_level_tree", BI.DemoLevelTree);Demo.TreeValueChooser = BI.inherit(BI.Widget, { props: { baseCls: "demo-tree-value-chooser-combo" }, @@ -2931,6 +3145,10 @@ Demo.COMPONENT_CONFIG = [{ pId: 5, text: "bi.tree_value_chooser_pane", value: "demo.tree_value_chooser_pane" +}, { + pId: 5, + text: "平台用", + value: "demo.platform_level_tree" }];Demo.CORE_CONFIG = [{ id: 1, text: "核心控件", diff --git a/docs/widget.js b/docs/widget.js index 9a0b7488b..fd9277951 100644 --- a/docs/widget.js +++ b/docs/widget.js @@ -9585,7 +9585,8 @@ BI.MultiSelectCombo = BI.inherit(BI.Single, { itemsCreator: function (op, callback) { o.itemsCreator(op, function (res) { if (op.times === 1 && BI.isNotNull(op.keywords)) { - self.trigger.setValue(self.getValue()); + //预防trigger内部把当前的storeValue改掉 + self.trigger.setValue(BI.deepClone(self.getValue())); } callback.apply(self, arguments); }); @@ -9638,7 +9639,7 @@ BI.MultiSelectCombo = BI.inherit(BI.Single, { assertShowValue(); }); } else { - self._join(this.getValue(), function () {//安徽省 北京 + self._join(this.getValue(), function () { assertShowValue(); }); } @@ -10431,7 +10432,8 @@ BI.MultiSelectSearchLoader = BI.inherit(BI.Widget, { }, setValue: function (v) { - this.storeValue = v; + //暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 + this.storeValue = BI.deepClone(v); this.button_group.setValue(v); }, @@ -10982,7 +10984,7 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { var assertShowValue = function () { BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); - self.trigger.setValue(self.storeValue); + // self.trigger.setValue(self.storeValue); }; this.adapter = BI.createWidget({ @@ -11034,7 +11036,7 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { action: function () { self._showSearcherPane(); self._setStartValue(""); - this.setValue(self.storeValue); + this.setValue(BI.deepClone(self.storeValue)); } }, { eventName: BI.Searcher.EVENT_STOP, diff --git a/src/base/single/button/button.basic.js b/src/base/single/button/button.basic.js index db0e4b3ab..919325d51 100644 --- a/src/base/single/button/button.basic.js +++ b/src/base/single/button/button.basic.js @@ -274,7 +274,7 @@ BI.BasicButton = BI.inherit(BI.Single, { setSelected: function (b) { var o = this.options; o.selected = b; - if (this.isSelected()) { + if (b) { this.handle().element.addClass("active"); } else { this.handle().element.removeClass("active"); diff --git a/src/widget/multiselect/multiselect.combo.js b/src/widget/multiselect/multiselect.combo.js index d5d1e1f41..b4096e75d 100644 --- a/src/widget/multiselect/multiselect.combo.js +++ b/src/widget/multiselect/multiselect.combo.js @@ -41,7 +41,8 @@ BI.MultiSelectCombo = BI.inherit(BI.Single, { itemsCreator: function (op, callback) { o.itemsCreator(op, function (res) { if (op.times === 1 && BI.isNotNull(op.keywords)) { - self.trigger.setValue(self.getValue()); + //预防trigger内部把当前的storeValue改掉 + self.trigger.setValue(BI.deepClone(self.getValue())); } callback.apply(self, arguments); }); @@ -94,7 +95,7 @@ BI.MultiSelectCombo = BI.inherit(BI.Single, { assertShowValue(); }); } else { - self._join(this.getValue(), function () {//安徽省 北京 + self._join(this.getValue(), function () { assertShowValue(); }); } diff --git a/src/widget/multiselect/search/multiselect.search.loader.js b/src/widget/multiselect/search/multiselect.search.loader.js index 20c74c61a..bdb10bef2 100644 --- a/src/widget/multiselect/search/multiselect.search.loader.js +++ b/src/widget/multiselect/search/multiselect.search.loader.js @@ -119,7 +119,8 @@ BI.MultiSelectSearchLoader = BI.inherit(BI.Widget, { }, setValue: function (v) { - this.storeValue = v; + //暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 + this.storeValue = BI.deepClone(v); this.button_group.setValue(v); }, diff --git a/src/widget/multiselectlist/multiselectlist.js b/src/widget/multiselectlist/multiselectlist.js index 72e80b550..f51654e76 100644 --- a/src/widget/multiselectlist/multiselectlist.js +++ b/src/widget/multiselectlist/multiselectlist.js @@ -17,7 +17,7 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { var assertShowValue = function () { BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); - self.trigger.setValue(self.storeValue); + // self.trigger.setValue(self.storeValue); }; this.adapter = BI.createWidget({ @@ -69,7 +69,7 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { action: function () { self._showSearcherPane(); self._setStartValue(""); - this.setValue(self.storeValue); + this.setValue(BI.deepClone(self.storeValue)); } }, { eventName: BI.Searcher.EVENT_STOP,