From 0c009add2c665799a3a2c38b98b7ced980bcdb45 Mon Sep 17 00:00:00 2001 From: "Zhenfei.Li" Date: Wed, 11 Jan 2023 10:31:14 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-14071=20refactor:=20case/trigger?= =?UTF-8?q?=E7=9A=84es6=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es6.js | 7 + src/base/single/trigger/trigger.js | 2 +- src/case/index.js | 3 + src/case/trigger/index.js | 8 + src/case/trigger/trigger.editor.js | 105 ++++++------ src/case/trigger/trigger.icon.js | 33 ++-- src/case/trigger/trigger.icon.text.js | 84 ++++----- src/case/trigger/trigger.icon.text.select.js | 67 ++++---- src/case/trigger/trigger.text.js | 159 +++++++++--------- src/case/trigger/trigger.text.select.js | 102 +++++------ src/case/trigger/trigger.text.select.small.js | 66 ++++---- src/case/trigger/trigger.text.small.js | 64 +++---- 12 files changed, 374 insertions(+), 326 deletions(-) create mode 100644 src/case/trigger/index.js diff --git a/es6.js b/es6.js index 9c0b18bf4..2fa0181eb 100644 --- a/es6.js +++ b/es6.js @@ -97,6 +97,13 @@ collection.methods.forEach(el => { "isString", "isNumber", "isEmpty", + "isEmptyString", + "any", + "deepContains", + "isNotEmptyString", + "each", + "contains", + "remove", ]; target.forEach(t => { diff --git a/src/base/single/trigger/trigger.js b/src/base/single/trigger/trigger.js index 3755fc8ae..af9db4078 100644 --- a/src/base/single/trigger/trigger.js +++ b/src/base/single/trigger/trigger.js @@ -12,7 +12,7 @@ export class Trigger extends Single { const conf = super._defaultConfig(...arguments); return extend(conf, { - _baseCls: (conf._baseCls || "") + " bi-trigger cursor-pointer", + _baseCls: `${conf._baseCls || ""} bi-trigger cursor-pointer`, height: 24, }); } diff --git a/src/case/index.js b/src/case/index.js index 1b8b33c0b..515a45107 100644 --- a/src/case/index.js +++ b/src/case/index.js @@ -2,16 +2,19 @@ import * as button from "./button"; import * as calendarItem from "./calendar"; import * as pager from "./pager"; import * as editor from "./editor"; +import * as trigger from "./trigger"; Object.assign(BI, { ...button, ...calendarItem, ...pager, ...editor, + ...trigger, }); export * from "./button"; export * from "./calendar"; export * from "./pager"; export * from "./editor"; +export * from "./trigger"; diff --git a/src/case/trigger/index.js b/src/case/trigger/index.js new file mode 100644 index 000000000..df4e68ab5 --- /dev/null +++ b/src/case/trigger/index.js @@ -0,0 +1,8 @@ +export { EditorTrigger } from "./trigger.editor"; +export { IconTrigger } from "./trigger.icon"; +export { IconTextTrigger } from "./trigger.icon.text"; +export { SelectIconTextTrigger } from "./trigger.icon.text.select"; +export { TextTrigger } from "./trigger.text"; +export { SelectTextTrigger } from "./trigger.text.select"; +export { SmallSelectTextTrigger } from "./trigger.text.select.small"; +export { SmallTextTrigger } from "./trigger.text.small"; diff --git a/src/case/trigger/trigger.editor.js b/src/case/trigger/trigger.editor.js index 5bdcc8f56..3bb8439ac 100644 --- a/src/case/trigger/trigger.editor.js +++ b/src/case/trigger/trigger.editor.js @@ -1,93 +1,98 @@ +import { shortcut, extend, emptyFn, createWidget, toPix, Controller } from "@/core"; +import { Trigger } from "@/base"; +import { SignEditor } from "../editor"; + /** * 文本输入框trigger * * Created by GUY on 2015/9/15. - * @class BI.EditorTrigger - * @extends BI.Trigger + * @class EditorTrigger + * @extends Trigger */ -BI.EditorTrigger = BI.inherit(BI.Trigger, { - _defaultConfig: function (config) { - var conf = BI.EditorTrigger.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-editor-trigger bi-border-radius " + (config.simple ? "bi-border-bottom" : "bi-border"), +@shortcut() +export class EditorTrigger extends Trigger { + static xtype = "bi.editor_trigger"; + static EVENT_CHANGE = "EVENT_CHANGE"; + static EVENT_FOCUS = "EVENT_FOCUS"; + static EVENT_EMPTY = "EVENT_EMPTY"; + static EVENT_VALID = "EVENT_VALID"; + static EVENT_ERROR = "EVENT_ERROR"; + + _defaultConfig(config) { + const conf = super._defaultConfig(...arguments); + + return extend(conf, { + baseCls: `${conf.baseCls || ""} bi-editor-trigger bi-border-radius ${config.simple ? "bi-border-bottom" : "bi-border"}`, height: 24, - validationChecker: BI.emptyFn, - quitChecker: BI.emptyFn, + validationChecker: emptyFn, + quitChecker: emptyFn, allowBlank: false, watermark: "", - errorText: "" + errorText: "", }); - }, + } - _init: function () { - BI.EditorTrigger.superclass._init.apply(this, arguments); - var self = this, o = this.options, c = this._const; - this.editor = BI.createWidget({ + _init() { + super._init(...arguments); + const o = this.options; + this.editor = createWidget({ type: "bi.sign_editor", - height: BI.toPix(o.height, 2), + height: toPix(o.height, 2), value: o.value, validationChecker: o.validationChecker, quitChecker: o.quitChecker, allowBlank: o.allowBlank, watermark: o.watermark, errorText: o.errorText, - title: function () { - return self.getValue(); - } + title: () => this.getValue(), }); - this.editor.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.editor.on(Controller.EVENT_CHANGE, (...args) => { + this.fireEvent(Controller.EVENT_CHANGE, ...args); }); - this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { - self.fireEvent(BI.EditorTrigger.EVENT_CHANGE, arguments); + this.editor.on(SignEditor.EVENT_CHANGE, (...args) => { + this.fireEvent(EditorTrigger.EVENT_CHANGE, ...args); }); - this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.EditorTrigger.EVENT_FOCUS, arguments); + this.editor.on(SignEditor.EVENT_FOCUS, (...args) => { + this.fireEvent(EditorTrigger.EVENT_FOCUS, ...args); }); - this.editor.on(BI.SignEditor.EVENT_EMPTY, function () { - self.fireEvent(BI.EditorTrigger.EVENT_EMPTY, arguments); + this.editor.on(SignEditor.EVENT_EMPTY, (...args) => { + this.fireEvent(EditorTrigger.EVENT_EMPTY, ...args); }); - this.editor.on(BI.SignEditor.EVENT_VALID, function () { - self.fireEvent(BI.EditorTrigger.EVENT_VALID, arguments); + this.editor.on(SignEditor.EVENT_VALID, (...args) => { + this.fireEvent(EditorTrigger.EVENT_VALID, ...args); }); - this.editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.EditorTrigger.EVENT_ERROR, arguments); + this.editor.on(SignEditor.EVENT_ERROR, (...args) => { + this.fireEvent(EditorTrigger.EVENT_ERROR, ...args); }); - BI.createWidget({ + createWidget({ element: this, type: "bi.horizontal_fill", - height: BI.toPix(o.height, 2), + height: toPix(o.height, 2), items: [ { el: this.editor, - width: "fill" + width: "fill", }, { el: { type: "bi.trigger_icon_button", - width: o.triggerWidth || BI.toPix(o.height, 2) + width: o.triggerWidth || toPix(o.height, 2), }, - width: "" + width: "", } - ] + ], }); - }, + } - getValue: function () { + getValue() { return this.editor.getValue(); - }, + } - setValue: function (value) { + setValue(value) { this.editor.setValue(value); - }, + } - setText: function (text) { + setText(text) { this.editor.setState(text); } -}); -BI.EditorTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.EditorTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.EditorTrigger.EVENT_EMPTY = "EVENT_EMPTY"; -BI.EditorTrigger.EVENT_VALID = "EVENT_VALID"; -BI.EditorTrigger.EVENT_ERROR = "EVENT_ERROR"; -BI.shortcut("bi.editor_trigger", BI.EditorTrigger); +} diff --git a/src/case/trigger/trigger.icon.js b/src/case/trigger/trigger.icon.js index 2da61d480..3368dd070 100644 --- a/src/case/trigger/trigger.icon.js +++ b/src/case/trigger/trigger.icon.js @@ -1,30 +1,35 @@ +import { shortcut, extend, createWidget } from "@/core"; +import { Trigger } from "@/base"; + /** * 图标按钮trigger * * Created by GUY on 2015/10/8. - * @class BI.IconTrigger - * @extends BI.Trigger + * @class IconTrigger + * @extends Trigger */ -BI.IconTrigger = BI.inherit(BI.Trigger, { +@shortcut() +export class IconTrigger extends Trigger { + static xtype = "bi.icon_trigger" - _defaultConfig: function () { - return BI.extend(BI.IconTrigger.superclass._defaultConfig.apply(this, arguments), { + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { baseCls: "bi-icon-trigger", extraCls: "pull-down-font", el: {}, - height: 24 + height: 24, }); - }, - _init: function () { - var o = this.options; - BI.IconTrigger.superclass._init.apply(this, arguments); - this.iconButton = BI.createWidget(o.el, { + } + + _init() { + const o = this.options; + super._init(...arguments); + this.iconButton = createWidget(o.el, { type: "bi.trigger_icon_button", element: this, width: o.width, height: o.height, - extraCls: o.extraCls + extraCls: o.extraCls, }); } -}); -BI.shortcut("bi.icon_trigger", BI.IconTrigger); \ No newline at end of file +} diff --git a/src/case/trigger/trigger.icon.text.js b/src/case/trigger/trigger.icon.text.js index a102b5d0c..b93c3181b 100644 --- a/src/case/trigger/trigger.icon.text.js +++ b/src/case/trigger/trigger.icon.text.js @@ -1,29 +1,35 @@ +import { shortcut, extend, isKey, createWidget, isEmptyString } from "@/core"; +import { Trigger } from "@/base"; + /** * 文字trigger * * Created by GUY on 2015/9/15. - * @class BI.IconTextTrigger - * @extends BI.Trigger + * @class IconTextTrigger + * @extends Trigger */ -BI.IconTextTrigger = BI.inherit(BI.Trigger, { +@shortcut() +export class IconTextTrigger extends Trigger { + static xtype = "bi.icon_text_trigger" - _defaultConfig: function () { - var conf = BI.IconTextTrigger.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-text-trigger", + _defaultConfig() { + const conf = super._defaultConfig(...arguments); + + return extend(conf, { + baseCls: `${conf.baseCls || ""} bi-text-trigger`, height: 24, iconHeight: null, iconWidth: null, - textCls: "" + textCls: "", }); - }, + } - _init: function () { - BI.IconTextTrigger.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.text = BI.createWidget({ + _init() { + super._init(...arguments); + const o = this.options; + this.text = createWidget({ type: "bi.label", - cls: "select-text-label" + (BI.isKey(o.textCls) ? (" " + o.textCls) : ""), + cls: `select-text-label${isKey(o.textCls) ? (` ${o.textCls}`) : ""}`, textAlign: "left", height: o.height, hgap: o.textHgap, @@ -32,19 +38,19 @@ BI.IconTextTrigger = BI.inherit(BI.Trigger, { rgap: o.textRgap, tgap: o.textTgap, bgap: o.textBgap, - text: o.text + text: o.text, }); - this.trigerButton = BI.createWidget({ + this.trigerButton = createWidget({ type: "bi.trigger_icon_button", - width: o.triggerWidth || o.height + width: o.triggerWidth || o.height, }); - BI.createWidget({ + createWidget({ element: this, type: "bi.horizontal_fill", columnSize: ["", "fill", ""], - ref: function (_ref) { - self.wrapper = _ref; + ref: _ref => { + this.wrapper = _ref; }, items: [{ el: { @@ -53,41 +59,39 @@ BI.IconTextTrigger = BI.inherit(BI.Trigger, { width: o.triggerWidth || o.height, iconCls: o.iconCls, invisible: !o.iconCls, - ref: function (_ref) { - self.icon = _ref; + ref: _ref => { + this.icon = _ref; }, iconHeight: o.iconHeight, iconWidth: o.iconWidth, - disableSelected: true - } + disableSelected: true, + }, }, { el: this.text, - lgap: BI.isEmptyString(o.iconCls) ? 5 : 0 + lgap: isEmptyString(o.iconCls) ? 5 : 0, }, { - el: this.trigerButton - }] + el: this.trigerButton, + }], }); - }, + } - setValue: function (value) { + setValue(value) { this.text.setValue(value); - }, + } - setIcon: function (iconCls) { - var o = this.options; + setIcon(iconCls) { this.icon.setIcon(iconCls); this.icon.setVisible(!!iconCls); - }, + } - setTextCls: function (cls) { - var o = this.options; - var oldCls = o.textCls; + setTextCls(cls) { + const o = this.options; + const oldCls = o.textCls; o.textCls = cls; this.text.element.removeClass(oldCls).addClass(cls); - }, + } - setText: function (text) { + setText(text) { this.text.setText(text); } -}); -BI.shortcut("bi.icon_text_trigger", BI.IconTextTrigger); +} diff --git a/src/case/trigger/trigger.icon.text.select.js b/src/case/trigger/trigger.icon.text.select.js index b0142b91e..0045972a4 100644 --- a/src/case/trigger/trigger.icon.text.select.js +++ b/src/case/trigger/trigger.icon.text.select.js @@ -1,23 +1,28 @@ +import { shortcut, extend, createWidget, isFunction, isArray, isNotNull, any, deepContains, Tree } from "@/core"; +import { Trigger } from "@/base"; + /** * Created by Windy on 2017/12/12. */ -BI.SelectIconTextTrigger = BI.inherit(BI.Trigger, { +@shortcut() +export class SelectIconTextTrigger extends Trigger { + static xtype = "bi.select_icon_text_trigger" - _defaultConfig: function () { - return BI.extend(BI.SelectIconTextTrigger.superclass._defaultConfig.apply(this, arguments), { + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { baseCls: "bi-select-text-trigger", height: 24, iconHeight: null, iconWidth: null, - iconCls: "" + iconCls: "", }); - }, + } - _init: function () { - BI.SelectIconTextTrigger.superclass._init.apply(this, arguments); - var self = this, o = this.options; - var obj = this._digist(o.value, o.items); - this.trigger = BI.createWidget({ + _init() { + super._init(...arguments); + const o = this.options; + const obj = this._digist(o.value, o.items); + this.trigger = createWidget({ type: "bi.icon_text_trigger", element: this, text: obj.text, @@ -32,49 +37,49 @@ BI.SelectIconTextTrigger = BI.inherit(BI.Trigger, { height: o.height, iconHeight: o.iconHeight, iconWidth: o.iconWidth, - iconWrapperWidth: o.iconWrapperWidth + iconWrapperWidth: o.iconWrapperWidth, }); - }, + } - _digist: function (vals, items) { - var o = this.options; - vals = BI.isArray(vals) ? vals : [vals]; - var result; - var formatItems = BI.Tree.transformToArrayFormat(items); - BI.any(formatItems, function (i, item) { - if (BI.deepContains(vals, item.value)) { + _digist(vals, items) { + const o = this.options; + vals = isArray(vals) ? vals : [vals]; + let result; + const formatItems = Tree.transformToArrayFormat(items); + any(formatItems, (i, item) => { + if (deepContains(vals, item.value)) { result = { text: item.text || item.value, - iconCls: item.iconCls + iconCls: item.iconCls, }; + return true; } }); - if (BI.isNotNull(result)) { + if (isNotNull(result)) { return { text: result.text, textCls: "", - iconCls: result.iconCls + iconCls: result.iconCls, }; } else { return { - text: BI.isFunction(o.text) ? o.text() : o.text, + text: isFunction(o.text) ? o.text() : o.text, textCls: "bi-water-mark", - iconCls: o.iconCls + iconCls: o.iconCls, }; } - }, + } - setValue: function (vals) { - var obj = this._digist(vals, this.options.items); + setValue(vals) { + const obj = this._digist(vals, this.options.items); this.trigger.setText(obj.text); this.trigger.setIcon(obj.iconCls); this.trigger.setTextCls(obj.textCls); - }, + } - populate: function (items) { + populate(items) { this.options.items = items; } -}); -BI.shortcut("bi.select_icon_text_trigger", BI.SelectIconTextTrigger); +} diff --git a/src/case/trigger/trigger.text.js b/src/case/trigger/trigger.text.js index 6e7273252..f4e15110d 100644 --- a/src/case/trigger/trigger.text.js +++ b/src/case/trigger/trigger.text.js @@ -1,41 +1,45 @@ +import { shortcut, isFunction, isKey, isNotEmptyString } from "@/core"; +import { Trigger } from "@/base"; + /** * 文字trigger * * Created by GUY on 2015/9/15. - * @class BI.TextTrigger - * @extends BI.Trigger + * @class TextTrigger + * @extends Trigger */ -BI.TextTrigger = BI.inherit(BI.Trigger, { +@shortcut() +export class TextTrigger extends Trigger { + static xtype = "bi.text_trigger" + + static EVENT_CLEAR = "EVENT_CLEAR" - props: function () { - var self = this; + props() { return { baseCls: "bi-text-trigger", height: 24, textHgap: 6, textCls: "", allowClear: false, - title: function () { - return self.text.getText(); - }, + title: () => this.text.getText(), defaultText: "", text: "", }; - }, + } - render: function () { - var self = this, o = this.options, c = this._const; + render() { + const o = this.options; - var text = this.getText(); + const text = this.getText(); - var defaultText = this.getDefaultText(); + const defaultText = this.getDefaultText(); - var label = { + const label = { type: "bi.label", - ref: function (_ref) { - self.text = _ref; + ref: _ref => { + this.text = _ref; }, - cls: `select-text-label ${o.textCls} ${!BI.isNotEmptyString(text) && BI.isNotEmptyString(defaultText) ? "bi-tips" : ""}`, + cls: `select-text-label ${o.textCls} ${!isNotEmptyString(text) && isNotEmptyString(defaultText) ? "bi-tips" : ""}`, textAlign: "left", height: o.height, text: text || o.defaultText, @@ -47,98 +51,93 @@ BI.TextTrigger = BI.inherit(BI.Trigger, { rgap: o.textRgap, tgap: o.textTgap, bgap: o.textBgap, - readonly: o.readonly + readonly: o.readonly, }; - var triggerButton = { + const triggerButton = { type: "bi.trigger_icon_button", - ref: function (_ref) { - self.triggerButton = _ref; + ref: _ref => { + this.triggerButton = _ref; }, - width: o.triggerWidth || o.height + width: o.triggerWidth || o.height, }; return ({ type: "bi.horizontal_fill", columnSize: ["fill", ""], - items: [ - { - el: label, - width: "fill" - }, { - el: o.allowClear ? { - type: "bi.vertical_adapt", - width: o.triggerWidth || o.height, - height: o.height, - horizontalAlign: "left", - scrollable: false, - items: [ - { - el: { - type: "bi.icon_button", - ref: function (_ref) { - self.clearBtn = _ref; - }, - cls: "close-h-font " + (o.allowClear ? "clear-button" : ""), - stopPropagation: true, - width: o.triggerWidth || o.height, - invisible: !BI.isNotEmptyString(o.text), - handler: function () { - self.fireEvent(BI.TextTrigger.EVENT_CLEAR); - }, - }, - }, { - el: triggerButton, - } - ] - } : triggerButton, - } - ] + items: [{ + el: label, + width: "fill", + }, { + el: o.allowClear ? { + type: "bi.vertical_adapt", + width: o.triggerWidth || o.height, + height: o.height, + horizontalAlign: "left", + scrollable: false, + items: [{ + el: { + type: "bi.icon_button", + ref: _ref => { + this.clearBtn = _ref; + }, + cls: `close-h-font ${o.allowClear ? "clear-button" : ""}`, + stopPropagation: true, + width: o.triggerWidth || o.height, + invisible: !isNotEmptyString(o.text), + handler: () => { + this.fireEvent(TextTrigger.EVENT_CLEAR); + }, + }, + }, { + el: triggerButton, + }], + } : triggerButton, + }], }); - }, + } - getText: function () { - var o = this.options; - return BI.isFunction(o.text) ? o.text() : o.text; - }, + getText() { + const o = this.options; + + return isFunction(o.text) ? o.text() : o.text; + } - getDefaultText: function () { - var o = this.options; - return BI.isFunction(o.defaultText) ? o.defaultText() : o.defaultText; - }, + getDefaultText() { + const o = this.options; + + return isFunction(o.defaultText) ? o.defaultText() : o.defaultText; + } - getTextor: function () { + getTextor() { return this.text; - }, + } - setTextCls: function (cls) { - var o = this.options; - var oldCls = o.textCls; + setTextCls(cls) { + const o = this.options; + const oldCls = o.textCls; o.textCls = cls; this.text.element.removeClass(oldCls).addClass(cls); - }, + } - setText: function (text) { + setText(text) { if (this.options.allowClear) { - this.clearBtn.setVisible(BI.isNotEmptyString(text)); + this.clearBtn.setVisible(isNotEmptyString(text)); } - if (BI.isKey(text)) { + if (isKey(text)) { this.text.setText(text); this.text.element.removeClass("bi-tips"); - } else if (BI.isKey(this.options.defaultText)) { + } else if (isKey(this.options.defaultText)) { this.text.setText(this.options.defaultText); this.text.element.addClass("bi-tips"); } else { this.text.setText(""); this.text.element.removeClass("bi-tips"); } - }, + } - setTipType: function (v) { + setTipType(v) { this.text.options.tipType = v; this.options.tipType = v; } -}); - -BI.TextTrigger.EVENT_CLEAR = "EVENT_CLEAR"; -BI.shortcut("bi.text_trigger", BI.TextTrigger); +} diff --git a/src/case/trigger/trigger.text.select.js b/src/case/trigger/trigger.text.select.js index 005ac241b..8094a424d 100644 --- a/src/case/trigger/trigger.text.select.js +++ b/src/case/trigger/trigger.text.select.js @@ -1,32 +1,40 @@ +import { shortcut, extend, emptyFn, createWidget, isFunction, isArray, Tree, each, contains, remove } from "@/core"; +import { Trigger } from "@/base"; +import { TextTrigger } from "./trigger.text"; + /** * 选择字段trigger * * Created by GUY on 2015/9/15. - * @class BI.SelectTextTrigger - * @extends BI.Trigger + * @class SelectTextTrigger + * @extends Trigger */ -BI.SelectTextTrigger = BI.inherit(BI.Trigger, { +@shortcut() +export class SelectTextTrigger extends Trigger { + static xtype = "bi.select_text_trigger" + + static EVENT_CLEAR = "EVENT_CLEAR" - _defaultConfig: function () { - return BI.extend(BI.SelectTextTrigger.superclass._defaultConfig.apply(this, arguments), { + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { baseCls: "bi-select-text-trigger", height: 24, allowClear: false, - valueFormatter: BI.emptyFn, + valueFormatter: emptyFn, defaultText: "", }); - }, + } - _init: function () { - BI.SelectTextTrigger.superclass._init.apply(this, arguments); - var self = this, o = this.options; - var text = this._digest(o.value, o.items); - this.trigger = BI.createWidget({ + _init() { + super._init(...arguments); + const o = this.options; + const text = this._digest(o.value, o.items); + this.trigger = createWidget({ type: "bi.text_trigger", element: this, height: o.height, readonly: o.readonly, - text: text, + text, defaultText: o.defaultText, textHgap: o.textHgap, textVgap: o.textVgap, @@ -37,71 +45,67 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, { tipType: o.tipType, title: null, allowClear: o.allowClear, - listeners: [ - { - eventName: BI.TextTrigger.EVENT_CLEAR, - action: function () { - self.setText(""); - self.fireEvent(BI.SelectTextTrigger.EVENT_CLEAR); - } - } - ] + listeners: [{ + eventName: TextTrigger.EVENT_CLEAR, + action: () => { + this.setText(""); + this.fireEvent(SelectTextTrigger.EVENT_CLEAR); + }, + }], }); - }, + } - _digest: function (val, items) { - var o = this.options; + _digest(val, items) { + const o = this.options; - val = BI.isArray(val) ? val.slice() : [val]; + val = isArray(val) ? val.slice() : [val]; - var result = []; + const result = []; // 提升valueFormatter的优先级 - if (o.valueFormatter !== BI.emptyFn && BI.isFunction(o.valueFormatter)) { - BI.each(val, function (index, v) { + if (o.valueFormatter !== emptyFn && isFunction(o.valueFormatter)) { + each(val, (index, v) => { result.push(o.valueFormatter(v)); }); + return result.join(","); } - var formatItems = BI.Tree.transformToArrayFormat(items); - BI.each(formatItems, function (i, item) { - if (BI.contains(val, item.value) && !BI.contains(result, item.text || item.value)) { + const formatItems = Tree.transformToArrayFormat(items); + each(formatItems, (i, item) => { + if (contains(val, item.value) && !contains(result, item.text || item.value)) { result.push(item.text || item.value); - BI.remove(val, item.value); + remove(val, item.value); } }); if (result.length > 0 && val.length === 0) { return result.join(","); } else { - return BI.isFunction(o.text) ? o.text() : o.text; + return isFunction(o.text) ? o.text() : o.text; } - }, + } - setText: function (text) { + setText(text) { this.options.text = text; this.trigger.setText(text); - }, + } - setValue: function (val) { - var formatText = this._digest(val, this.options.items); + setValue(val) { + const formatText = this._digest(val, this.options.items); this.trigger.setText(formatText); - }, + } - setTipType: function (v) { + setTipType(v) { this.options.tipType = v; this.trigger.setTipType(v); - }, + } - getTextor: function () { + getTextor() { return this.trigger.getTextor(); - }, + } - populate: function (items) { + populate(items) { this.options.items = items; } -}); - -BI.SelectTextTrigger.EVENT_CLEAR = "EVENT_CLEAR"; -BI.shortcut("bi.select_text_trigger", BI.SelectTextTrigger); +} diff --git a/src/case/trigger/trigger.text.select.small.js b/src/case/trigger/trigger.text.select.small.js index adbd5603c..944ee1a51 100644 --- a/src/case/trigger/trigger.text.select.small.js +++ b/src/case/trigger/trigger.text.select.small.js @@ -1,26 +1,31 @@ +import { shortcut, extend, toPix, createWidget, isArray, deepContains, each, contains, Tree } from "@/core"; +import { Trigger } from "@/base"; + /** * 选择字段trigger小一号的 * - * @class BI.SmallSelectTextTrigger - * @extends BI.Trigger + * @class SmallSelectTextTrigger + * @extends Trigger */ -BI.SmallSelectTextTrigger = BI.inherit(BI.Trigger, { +@shortcut() +export class SmallSelectTextTrigger extends Trigger { + static xtype = "bi.small_select_text_trigger" - _defaultConfig: function () { - return BI.extend(BI.SmallSelectTextTrigger.superclass._defaultConfig.apply(this, arguments), { + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { baseCls: "bi-small-select-text-trigger bi-border", height: 20, }); - }, + } - _init: function () { - BI.SmallSelectTextTrigger.superclass._init.apply(this, arguments); - var self = this, o = this.options; - var obj = this._digest(o.value, o.items); - this.trigger = BI.createWidget({ + _init() { + super._init(...arguments); + const o = this.options; + const obj = this._digest(o.value, o.items); + this.trigger = createWidget({ type: "bi.small_text_trigger", element: this, - height: BI.toPix(o.height, 2), + height: toPix(o.height, 2), text: obj.text, cls: obj.cls, textHgap: o.textHgap, @@ -30,15 +35,15 @@ BI.SmallSelectTextTrigger = BI.inherit(BI.Trigger, { textTgap: o.textTgap, textBgap: o.textBgap, }); - }, + } - _digest: function(vals, items){ - var o = this.options; - vals = BI.isArray(vals) ? vals : [vals]; - var result = []; - var formatItems = BI.Tree.transformToArrayFormat(items); - BI.each(formatItems, function (i, item) { - if (BI.deepContains(vals, item.value) && !BI.contains(result, item.text || item.value)) { + _digest(vals, items) { + const o = this.options; + vals = isArray(vals) ? vals : [vals]; + const result = []; + const formatItems = Tree.transformToArrayFormat(items); + each(formatItems, (i, item) => { + if (deepContains(vals, item.value) && !contains(result, item.text || item.value)) { result.push(item.text || item.value); } }); @@ -46,24 +51,23 @@ BI.SmallSelectTextTrigger = BI.inherit(BI.Trigger, { if (result.length > 0) { return { cls: "", - text: result.join(",") - } + text: result.join(","), + }; } else { return { cls: "bi-water-mark", - text: o.text - } + text: o.text, + }; } - }, + } - setValue: function (vals) { - var formatValue = this._digest(vals, this.options.items); + setValue(vals) { + const formatValue = this._digest(vals, this.options.items); this.trigger.element.removeClass("bi-water-mark").addClass(formatValue.cls); this.trigger.setText(formatValue.text); - }, + } - populate: function (items) { + populate(items) { this.options.items = items; } -}); -BI.shortcut("bi.small_select_text_trigger", BI.SmallSelectTextTrigger); +} diff --git a/src/case/trigger/trigger.text.small.js b/src/case/trigger/trigger.text.small.js index 27c395a69..9269a4210 100644 --- a/src/case/trigger/trigger.text.small.js +++ b/src/case/trigger/trigger.text.small.js @@ -1,23 +1,30 @@ +import { shortcut, extend, createWidget } from "@/core"; +import { Trigger } from "@/base"; + /** * 文字trigger(右边小三角小一号的) == * - * @class BI.SmallTextTrigger - * @extends BI.Trigger + * @class SmallTextTrigger + * @extends Trigger */ -BI.SmallTextTrigger = BI.inherit(BI.Trigger, { - _defaultConfig: function () { - var conf = BI.SmallTextTrigger.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-text-trigger", +@shortcut() +export class SmallTextTrigger extends Trigger { + static xtype = "bi.small_text_trigger" + + _defaultConfig() { + const conf = super._defaultConfig(...arguments); + + return extend(conf, { + baseCls: `${conf.baseCls || ""} bi-text-trigger`, height: 20, textHgap: 6, }); - }, + } - _init: function () { - BI.SmallTextTrigger.superclass._init.apply(this, arguments); - var self = this, o = this.options, c = this._const; - this.text = BI.createWidget({ + _init() { + super._init(...arguments); + const o = this.options; + this.text = createWidget({ type: "bi.label", textAlign: "left", height: o.height, @@ -29,32 +36,29 @@ BI.SmallTextTrigger = BI.inherit(BI.Trigger, { tgap: o.textTgap, bgap: o.textBgap, }); - this.trigerButton = BI.createWidget({ + this.trigerButton = createWidget({ type: "bi.trigger_icon_button", - width: o.triggerWidth || o.height + width: o.triggerWidth || o.height, }); - BI.createWidget({ + createWidget({ element: this, type: "bi.horizontal_fill", - items: [ - { - el: this.text, - width: "fill" - }, { - el: this.trigerButton, - width: "" - } - ] + items: [{ + el: this.text, + width: "fill", + }, { + el: this.trigerButton, + width: "", + }], }); - }, + } - setValue: function (value) { + setValue(value) { this.text.setValue(value); - }, + } - setText: function (text) { + setText(text) { this.text.setText(text); } -}); -BI.shortcut("bi.small_text_trigger", BI.SmallTextTrigger); +}