From 6d08657fc652ad2b2bfe98c85cc68c62739b492f Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 26 Aug 2021 21:16:24 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=94=AF=E6=8C=81i18n=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=8D=A2i18n=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 1 + src/base/single/0.single.js | 3 ++- src/base/single/1.text.js | 15 +++++++++++---- src/core/utils/i18n.js | 37 +++++++++++++++++++++++++++++++++++-- 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/changelog.md b/changelog.md index 8c8bb9ba5..75f0e66b1 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # 更新日志 2.0(2021-07) +- 支持BI.changeI18n动态换i18n方法 - layout支持forceUpdate刷新方式 - width属性支持calc() - 修改了颜色选择器交互 diff --git a/src/base/single/0.single.js b/src/base/single/0.single.js index d6cd92f2c..e12c726d1 100644 --- a/src/base/single/0.single.js +++ b/src/base/single/0.single.js @@ -196,7 +196,8 @@ BI.Single = BI.inherit(BI.Widget, { return this.options.value; }, - destroyed: function () { + __d: function () { + BI.Single.superclass.__d.call(this); if (BI.isNotNull(this.showTimeout)) { clearTimeout(this.showTimeout); this.showTimeout = null; diff --git a/src/base/single/1.text.js b/src/base/single/1.text.js index 125854873..65aa03712 100644 --- a/src/base/single/1.text.js +++ b/src/base/single/1.text.js @@ -45,13 +45,13 @@ }); } if (BI.isWidthOrHeight(o.height)) { - this.element.css({ lineHeight: BI.isNumber(o.height) ? (o.height / BI.pixRatio + BI.pixUnit) : o.height }); + this.element.css({lineHeight: BI.isNumber(o.height) ? (o.height / BI.pixRatio + BI.pixUnit) : o.height}); } if (BI.isWidthOrHeight(o.lineHeight)) { - this.element.css({ lineHeight: BI.isNumber(o.lineHeight) ? (o.lineHeight / BI.pixRatio + BI.pixUnit) : o.lineHeight }); + this.element.css({lineHeight: BI.isNumber(o.lineHeight) ? (o.lineHeight / BI.pixRatio + BI.pixUnit) : o.lineHeight}); } if (BI.isWidthOrHeight(o.maxWidth)) { - this.element.css({ maxWidth: BI.isNumber(o.maxWidth) ? (o.maxWidth / BI.pixRatio + BI.pixUnit) : o.maxWidth }); + this.element.css({maxWidth: BI.isNumber(o.maxWidth) ? (o.maxWidth / BI.pixRatio + BI.pixUnit) : o.maxWidth}); } this.element.css({ textAlign: o.textAlign, @@ -106,7 +106,9 @@ _getShowText: function () { var o = this.options; var text = BI.isFunction(o.text) ? o.text() : o.text; - + if (text && text.addWidget) { + text.addWidget(this); + } return BI.isKey(text) ? BI.Text.formatText(text + "") : text; }, @@ -152,6 +154,11 @@ BI.Text.superclass.setText.apply(this, arguments); this.options.text = text; this._doRedMark(this.options.keyword); + }, + + __d: function () { + BI.Text.superclass.__d.call(this); + BI.i18nProvider.removeWidget(this); } }); var formatters = []; diff --git a/src/core/utils/i18n.js b/src/core/utils/i18n.js index 23fd11600..f725ad666 100644 --- a/src/core/utils/i18n.js +++ b/src/core/utils/i18n.js @@ -1,6 +1,28 @@ !(function () { var i18nStore = {}; + var i18nWidgets = {}; _.extend(BI, { + i18nProvider: { + addWidget: function (widget, i18n) { + if (!i18nWidgets[widget.getName()]) { + i18nWidgets[widget.getName()] = i18n; + i18n.widget = widget; + } + }, + removeWidget: function (widget) { + if (i18nWidgets[widget.getName()]) { + delete i18nWidgets[widget.getName()]; + } + } + }, + changeI18n: function (i18n) { + if (i18n) { + i18nStore = i18n; + } + BI.each(i18nWidgets, function (widgetName, i18n) { + i18n.widget.setText(BI.i18nText.apply(null, i18n.args)); + }); + }, addI18n: function (i18n) { BI.extend(i18nStore, i18n); }, @@ -24,7 +46,18 @@ }); } } - return localeText; + return { + args: arguments, + addWidget: function (widget) { + BI.i18nProvider.addWidget(widget, this); + }, + valueOf: function () { + return localeText; + }, + toString: function () { + return localeText; + } + }; } }); -})(); \ No newline at end of file +})(); From bf1e026b647a198b6cacf2a0b932ebe05ba10547 Mon Sep 17 00:00:00 2001 From: guy Date: Fri, 27 Aug 2021 09:44:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=94=AF=E6=8C=81i18n=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 1 - src/base/single/1.text.js | 4 ---- src/core/utils/i18n.js | 30 +----------------------------- 3 files changed, 1 insertion(+), 34 deletions(-) diff --git a/changelog.md b/changelog.md index 75f0e66b1..8c8bb9ba5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,5 @@ # 更新日志 2.0(2021-07) -- 支持BI.changeI18n动态换i18n方法 - layout支持forceUpdate刷新方式 - width属性支持calc() - 修改了颜色选择器交互 diff --git a/src/base/single/1.text.js b/src/base/single/1.text.js index 65aa03712..2fc5adfb7 100644 --- a/src/base/single/1.text.js +++ b/src/base/single/1.text.js @@ -106,9 +106,6 @@ _getShowText: function () { var o = this.options; var text = BI.isFunction(o.text) ? o.text() : o.text; - if (text && text.addWidget) { - text.addWidget(this); - } return BI.isKey(text) ? BI.Text.formatText(text + "") : text; }, @@ -158,7 +155,6 @@ __d: function () { BI.Text.superclass.__d.call(this); - BI.i18nProvider.removeWidget(this); } }); var formatters = []; diff --git a/src/core/utils/i18n.js b/src/core/utils/i18n.js index f725ad666..0dbf0a1a9 100644 --- a/src/core/utils/i18n.js +++ b/src/core/utils/i18n.js @@ -1,27 +1,10 @@ !(function () { var i18nStore = {}; - var i18nWidgets = {}; _.extend(BI, { - i18nProvider: { - addWidget: function (widget, i18n) { - if (!i18nWidgets[widget.getName()]) { - i18nWidgets[widget.getName()] = i18n; - i18n.widget = widget; - } - }, - removeWidget: function (widget) { - if (i18nWidgets[widget.getName()]) { - delete i18nWidgets[widget.getName()]; - } - } - }, changeI18n: function (i18n) { if (i18n) { i18nStore = i18n; } - BI.each(i18nWidgets, function (widgetName, i18n) { - i18n.widget.setText(BI.i18nText.apply(null, i18n.args)); - }); }, addI18n: function (i18n) { BI.extend(i18nStore, i18n); @@ -46,18 +29,7 @@ }); } } - return { - args: arguments, - addWidget: function (widget) { - BI.i18nProvider.addWidget(widget, this); - }, - valueOf: function () { - return localeText; - }, - toString: function () { - return localeText; - } - }; + return localeText; } }); })(); From da97b6be0b91cc839098de4860daffd73850cab3 Mon Sep 17 00:00:00 2001 From: guy Date: Fri, 27 Aug 2021 09:45:30 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/single/1.text.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/base/single/1.text.js b/src/base/single/1.text.js index 2fc5adfb7..cc6081e7f 100644 --- a/src/base/single/1.text.js +++ b/src/base/single/1.text.js @@ -151,10 +151,6 @@ BI.Text.superclass.setText.apply(this, arguments); this.options.text = text; this._doRedMark(this.options.keyword); - }, - - __d: function () { - BI.Text.superclass.__d.call(this); } }); var formatters = [];