From f0fd06cc838b448d56fa109174950e7ac6109be7 Mon Sep 17 00:00:00 2001 From: treecat Date: Tue, 21 Jun 2022 15:51:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?DESIGN-4069=20feat:=20button=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20setIcon=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/js/base/button/demo.button.js | 15 +++++++++++++++ src/base/single/button/buttons/button.js | 11 +++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/demo/js/base/button/demo.button.js b/demo/js/base/button/demo.button.js index 400559566..056564c9f 100644 --- a/demo/js/base/button/demo.button.js +++ b/demo/js/base/button/demo.button.js @@ -376,6 +376,21 @@ Demo.Button = BI.inherit(BI.Widget, { plain: true, disabled: true } + }, { + el: { + type: "bi.button", + iconCls: "plus-font", + text: "点我,更改图标", + handler() { + this.i = this.i === undefined ? 0 : ++this.i; + const arr = ["text-background-font", "check-mark-ha-font", "close-font", "search-font", "date-change-h-font"]; + if(this.i >= arr.length) { + this.i = 0; + } + this.setIcon(arr[this.i]); + }, + height: 24 + } }]; // BI.each(items, function (i, item) { // item.el.handler = function () { diff --git a/src/base/single/button/buttons/button.js b/src/base/single/button/buttons/button.js index 78e910f7c..0ba1468b4 100644 --- a/src/base/single/button/buttons/button.js +++ b/src/base/single/button/buttons/button.js @@ -77,8 +77,8 @@ } if (BI.isKey(o.iconCls)) { this.icon = BI.createWidget({ - type: "bi.icon_label", - cls: o.iconCls, + type: "bi.icon_change_button", + iconCls: o.iconCls, width: this._const.iconWidth, height: lineHeight, lineHeight: lineHeight @@ -195,6 +195,13 @@ } }, + setIcon: function (iconCls) { + if (this.icon) { + this.options.iconCls = iconCls; + this.icon.setIcon(iconCls); + } + }, + doRedMark: function () { this.text.doRedMark.apply(this.text, arguments); }, From 0e4efcc66f94279b659fbae7cb4ad5b95a98c00c Mon Sep 17 00:00:00 2001 From: treecat Date: Tue, 21 Jun 2022 16:37:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?DESIGN-4069=20fix:=20button=20=E7=9A=84=20s?= =?UTF-8?q?etIcon=20=E4=B8=8D=E4=BD=BF=E7=94=A8=20IconChangeButton?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/single/button/buttons/button.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/base/single/button/buttons/button.js b/src/base/single/button/buttons/button.js index 0ba1468b4..39a116c77 100644 --- a/src/base/single/button/buttons/button.js +++ b/src/base/single/button/buttons/button.js @@ -77,8 +77,8 @@ } if (BI.isKey(o.iconCls)) { this.icon = BI.createWidget({ - type: "bi.icon_change_button", - iconCls: o.iconCls, + type: "bi.icon_label", + cls: o.iconCls, width: this._const.iconWidth, height: lineHeight, lineHeight: lineHeight @@ -195,10 +195,11 @@ } }, - setIcon: function (iconCls) { - if (this.icon) { - this.options.iconCls = iconCls; - this.icon.setIcon(iconCls); + setIcon: function (cls) { + var o = this.options; + if(this.icon && o.iconCls !== cls) { + this.icon.element.removeClass(o.iconCls).addClass(cls); + o.iconCls = cls; } },