diff --git a/es6.js b/es6.js index 1a025d511..c14bb31f5 100644 --- a/es6.js +++ b/es6.js @@ -214,7 +214,8 @@ async function handleFile(srcName) { M += `${f}\n`; }); - Object.keys(G).forEach(moduleKey => { + Object.keys(G).forEach(key => { + let moduleKey = key; if (moduleKey === path.basename(srcName).replace(/.js$/g, "")) { return; } @@ -222,6 +223,11 @@ async function handleFile(srcName) { Object.keys(G[moduleKey]).forEach(key => { i += `${key}, `; }); + const single = !/\//.test(moduleKey); + if (single) { + moduleKey = `./${moduleKey}`; + } + I += `import {${i}} from '${moduleKey}'\n`; }); diff --git a/es6.xtype.js b/es6.xtype.js index dd9bec56c..28c934c80 100644 --- a/es6.xtype.js +++ b/es6.xtype.js @@ -106,22 +106,28 @@ function search(src, module) { while (dstPath[i] === srcPath[i] && i < dstPath.length && i < srcPath.length) { i++; } + + // i 代表同名的位置 + i--; + // 没有匹配完 if (i < srcPath.length) { let result = ""; - const rawI = i; - - // 回溯 - for (let j = 0; j < srcPath.length - rawI; j++) { + + // 回溯,向上找,回到目录 i + for (let j = srcPath.length - 1; j > i; j--) { result += "../"; - i--; } + + // 匹配过的下一个位置 i++; - // dstPath 也没有了 - if (i < dstPath.length) { - return result + findDstIndexPath(dstPath, i); - } else if (i === dstPath.length) { + + if (i >= dstPath.length) { + // 越界 return `${result}${dstName}`; + } else { + // 看看这个目录下有没有 index + return result + findDstIndexPath(dstPath, i); } } else if (i === srcPath.length) { if (i === dstPath.length) { diff --git a/src/case/combo/bubblecombo/combo.bubble.js b/src/case/combo/bubblecombo/combo.bubble.js index 7f2448ac0..f7e79c93d 100644 --- a/src/case/combo/bubblecombo/combo.bubble.js +++ b/src/case/combo/bubblecombo/combo.bubble.js @@ -1,12 +1,29 @@ -/** - * Created by GUY on 2017/2/8. - * - * @class BI.BubbleCombo - * @extends BI.Widget - */ -BI.BubbleCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.BubbleCombo.superclass._defaultConfig.apply(this, arguments), { +import { + shortcut, + Widget, + extend, + emptyFn, + createWidget, + isFunction +} from "@/core"; +import { Combo } from "@/base"; + +@shortcut() +export class BubbleCombo extends Widget { + static xtype = "bi.bubble_combo"; + + static EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; + static EVENT_CHANGE = "EVENT_CHANGE"; + static EVENT_EXPAND = "EVENT_EXPAND"; + static EVENT_COLLAPSE = "EVENT_COLLAPSE"; + static EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; + static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; + static EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; + static EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; + static EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; + + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { baseCls: "bi-bubble-combo", trigger: "click", toggle: true, @@ -22,17 +39,18 @@ BI.BubbleCombo = BI.inherit(BI.Widget, { adjustLength: 0, // 调整的距离 adjustXOffset: 0, adjustYOffset: 0, - hideChecker: BI.emptyFn, + hideChecker: emptyFn, offsetStyle: "left", // left,right,center el: {}, - popup: {} + popup: {}, }); - }, - _init: function () { - BI.BubbleCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.combo = BI.createWidget({ - type: "bi.combo", + } + + _init() { + super._init(...arguments); + const o = this.options; + this.combo = createWidget({ + type: Combo.xtype, element: this, trigger: o.trigger, toggle: o.toggle, @@ -55,72 +73,67 @@ BI.BubbleCombo = BI.inherit(BI.Widget, { comboClass: o.comboClass, supportCSSTransform: o.supportCSSTransform, el: o.el, - popup: () => BI.extend({ - type: "bi.bubble_popup_view", - animation: "bi-zoom-big", - animationDuring: 200, - primary: o.primary - }, BI.isFunction(this.options.popup) ? this.options.popup() : this.options.popup) + popup: () => + extend( + { + type: "bi.bubble_popup_view", + animation: "bi-zoom-big", + animationDuring: 200, + primary: o.primary, + }, + isFunction(this.options.popup) + ? this.options.popup() + : this.options.popup + ), }); - this.combo.on(BI.Combo.EVENT_TRIGGER_CHANGE, function () { - self.fireEvent(BI.BubbleCombo.EVENT_TRIGGER_CHANGE, arguments); + this.combo.on(Combo.EVENT_TRIGGER_CHANGE, (...args) => { + this.fireEvent(BubbleCombo.EVENT_TRIGGER_CHANGE, ...args); }); - this.combo.on(BI.Combo.EVENT_CHANGE, function () { - self.fireEvent(BI.BubbleCombo.EVENT_CHANGE, arguments); + this.combo.on(Combo.EVENT_CHANGE, (...args) => { + this.fireEvent(BubbleCombo.EVENT_CHANGE, ...args); }); - this.combo.on(BI.Combo.EVENT_EXPAND, function () { - self.fireEvent(BI.BubbleCombo.EVENT_EXPAND, arguments); + this.combo.on(Combo.EVENT_EXPAND, (...args) => { + this.fireEvent(BubbleCombo.EVENT_EXPAND, ...args); }); - this.combo.on(BI.Combo.EVENT_COLLAPSE, function () { - self.fireEvent(BI.BubbleCombo.EVENT_COLLAPSE, arguments); + this.combo.on(Combo.EVENT_COLLAPSE, (...args) => { + this.fireEvent(BubbleCombo.EVENT_COLLAPSE, ...args); }); - this.combo.on(BI.Combo.EVENT_AFTER_INIT, function () { - self.fireEvent(BI.BubbleCombo.EVENT_AFTER_INIT, arguments); + this.combo.on(Combo.EVENT_AFTER_INIT, (...args) => { + this.fireEvent(BubbleCombo.EVENT_AFTER_INIT, ...args); }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.BubbleCombo.EVENT_BEFORE_POPUPVIEW, arguments); + this.combo.on(Combo.EVENT_BEFORE_POPUPVIEW, (...args) => { + this.fireEvent(BubbleCombo.EVENT_BEFORE_POPUPVIEW, ...args); }); - this.combo.on(BI.Combo.EVENT_AFTER_POPUPVIEW, function () { - self.fireEvent(BI.BubbleCombo.EVENT_AFTER_POPUPVIEW, arguments); + this.combo.on(Combo.EVENT_AFTER_POPUPVIEW, (...args) => { + this.fireEvent(BubbleCombo.EVENT_AFTER_POPUPVIEW, ...args); }); - this.combo.on(BI.Combo.EVENT_BEFORE_HIDEVIEW, function () { - self.fireEvent(BI.BubbleCombo.EVENT_BEFORE_HIDEVIEW, arguments); + this.combo.on(Combo.EVENT_BEFORE_HIDEVIEW, (...args) => { + this.fireEvent(BubbleCombo.EVENT_BEFORE_HIDEVIEW, ...args); }); - this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () { - self.fireEvent(BI.BubbleCombo.EVENT_AFTER_HIDEVIEW, arguments); + this.combo.on(Combo.EVENT_AFTER_HIDEVIEW, (...args) => { + this.fireEvent(BubbleCombo.EVENT_AFTER_HIDEVIEW, ...args); }); - }, + } - hideView: function () { + hideView() { this.combo && this.combo.hideView(); - }, + } - showView: function () { + showView() { this.combo && this.combo.showView(); - }, + } - isViewVisible: function () { + isViewVisible() { return this.combo.isViewVisible(); - }, + } - adjustWidth: function () { + adjustWidth() { this.combo.adjustWidth(); - }, + } - adjustHeight: function () { + adjustHeight() { this.combo.adjustHeight(); } -}); - -BI.BubbleCombo.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; -BI.BubbleCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.BubbleCombo.EVENT_EXPAND = "EVENT_EXPAND"; -BI.BubbleCombo.EVENT_COLLAPSE = "EVENT_COLLAPSE"; -BI.BubbleCombo.EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; +} -BI.BubbleCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.BubbleCombo.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; -BI.BubbleCombo.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; -BI.BubbleCombo.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; -BI.shortcut("bi.bubble_combo", BI.BubbleCombo); diff --git a/src/case/combo/bubblecombo/popup.bubble.js b/src/case/combo/bubblecombo/popup.bubble.js index 6826a99f5..2b145941a 100644 --- a/src/case/combo/bubblecombo/popup.bubble.js +++ b/src/case/combo/bubblecombo/popup.bubble.js @@ -1,133 +1,37 @@ -/** - * Created by GUY on 2017/2/8. - * - * @class BI.BubblePopupView - * @extends BI.PopupView - */ -BI.BubblePopupView = BI.inherit(BI.PopupView, { - _defaultConfig: function () { - var config = BI.BubblePopupView.superclass._defaultConfig.apply(this, arguments); - return BI.extend(config, { - baseCls: config.baseCls + " bi-bubble-popup-view", - minWidth: 70, - maxWidth: 300, - // minHeight: 50, - showArrow: true, - }); - } -}); - -BI.shortcut("bi.bubble_popup_view", BI.BubblePopupView); - -/** - * Created by GUY on 2017/2/8. - * - * @class BI.BubblePopupBarView - * @extends BI.BubblePopupView - */ -BI.BubblePopupBarView = BI.inherit(BI.BubblePopupView, { - _defaultConfig: function () { - return BI.extend(BI.BubblePopupBarView.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-bubble-bar-popup-view", - buttons: [{ - value: false, - text: BI.i18nText("BI-Basic_Cancel"), - level: "ignore" - }, { - text: BI.i18nText(BI.i18nText("BI-Basic_OK")), - value: true - }], - innerVgap: 16, - innerHgap: 16, - }); - }, - - _createToolBar: function () { - var o = this.options, self = this; - - var items = []; - BI.each(o.buttons, function (i, buttonOpt) { - if (BI.isWidget(buttonOpt)) { - items.push({ - el: buttonOpt, - lgap: 12, - }); - } else { - items.push({ - el: BI.extend({ - type: "bi.button", - height: 24, - handler: function (v) { - self.fireEvent(BI.BubblePopupBarView.EVENT_CLICK_TOOLBAR_BUTTON, v); - } - }, buttonOpt), - lgap: 12, - }); - } - }); - return BI.createWidget({ - type: "bi.right_vertical_adapt", - innerVgap: o.innerVgap, - innerHgap: o.innerHgap, - items: items - }); - }, +import { shortcut, extend } from "@/core"; +import { PopupView, Label } from "@/base"; - _createContent: function () { - return this.options.el; - }, +@shortcut() +export class BubblePopupView extends PopupView { + static xtype = "bi.text_bubble_bar_popup_view"; - _createView: function () { - var o = this.options; + static EVENT_CLICK_TOOLBAR_BUTTON = "EVENT_CLICK_TOOLBAR_BUTTON"; + static EVENT_CHANGE = "EVENT_CLICK_TOOLBAR_BUTTON"; - var view = BI.createWidget({ - type: "bi.vertical", - items: [this._createContent()], - cls: "bar-popup-container", - hgap: o.innerHgap, - tgap: o.innerVgap, - }); - - view.element.css("min-height", o.minHeight); - - return view; - } -}); -BI.BubblePopupBarView.EVENT_CLICK_TOOLBAR_BUTTON = "EVENT_CLICK_TOOLBAR_BUTTON"; -BI.shortcut("bi.bubble_bar_popup_view", BI.BubblePopupBarView); - -/** - * Created by Windy on 2018/2/2. - * - * @class BI.TextBubblePopupBarView - * @extends BI.BubblePopupView - */ -BI.TextBubblePopupBarView = BI.inherit(BI.BubblePopupBarView, { - - _defaultConfig: function () { - var config = BI.TextBubblePopupBarView.superclass._defaultConfig.apply(this, arguments); - return BI.extend(config, { - baseCls: config.baseCls + " bi-text-bubble-bar-popup-view", + _defaultConfig() { + const config = super._defaultConfig(...arguments); + + return extend(config, { + baseCls: `${config.baseCls} bi-text-bubble-bar-popup-view`, text: "", }); - }, + } - _createContent: function () { - var self = this, o = this.options; + _createContent() { + const o = this.options; + return { - type: "bi.label", + type: Label.xtype, text: o.text, whiteSpace: "normal", textAlign: "left", - ref: function () { - self.text = this; - } + ref: _ref => { + this.text = _ref; + }, }; - }, + } - populate: function (v) { + populate(v) { this.text.setText(v || this.options.text); } -}); -BI.TextBubblePopupBarView.EVENT_CHANGE = "EVENT_CLICK_TOOLBAR_BUTTON"; -BI.shortcut("bi.text_bubble_bar_popup_view", BI.TextBubblePopupBarView); +} diff --git a/src/case/combo/editoriconcheckcombo/combo.editiconcheck.js b/src/case/combo/editoriconcheckcombo/combo.editiconcheck.js index 28c57a2e9..b3bb8e29f 100644 --- a/src/case/combo/editoriconcheckcombo/combo.editiconcheck.js +++ b/src/case/combo/editoriconcheckcombo/combo.editiconcheck.js @@ -1,26 +1,44 @@ -/** - * Created by Young's on 2016/4/28. - */ -BI.EditorIconCheckCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.EditorIconCheckCombo.superclass._defaultConfig.apply(this, arguments), { +import { + shortcut, + Widget, + extend, + emptyFn, + createWidget, + Controller +} from "@/core"; +import { ButtonGroup, Combo } from "@/base"; +import { EditorTrigger } from "../../trigger"; +import { TextValueCheckComboPopup } from "../textvaluecheckcombo/popup.textvaluecheck"; + +@shortcut() +export class EditorIconCheckCombo extends Widget { + static xtype = "bi.editor_icon_check_combo"; + + 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() { + return extend(super._defaultConfig(...arguments), { baseClass: "bi-check-editor-combo", width: 100, height: 24, - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, - validationChecker: BI.emptyFn, - quitChecker: BI.emptyFn, + chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, + validationChecker: emptyFn, + quitChecker: emptyFn, allowBlank: true, watermark: "", - errorText: "" + errorText: "", }); - }, + } - _init: function () { - BI.EditorIconCheckCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.trigger = BI.createWidget({ - type: "bi.editor_trigger", + _init() { + super._init(...arguments); + const o = this.options; + this.trigger = createWidget({ + type: EditorTrigger.xtype, items: o.items, height: o.height, validationChecker: o.validationChecker, @@ -28,41 +46,41 @@ BI.EditorIconCheckCombo = BI.inherit(BI.Widget, { allowBlank: o.allowBlank, watermark: o.watermark, errorText: o.errorText, - value: o.value + value: o.value, }); - this.trigger.on(BI.EditorTrigger.EVENT_CHANGE, function () { - self.popup.setValue(this.getValue()); - self.fireEvent(BI.EditorIconCheckCombo.EVENT_CHANGE, arguments); + this.trigger.on(EditorTrigger.EVENT_CHANGE, (...args) => { + this.popup.setValue(this.getValue()); + this.fireEvent(EditorIconCheckCombo.EVENT_CHANGE, ...args); }); - this.trigger.on(BI.EditorTrigger.EVENT_FOCUS, function () { - self.fireEvent(BI.EditorIconCheckCombo.EVENT_FOCUS, arguments); + this.trigger.on(EditorTrigger.EVENT_FOCUS, (...args) => { + this.fireEvent(EditorIconCheckCombo.EVENT_FOCUS, ...args); }); - this.trigger.on(BI.EditorTrigger.EVENT_EMPTY, function () { - self.fireEvent(BI.EditorIconCheckCombo.EVENT_EMPTY, arguments); + this.trigger.on(EditorTrigger.EVENT_EMPTY, (...args) => { + this.fireEvent(EditorIconCheckCombo.EVENT_EMPTY, ...args); }); - this.trigger.on(BI.EditorTrigger.EVENT_VALID, function () { - self.fireEvent(BI.EditorIconCheckCombo.EVENT_VALID, arguments); + this.trigger.on(EditorTrigger.EVENT_VALID, (...args) => { + this.fireEvent(EditorIconCheckCombo.EVENT_VALID, ...args); }); - this.trigger.on(BI.EditorTrigger.EVENT_ERROR, function () { - self.fireEvent(BI.EditorIconCheckCombo.EVENT_ERROR, arguments); + this.trigger.on(EditorTrigger.EVENT_ERROR, (...args) => { + this.fireEvent(EditorIconCheckCombo.EVENT_ERROR, ...args); }); - this.popup = BI.createWidget({ + this.popup = createWidget({ type: "bi.text_value_check_combo_popup", chooseType: o.chooseType, items: o.items, - value: o.value + value: o.value, }); - this.popup.on(BI.TextValueCheckComboPopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.editorIconCheckCombo.hideView(); - self.fireEvent(BI.EditorIconCheckCombo.EVENT_CHANGE); + this.popup.on(TextValueCheckComboPopup.EVENT_CHANGE, () => { + this.setValue(this.popup.getValue()); + this.editorIconCheckCombo.hideView(); + this.fireEvent(EditorIconCheckCombo.EVENT_CHANGE); }); - this.popup.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.popup.on(Controller.EVENT_CHANGE, (...args) => { + this.fireEvent(Controller.EVENT_CHANGE, ...args); }); - this.editorIconCheckCombo = BI.createWidget({ - type: "bi.combo", + this.editorIconCheckCombo = createWidget({ + type: Combo.xtype, container: o.container, direction: o.direction, element: this, @@ -70,27 +88,21 @@ BI.EditorIconCheckCombo = BI.inherit(BI.Widget, { el: this.trigger, popup: { el: this.popup, - maxHeight: 300 - } + maxHeight: 300, + }, }); - }, + } - setValue: function (v) { + setValue(v) { this.editorIconCheckCombo.setValue(v); - }, + } - getValue: function () { + getValue() { return this.trigger.getValue(); - }, + } - populate: function (items) { + populate(items) { this.options.items = items; this.editorIconCheckCombo.populate(items); } -}); -BI.EditorIconCheckCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.EditorIconCheckCombo.EVENT_FOCUS = "EVENT_FOCUS"; -BI.EditorIconCheckCombo.EVENT_EMPTY = "EVENT_EMPTY"; -BI.EditorIconCheckCombo.EVENT_VALID = "EVENT_VALID"; -BI.EditorIconCheckCombo.EVENT_ERROR = "EVENT_ERROR"; -BI.shortcut("bi.editor_icon_check_combo", BI.EditorIconCheckCombo); +} \ No newline at end of file diff --git a/src/case/combo/iconcombo/combo.icon.js b/src/case/combo/iconcombo/combo.icon.js index 6c0f45c51..338e10183 100644 --- a/src/case/combo/iconcombo/combo.icon.js +++ b/src/case/combo/iconcombo/combo.icon.js @@ -1,12 +1,24 @@ -/** - * Created by GUY on 2016/2/2. - * - * @class BI.IconCombo - * @extend BI.Widget - */ -BI.IconCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.IconCombo.superclass._defaultConfig.apply(this, arguments), { +import { + shortcut, + Widget, + extend, + isFunction, + createWidget, + Controller, + isNull, + isArray +} from "@/core"; +import { ButtonGroup, Combo } from "@/base"; +import { IconComboPopup } from "./popup.iconcombo"; + +@shortcut() +export class IconCombo extends Widget { + static xtype = "bi.icon_combo"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { baseCls: "bi-icon-combo", width: 24, height: 24, @@ -20,22 +32,26 @@ BI.IconCombo = BI.inherit(BI.Widget, { adjustXOffset: 0, adjustYOffset: 0, offsetStyle: "left", - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, + chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, isShowDown: true, - hideWhenAnotherComboOpen: false + hideWhenAnotherComboOpen: false, }); - }, + } - _init: function () { - var self = this, o = this.options; - o.value = BI.isFunction(o.value) ? this.__watch(o.value, function (context, newValue) { - self.setValue(newValue); - }) : o.value; - o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { - self.populate(newValue); - }) : o.items; - BI.IconCombo.superclass._init.apply(this, arguments); - this.trigger = BI.createWidget(o.el, { + _init() { + const o = this.options; + o.value = isFunction(o.value) + ? this.__watch(o.value, (context, newValue) => { + this.setValue(newValue); + }) + : o.value; + o.items = isFunction(o.items) + ? this.__watch(o.items, (context, newValue) => { + this.populate(newValue); + }) + : o.items; + super._init(...arguments); + this.trigger = createWidget(o.el, { type: "bi.icon_combo_trigger", iconCls: o.iconCls, title: o.title, @@ -45,24 +61,24 @@ BI.IconCombo = BI.inherit(BI.Widget, { iconWidth: o.iconWidth, iconHeight: o.iconHeight, value: o.value, - isShowDown: o.isShowDown + isShowDown: o.isShowDown, }); - this.popup = BI.createWidget(o.popup, { - type: "bi.icon_combo_popup", + this.popup = createWidget(o.popup, { + type: IconComboPopup.xtype, chooseType: o.chooseType, items: o.items, - value: o.value + value: o.value, }); - this.popup.on(BI.IconComboPopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.iconCombo.hideView(); - self.fireEvent(BI.IconCombo.EVENT_CHANGE); + this.popup.on(IconComboPopup.EVENT_CHANGE, () => { + this.setValue(this.popup.getValue()); + this.iconCombo.hideView(); + this.fireEvent(IconCombo.EVENT_CHANGE); }); - this.popup.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.popup.on(Controller.EVENT_CHANGE, (...args) => { + this.fireEvent(Controller.EVENT_CHANGE, ...args); }); - this.iconCombo = BI.createWidget({ - type: "bi.combo", + this.iconCombo = createWidget({ + type: Combo.xtype, element: this, direction: o.direction, trigger: o.trigger, @@ -77,33 +93,32 @@ BI.IconCombo = BI.inherit(BI.Widget, { el: this.popup, maxWidth: o.maxWidth, maxHeight: o.maxHeight, - minWidth: o.minWidth - } + minWidth: o.minWidth, + }, }); - }, + } - showView: function () { + showView() { this.iconCombo.showView(); - }, + } - hideView: function () { + hideView() { this.iconCombo.hideView(); - }, + } - setValue: function (v) { + setValue(v) { this.trigger.setValue(v); this.popup.setValue(v); - }, + } - getValue: function () { - var value = this.popup.getValue(); - return BI.isNull(value) ? [] : (BI.isArray(value) ? value : [value]); - }, + getValue() { + const value = this.popup.getValue(); + + return isNull(value) ? [] : isArray(value) ? value : [value]; + } - populate: function (items) { + populate(items) { this.options.items = items; this.iconCombo.populate(items); } -}); -BI.IconCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.icon_combo", BI.IconCombo); \ No newline at end of file +} diff --git a/src/case/combo/iconcombo/popup.iconcombo.js b/src/case/combo/iconcombo/popup.iconcombo.js index 9b0f4cc80..a503dd427 100644 --- a/src/case/combo/iconcombo/popup.iconcombo.js +++ b/src/case/combo/iconcombo/popup.iconcombo.js @@ -1,63 +1,74 @@ -/** - * Created by GUY on 2016/2/2. - * - * @class BI.IconComboPopup - * @extend BI.Pane - */ -BI.IconComboPopup = BI.inherit(BI.Pane, { - _defaultConfig: function () { - return BI.extend(BI.IconComboPopup.superclass._defaultConfig.apply(this, arguments), { +import { + shortcut, + extend, + createWidget, + createItems, + Controller, + Events, + VerticalLayout +} from "@/core"; +import { Pane, ButtonGroup } from "@/base"; +import { SingleSelectIconTextItem } from "../../button"; + +@shortcut() +export class IconComboPopup extends Pane { + static xtype = "bi.icon_combo_popup"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { baseCls: "bi.icon-combo-popup", - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE + chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, }); - }, - - _init: function () { - BI.IconComboPopup.superclass._init.apply(this, arguments); - var o = this.options, self = this; - this.popup = BI.createWidget({ - type: "bi.button_group", - items: BI.createItems(o.items, { - type: "bi.single_select_icon_text_item", + } + + _init() { + super._init(...arguments); + const o = this.options; + this.popup = createWidget({ + type: ButtonGroup.xtype, + items: createItems(o.items, { + type: SingleSelectIconTextItem.xtype, }), chooseType: o.chooseType, - layouts: [{ - type: "bi.vertical" - }], - value: o.value + layouts: [ + { + type: VerticalLayout.xtype, + } + ], + value: o.value, }); - this.popup.on(BI.Controller.EVENT_CHANGE, function (type, val, obj) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - if (type === BI.Events.CLICK) { - self.fireEvent(BI.IconComboPopup.EVENT_CHANGE, val, obj); + this.popup.on(Controller.EVENT_CHANGE, (...args) => { + const [type, val, obj] = args; + this.fireEvent(Controller.EVENT_CHANGE, ...args); + if (type === Events.CLICK) { + this.fireEvent(IconComboPopup.EVENT_CHANGE, val, obj); } }); - BI.createWidget({ - type: "bi.vertical", + createWidget({ + type: VerticalLayout.xtype, element: this, vgap: 5, - items: [this.popup] + items: [this.popup], }); - }, + } - populate: function (items) { - BI.IconComboPopup.superclass.populate.apply(this, arguments); - items = BI.createItems(items, { - type: "bi.single_select_icon_text_item", + populate(items) { + super.populate(...arguments); + items = createItems(items, { + type: SingleSelectIconTextItem.xtype, }); this.popup.populate(items); - }, + } - getValue: function () { + getValue() { return this.popup.getValue(); - }, + } - setValue: function (v) { + setValue(v) { this.popup.setValue(v); } - -}); -BI.IconComboPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.icon_combo_popup", BI.IconComboPopup); \ No newline at end of file +} diff --git a/src/case/combo/iconcombo/trigger.iconcombo.js b/src/case/combo/iconcombo/trigger.iconcombo.js index 65c353504..67293f2fc 100644 --- a/src/case/combo/iconcombo/trigger.iconcombo.js +++ b/src/case/combo/iconcombo/trigger.iconcombo.js @@ -1,12 +1,24 @@ -/** - * Created by GUY on 2016/2/2. - * - * @class BI.IconComboTrigger - * @extend BI.Widget - */ -BI.IconComboTrigger = BI.inherit(BI.Trigger, { - _defaultConfig: function () { - return BI.extend(BI.IconComboTrigger.superclass._defaultConfig.apply(this, arguments), { +import { + shortcut, + extend, + isKey, + createWidget, + isNotEmptyString, + AbsoluteLayout, + isArray, + any +} from "@/core"; +import { Trigger, IconButton } from "@/base"; +import { IconChangeButton } from "../../button"; + +@shortcut() +export class IconComboTrigger extends Trigger { + static xtype = "bi.icon_combo_trigger"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { extraCls: "bi-icon-combo-trigger", el: {}, items: [], @@ -14,80 +26,85 @@ BI.IconComboTrigger = BI.inherit(BI.Trigger, { width: 24, height: 24, isShowDown: true, - value: "" + value: "", }); - }, + } - _init: function () { - BI.IconComboTrigger.superclass._init.apply(this, arguments); - var o = this.options, self = this; - var iconCls = ""; - if(BI.isKey(o.value)){ + _init() { + super._init(...arguments); + const o = this.options; + let iconCls = ""; + if (isKey(o.value)) { iconCls = this._digest(o.value, o.items); } - this.button = BI.createWidget(o.el, { - type: "bi.icon_change_button", + this.button = createWidget(o.el, { + type: IconChangeButton.xtype, cls: "icon-combo-trigger-icon", - iconCls: iconCls, + iconCls, disableSelected: true, width: o.isShowDown ? o.width - 12 : o.width, height: o.height, iconWidth: o.iconWidth, iconHeight: o.iconHeight, - selected: BI.isNotEmptyString(iconCls) + selected: isNotEmptyString(iconCls), }); - this.down = BI.createWidget({ - type: "bi.icon_button", + this.down = createWidget({ + type: IconButton.xtype, disableSelected: true, cls: "icon-combo-down-icon trigger-triangle-font font-size-12", width: 12, height: 8, - selected: BI.isNotEmptyString(iconCls), - invisible: !o.isShowDown + selected: isNotEmptyString(iconCls), + invisible: !o.isShowDown, }); - BI.createWidget({ - type: "bi.absolute", + createWidget({ + type: AbsoluteLayout.xtype, element: this, - items: [{ - el: this.button, - left: 0, - right: 0, - top: 0, - bottom: 0 - }, { - el: this.down, - right: 3, - bottom: 0 - }] + items: [ + { + el: this.button, + left: 0, + right: 0, + top: 0, + bottom: 0, + }, + { + el: this.down, + right: 3, + bottom: 0, + } + ], }); - }, + } - _digest: function (v, items) { - var iconCls = ""; - v = BI.isArray(v) ? v[0] : v; - BI.any(items, function (i, item) { + _digest(v, items) { + let iconCls = ""; + v = isArray(v) ? v[0] : v; + any(items, (i, item) => { if (v === item.value) { iconCls = item.iconCls; + return true; } }); + return iconCls; - }, + } - populate: function (items) { - var o = this.options; + populate(items) { + const o = this.options; this.options.items = items || []; this.button.setIcon(o.iconCls); this.button.setSelected(false); this.down.setSelected(false); - }, + } - setValue: function (v) { - BI.IconComboTrigger.superclass.setValue.apply(this, arguments); - var o = this.options; - var iconCls = this._digest(v, this.options.items); - v = BI.isArray(v) ? v[0] : v; - if (BI.isNotEmptyString(iconCls)) { + setValue(v) { + super.setValue(...arguments); + const o = this.options; + const iconCls = this._digest(v, this.options.items); + v = isArray(v) ? v[0] : v; + if (isNotEmptyString(iconCls)) { this.button.setIcon(iconCls); this.button.setSelected(true); this.down.setSelected(true); @@ -97,6 +114,4 @@ BI.IconComboTrigger = BI.inherit(BI.Trigger, { this.down.setSelected(false); } } -}); -BI.IconComboTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.icon_combo_trigger", BI.IconComboTrigger); +} diff --git a/src/case/combo/icontextvaluecombo/combo.icontextvalue.js b/src/case/combo/icontextvaluecombo/combo.icontextvalue.js index 9a920240a..85004eb22 100644 --- a/src/case/combo/icontextvaluecombo/combo.icontextvalue.js +++ b/src/case/combo/icontextvaluecombo/combo.icontextvalue.js @@ -1,32 +1,61 @@ -/** - * Created by Windy on 2017/12/12. - * combo : icon + text + icon, popup : icon + text - */ -BI.IconTextValueCombo = BI.inherit(BI.Widget, { - _defaultConfig: function (config) { - return BI.extend(BI.IconTextValueCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-icon-text-value-combo " + (config.simple ? "bi-border-bottom" : "bi-border bi-border-radius"), +import { + shortcut, + Widget, + extend, + isFunction, + createWidget, + toPix, + Controller, + isKey, + isNull, + isEmptyArray, + isEmptyString, + isArray, + find, + contains +} from "@/core"; +import { IconTextValueComboPopup } from "./popup.icontextvalue"; +import { SelectIconTextTrigger } from "../../trigger"; +import { Combo } from "@/base"; + +@shortcut() +export class IconTextValueCombo extends Widget { + static xtype = "bi.icon_text_value_combo"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig(config) { + return extend(super._defaultConfig(...arguments), { + baseCls: + `bi-icon-text-value-combo ${ + config.simple + ? "bi-border-bottom" + : "bi-border bi-border-radius"}`, height: 24, iconHeight: null, iconWidth: null, value: "", }); - }, + } - _init: function () { - var self = this, o = this.options; - o.value = BI.isFunction(o.value) ? this.__watch(o.value, function (context, newValue) { - self.setValue(newValue); - }) : o.value; - o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { - self.populate(newValue); - }) : o.items; - BI.IconTextValueCombo.superclass._init.apply(this, arguments); - this.trigger = BI.createWidget({ - type: "bi.select_icon_text_trigger", + _init() { + const o = this.options; + o.value = isFunction(o.value) + ? this.__watch(o.value, (context, newValue) => { + this.setValue(newValue); + }) + : o.value; + o.items = isFunction(o.items) + ? this.__watch(o.items, (context, newValue) => { + this.populate(newValue); + }) + : o.items; + super._init(...arguments); + this.trigger = createWidget({ + type: SelectIconTextTrigger.xtype, cls: "icon-text-value-trigger", items: o.items, - height: BI.toPix(o.height, 2), + height: toPix(o.height, 2), text: o.text, iconCls: o.iconCls, value: o.value, @@ -34,28 +63,28 @@ BI.IconTextValueCombo = BI.inherit(BI.Widget, { iconWidth: o.iconWidth, iconWrapperWidth: o.iconWrapperWidth, title: o.title, - warningTitle: o.warningTitle + warningTitle: o.warningTitle, }); - this.popup = BI.createWidget({ + this.popup = createWidget({ type: "bi.icon_text_value_combo_popup", items: o.items, value: o.value, iconHeight: o.iconHeight, iconWidth: o.iconWidth, - iconWrapperWidth: o.iconWrapperWidth + iconWrapperWidth: o.iconWrapperWidth, }); - this.popup.on(BI.IconTextValueComboPopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.textIconCombo.hideView(); - self.fireEvent(BI.IconTextValueCombo.EVENT_CHANGE, arguments); + this.popup.on(IconTextValueComboPopup.EVENT_CHANGE, (...args) => { + this.setValue(this.popup.getValue()); + this.textIconCombo.hideView(); + this.fireEvent(IconTextValueCombo.EVENT_CHANGE, ...args); }); - this.popup.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.popup.on(Controller.EVENT_CHANGE, (...args) => { + this.fireEvent(Controller.EVENT_CHANGE, ...args); }); - this.textIconCombo = BI.createWidget({ - type: "bi.combo", - height: BI.toPix(o.height, 2), - width: BI.toPix(o.width, 2), + this.textIconCombo = createWidget({ + type: Combo.xtype, + height: toPix(o.height, 2), + width: toPix(o.width, 2), element: this, container: o.container, direction: o.direction, @@ -64,24 +93,22 @@ BI.IconTextValueCombo = BI.inherit(BI.Widget, { popup: { el: this.popup, maxHeight: 240, - minHeight: 25 - } + minHeight: 25, + }, }); - if (BI.isKey(o.value)) { + if (isKey(o.value)) { this.setValue(o.value); } - }, + } - _checkError: function (v) { - if(BI.isNull(v) || BI.isEmptyArray(v) || BI.isEmptyString(v)) { + _checkError(v) { + if (isNull(v) || isEmptyArray(v) || isEmptyString(v)) { this.trigger.options.tipType = "success"; this.element.removeClass("combo-error"); } else { - v = BI.isArray(v) ? v : [v]; - var result = BI.find(this.options.items, function (idx, item) { - return BI.contains(v, item.value); - }); - if (BI.isNull(result)) { + v = isArray(v) ? v : [v]; + const result = find(this.options.items, (idx, item) => contains(v, item.value)); + if (isNull(result)) { this.trigger.options.tipType = "warning"; this.element.removeClass("combo-error").addClass("combo-error"); } else { @@ -89,23 +116,22 @@ BI.IconTextValueCombo = BI.inherit(BI.Widget, { this.element.removeClass("combo-error"); } } - }, + } - setValue: function (v) { + setValue(v) { this.trigger.setValue(v); this.popup.setValue(v); this._checkError(v); - }, + } - getValue: function () { - var value = this.popup.getValue(); - return BI.isNull(value) ? [] : (BI.isArray(value) ? value : [value]); - }, + getValue() { + const value = this.popup.getValue(); + + return isNull(value) ? [] : isArray(value) ? value : [value]; + } - populate: function (items) { + populate(items) { this.options.items = items; this.textIconCombo.populate(items); } -}); -BI.IconTextValueCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.icon_text_value_combo", BI.IconTextValueCombo); +} diff --git a/src/case/combo/icontextvaluecombo/popup.icontextvalue.js b/src/case/combo/icontextvaluecombo/popup.icontextvalue.js index 88db08e67..02edd74f3 100644 --- a/src/case/combo/icontextvaluecombo/popup.icontextvalue.js +++ b/src/case/combo/icontextvaluecombo/popup.icontextvalue.js @@ -1,74 +1,88 @@ -/** - * Created by Windy on 2017/12/12. - */ -BI.IconTextValueComboPopup = BI.inherit(BI.Pane, { - _defaultConfig: function () { - return BI.extend(BI.IconTextValueComboPopup.superclass._defaultConfig.apply(this, arguments), { +import { + shortcut, + extend, + createWidget, + createItems, + Controller, + Events, + VerticalLayout +} from "@/core"; +import { Pane, ButtonGroup } from "@/base"; +import { SingleSelectIconTextItem } from "../../button"; + +@shortcut() +export class IconTextValueComboPopup extends Pane { + static xtype = "bi.icon_text_value_combo_popup"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { baseCls: "bi-icon-text-icon-popup", behaviors: { - redmark: function () { + redmark () { return true; - } - } + }, + }, }); - }, + } - _init: function () { - BI.IconTextValueComboPopup.superclass._init.apply(this, arguments); - var o = this.options, self = this; - this.popup = BI.createWidget({ - type: "bi.button_group", - items: BI.createItems(o.items, { - type: "bi.single_select_icon_text_item", + _init() { + super._init(...arguments); + const o = this.options; + this.popup = createWidget({ + type: ButtonGroup.xtype, + items: createItems(o.items, { + type: SingleSelectIconTextItem.xtype, iconHeight: o.iconHeight, iconWidth: o.iconWidth, - iconWrapperWidth: o.iconWrapperWidth + iconWrapperWidth: o.iconWrapperWidth, }), - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, - layouts: [{ - type: "bi.vertical" - }], + chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, + layouts: [ + { + type: VerticalLayout.xtype, + } + ], behaviors: o.behaviors, - value: o.value + value: o.value, }); - this.popup.on(BI.Controller.EVENT_CHANGE, function (type, val, obj) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - if (type === BI.Events.CLICK) { - self.fireEvent(BI.IconTextValueComboPopup.EVENT_CHANGE, val, obj); + this.popup.on(Controller.EVENT_CHANGE, (...args) => { + const [type, val, obj] = args; + this.fireEvent(Controller.EVENT_CHANGE, ...args); + if (type === Events.CLICK) { + this.fireEvent(IconTextValueComboPopup.EVENT_CHANGE, val, obj); } }); this.check(); - BI.createWidget({ - type: "bi.vertical", + createWidget({ + type: VerticalLayout.xtype, element: this, vgap: 5, - items: [this.popup] + items: [this.popup], }); - }, + } - populate: function (items, keyword) { - BI.IconTextValueComboPopup.superclass.populate.apply(this, arguments); - var o = this.options; - items = BI.createItems(items, { - type: "bi.single_select_icon_text_item", + populate(items, keyword) { + super.populate(...arguments); + const o = this.options; + items = createItems(items, { + type: SingleSelectIconTextItem.xtype, iconWrapperWidth: o.iconWrapperWidth, iconHeight: o.iconHeight, iconWidth: o.iconWidth, }); this.popup.populate(items, keyword); - }, + } - getValue: function () { + getValue() { return this.popup.getValue(); - }, + } - setValue: function (v) { + setValue(v) { this.popup.setValue(v); } - -}); -BI.IconTextValueComboPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.icon_text_value_combo_popup", BI.IconTextValueComboPopup); +} diff --git a/src/case/combo/index.js b/src/case/combo/index.js new file mode 100644 index 000000000..12b79a169 --- /dev/null +++ b/src/case/combo/index.js @@ -0,0 +1,22 @@ +export { BubbleCombo } from "./bubblecombo/combo.bubble"; +export { BubblePopupView } from "./bubblecombo/popup.bubble"; + +export { EditorIconCheckCombo } from "./editoriconcheckcombo/combo.editiconcheck"; + +export { IconCombo } from "./iconcombo/combo.icon"; +export { IconComboPopup } from "./iconcombo/popup.iconcombo"; +export { IconComboTrigger } from "./iconcombo/trigger.iconcombo"; + +export { IconTextValueCombo } from "./icontextvaluecombo/combo.icontextvalue"; +export { IconTextValueComboPopup } from "./icontextvaluecombo/popup.icontextvalue"; + +export { SearchTextValueCombo } from "./searchtextvaluecombo/combo.searchtextvalue"; +export { SearchTextValueComboPopup } from "./searchtextvaluecombo/popup.searchtextvalue"; +export { SearchTextValueTrigger } from "./searchtextvaluecombo/trigger.searchtextvalue"; + +export { TextValueCheckCombo } from "./textvaluecheckcombo/combo.textvaluecheck"; +export { TextValueCheckComboPopup } from "./textvaluecheckcombo/popup.textvaluecheck"; + +export { TextValueCombo } from "./textvaluecombo/combo.textvalue"; +export { SmallTextValueCombo } from "./textvaluecombo/combo.textvaluesmall"; +export { TextValueComboPopup } from "./textvaluecombo/popup.textvalue"; diff --git a/src/case/combo/searchtextvaluecombo/combo.searchtextvalue.js b/src/case/combo/searchtextvaluecombo/combo.searchtextvalue.js index baa653207..a5c586773 100644 --- a/src/case/combo/searchtextvaluecombo/combo.searchtextvalue.js +++ b/src/case/combo/searchtextvaluecombo/combo.searchtextvalue.js @@ -1,9 +1,25 @@ -/** - * Created by Windy on 2018/2/2. - */ -BI.SearchTextValueCombo = BI.inherit(BI.Widget, { +import { + shortcut, + Widget, + isFunction, + toPix, + isKey, + isNull, + isEmptyArray, + isEmptyString, + isArray, + find, + contains +} from "@/core"; +import { SearchTextValueTrigger } from "./trigger.searchtextvalue"; +import { ButtonGroup, Combo } from "@/base"; +import { TextValueComboPopup } from "../textvaluecombo/popup.textvalue"; - props: { +@shortcut() +export class SearchTextValueCombo extends Widget { + static xtype = "bi.search_text_value_combo"; + + props = { baseCls: "bi-search-text-value-combo", height: 24, text: "", @@ -12,36 +28,46 @@ BI.SearchTextValueCombo = BI.inherit(BI.Widget, { tipType: "", warningTitle: "", allowClear: false, - }, + }; + + static EVENT_CHANGE = "EVENT_CHANGE"; + static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; + static EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; - render: function () { - var self = this, o = this.options; - o.value = BI.isFunction(o.value) ? this.__watch(o.value, function (context, newValue) { - self.setValue(newValue); - }) : o.value; - o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { - self.populate(newValue); - }) : o.items; + render() { + const o = this.options; + o.value = isFunction(o.value) + ? this.__watch(o.value, (context, newValue) => { + this.setValue(newValue); + }) + : o.value; + o.items = isFunction(o.items) + ? this.__watch(o.items, (context, newValue) => { + this.populate(newValue); + }) + : o.items; return { - type: "bi.combo", - cls: (o.simple ? "bi-border-bottom" : "bi-border bi-border-radius") + " bi-focus-shadow", + type: Combo.xtype, + cls: + `${o.simple ? "bi-border-bottom" : "bi-border bi-border-radius" + } bi-focus-shadow`, container: o.container, adjustLength: 2, - height: BI.toPix(o.height, o.simple ? 1 : 2), - width: BI.toPix(o.width, 2), - ref: function () { - self.combo = this; + height: toPix(o.height, o.simple ? 1 : 2), + width: toPix(o.width, 2), + ref: _ref => { + this.combo = _ref; }, el: { type: "bi.search_text_value_trigger", cls: "search-text-value-trigger", watermark: o.watermark, - ref: function () { - self.trigger = this; + ref: _ref => { + this.trigger = _ref; }, items: o.items, - height: BI.toPix(o.height, o.simple ? 1 : 2), + height: toPix(o.height, o.simple ? 1 : 2), text: o.text, defaultText: o.defaultText, value: o.value, @@ -49,80 +75,92 @@ BI.SearchTextValueCombo = BI.inherit(BI.Widget, { warningTitle: o.warningTitle, title: o.title, allowClear: o.allowClear, - listeners: [{ - eventName: BI.SearchTextValueTrigger.EVENT_CHANGE, - action: function () { - self.setValue(this.getValue()[0]); - self.combo.hideView(); - self.fireEvent(BI.SearchTextValueCombo.EVENT_CHANGE); - } - }, { - eventName: BI.SearchTextValueTrigger.EVENT_CLEAR, - action: function () { - self._clear(); - self.fireEvent(BI.SearchTextValueCombo.EVENT_CHANGE); + listeners: [ + { + eventName: SearchTextValueTrigger.EVENT_CHANGE, + action: () => { + this.setValue(this.getValue()[0]); + this.combo.hideView(); + this.fireEvent(SearchTextValueCombo.EVENT_CHANGE); + }, + }, + { + eventName: SearchTextValueTrigger.EVENT_CLEAR, + action: () => { + this._clear(); + this.fireEvent(SearchTextValueCombo.EVENT_CHANGE); + }, } - }] + ], }, popup: { el: { type: "bi.text_value_combo_popup", - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, + chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, value: o.value, items: o.items, - ref: function () { - self.popup = this; - self.trigger.getSearcher().setAdapter(self.popup); + ref: _ref => { + this.popup = _ref; + this.trigger.getSearcher().setAdapter(this.popup); }, - listeners: [{ - eventName: BI.TextValueComboPopup.EVENT_CHANGE, - action: function () { - self.setValue(this.getValue()[0]); - self.combo.hideView(); - self.fireEvent(BI.SearchTextValueCombo.EVENT_CHANGE); + listeners: [ + { + eventName: TextValueComboPopup.EVENT_CHANGE, + action: () => { + this.setValue(this.getValue()[0]); + this.combo.hideView(); + this.fireEvent( + SearchTextValueCombo.EVENT_CHANGE + ); + }, } - }] + ], }, value: o.value, maxHeight: 252, - minHeight: 25 + minHeight: 25, }, - listeners: [{ - eventName: BI.Combo.EVENT_AFTER_HIDEVIEW, - action: function () { - self.trigger.stopEditing(); - self.fireEvent(BI.SearchTextValueCombo.EVENT_AFTER_HIDEVIEW); - } - }, { - eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, - action: function () { - self.fireEvent(BI.SearchTextValueCombo.EVENT_BEFORE_POPUPVIEW); + listeners: [ + { + eventName: Combo.EVENT_AFTER_HIDEVIEW, + action: () => { + this.trigger.stopEditing(); + this.fireEvent( + SearchTextValueCombo.EVENT_AFTER_HIDEVIEW + ); + }, + }, + { + eventName: Combo.EVENT_BEFORE_POPUPVIEW, + action: () => { + this.fireEvent( + SearchTextValueCombo.EVENT_BEFORE_POPUPVIEW + ); + }, } - }], + ], }; - }, + } - created: function () { - var o = this.options; - if (BI.isKey(o.value)) { + created() { + const o = this.options; + if (isKey(o.value)) { this._checkError(o.value); } - }, + } - _clear: function () { + _clear() { this.setValue(); - }, + } - _checkError: function (v) { - if (BI.isNull(v) || BI.isEmptyArray(v) || BI.isEmptyString(v)) { + _checkError(v) { + if (isNull(v) || isEmptyArray(v) || isEmptyString(v)) { this.trigger.options.tipType = "success"; this.element.removeClass("combo-error"); } else { - v = BI.isArray(v) ? v : [v]; - var result = BI.find(this.options.items, function (idx, item) { - return BI.contains(v, item.value); - }); - if (BI.isNull(result)) { + v = isArray(v) ? v : [v]; + const result = find(this.options.items, (idx, item) => contains(v, item.value)); + if (isNull(result)) { this.element.removeClass("combo-error").addClass("combo-error"); this.trigger.attr("tipType", "warning"); } else { @@ -130,24 +168,21 @@ BI.SearchTextValueCombo = BI.inherit(BI.Widget, { this.trigger.attr("tipType", "success"); } } - }, + } - populate: function (items) { + populate(items) { this.options.items = items; this.combo.populate(items); - }, + } - setValue: function (v) { + setValue(v) { this.combo.setValue(v); this._checkError(v); - }, + } - getValue: function () { - var value = this.combo.getValue(); - return BI.isNull(value) ? [] : (BI.isArray(value) ? value : [value]); + getValue() { + const value = this.combo.getValue(); + + return isNull(value) ? [] : isArray(value) ? value : [value]; } -}); -BI.SearchTextValueCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SearchTextValueCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.SearchTextValueCombo.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW" -BI.shortcut("bi.search_text_value_combo", BI.SearchTextValueCombo); +} diff --git a/src/case/combo/searchtextvaluecombo/popup.searchtextvalue.js b/src/case/combo/searchtextvaluecombo/popup.searchtextvalue.js index dc1107fb1..36975c1d7 100644 --- a/src/case/combo/searchtextvaluecombo/popup.searchtextvalue.js +++ b/src/case/combo/searchtextvaluecombo/popup.searchtextvalue.js @@ -1,76 +1,100 @@ -/** - * Created by Windy on 2018/2/5. - */ -BI.SearchTextValueComboPopup = BI.inherit(BI.Pane, { +import { + shortcut, + Controller, + Events, + VerticalLayout, + map, + extend, + concat +} from "@/core"; +import { ButtonGroup, Pane } from "@/base"; +import { SingleSelectItem } from "../../button"; - props: { - baseCls: "bi-search-text-value-popup" - }, +@shortcut() +export class SearchTextValueComboPopup extends Pane { + static xtype = "bi.search_text_value_combo_popup"; - render: function () { - var self = this, o = this.options; + props = { baseCls: "bi-search-text-value-popup" }; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + render() { + const o = this.options; + return { - type: "bi.vertical", + type: VerticalLayout.xtype, vgap: 5, - items: [{ - type: "bi.button_group", - ref: function () { - self.popup = this; - }, - items: this._formatItems(o.items), - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, - layouts: [{ - type: "bi.vertical" - }], - behaviors: { - redmark: function () { - return true; - } - }, - value: o.value, - listeners: [{ - eventName: BI.Controller.EVENT_CHANGE, - action: function (type, val, obj) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - if (type === BI.Events.CLICK) { - self.fireEvent(BI.SearchTextValueComboPopup.EVENT_CHANGE, val, obj); + items: [ + { + type: ButtonGroup.xtype, + ref: _ref => { + this.popup = _ref; + }, + items: this._formatItems(o.items), + chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, + layouts: [ + { + type: VerticalLayout.xtype, + } + ], + behaviors: { + redmark () { + return true; + }, + }, + value: o.value, + listeners: [ + { + eventName: Controller.EVENT_CHANGE, + action: (...args) => { + const [type, val, obj] = args; + this.fireEvent( + Controller.EVENT_CHANGE, + ...args + ); + if (type === Events.CLICK) { + this.fireEvent( + SearchTextValueComboPopup.EVENT_CHANGE, + val, + obj + ); + } + }, } - } - }] - }] + ], + } + ], }; - }, + } - _formatItems: function (items) { - var o = this.options; - return BI.map(items, function (i, item) { - return BI.extend({ - type: "bi.single_select_item", + _formatItems(items) { + const o = this.options; + + return map(items, (i, item) => extend( + { + type: SingleSelectItem.xtype, textAlign: o.textAlign, - title: item.title || item.text - }, item); - }); - }, + title: item.title || item.text, + }, + item + )); + } - // mounted之后做check - mounted: function() { + mounted() { this.check(); - }, + } - populate: function (find, match, keyword) { - var items = BI.concat(find, match); - BI.SearchTextValueComboPopup.superclass.populate.apply(this, items); + populate(find, match, keyword) { + const items = concat(find, match); + super.populate.apply(this, items); this.popup.populate(this._formatItems(items), keyword); - }, + } - getValue: function () { + getValue() { return this.popup.getValue(); - }, + } - setValue: function (v) { + setValue(v) { this.popup.setValue(v); } - -}); -BI.SearchTextValueComboPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.search_text_value_combo_popup", BI.SearchTextValueComboPopup); +} diff --git a/src/case/combo/searchtextvaluecombo/trigger.searchtextvalue.js b/src/case/combo/searchtextvaluecombo/trigger.searchtextvalue.js index 7f6f7925d..a090b4c66 100644 --- a/src/case/combo/searchtextvaluecombo/trigger.searchtextvalue.js +++ b/src/case/combo/searchtextvaluecombo/trigger.searchtextvalue.js @@ -1,32 +1,53 @@ -/** - * Created by Windy on 2018/2/2. - */ -BI.SearchTextValueTrigger = BI.inherit(BI.Trigger, { +import { + shortcut, + find, + i18nText, + isNotEmptyString, + VerticalAdaptLayout +} from "@/core"; +import { + ButtonGroup, + Trigger, + Searcher, + IconButton +} from "@/base"; +import { TriggerIconButton } from "../../button"; +import { DefaultTextEditor } from "../../editor"; - props: function () { +@shortcut() +export class SearchTextValueTrigger extends Trigger { + static xtype = "bi.search_text_value_trigger"; + + static EVENT_SEARCHING = "EVENT_SEARCHING"; + static EVENT_STOP = "EVENT_STOP"; + static EVENT_START = "EVENT_START"; + static EVENT_CHANGE = "EVENT_CHANGE"; + static EVENT_CLEAR = "EVENT_CLEAR"; + + props() { return { baseCls: "bi-search-text-value-trigger", height: 24, - watermark: BI.i18nText("BI-Basic_Search"), + watermark: i18nText("BI-Basic_Search"), allowClear: false, title: () => this.editor.getText(), }; - }, + } - render: function () { - var self = this, o = this.options; + render() { + const o = this.options; - var triggerButton = { - type: "bi.trigger_icon_button", + const triggerButton = { + type: TriggerIconButton.xtype, cls: "trigger-icon-button", - ref: function () { - self.triggerBtn = this; + ref: _ref => { + this.triggerBtn = _ref; }, width: o.height, height: o.height, }; - var stateText = this._digest(o.value, o.items) || o.text; + const stateText = this._digest(o.value, o.items) || o.text; return { type: "bi.horizontal_fill", @@ -34,15 +55,15 @@ BI.SearchTextValueTrigger = BI.inherit(BI.Trigger, { items: [ { el: { - type: "bi.searcher", - ref: function () { - self.searcher = this; + type: Searcher.xtype, + ref: _ref => { + this.searcher = this; }, isAutoSearch: false, el: { - type: "bi.default_text_editor", - ref: function () { - self.editor = this; + type: DefaultTextEditor.xtype, + ref: _ref => { + this.editor = _ref; }, watermark: o.watermark, defaultText: o.defaultText, @@ -53,90 +74,103 @@ BI.SearchTextValueTrigger = BI.inherit(BI.Trigger, { popup: { type: "bi.search_text_value_combo_popup", cls: "bi-card", - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, - tipText: BI.i18nText("BI-No_Select"), + chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, + tipText: i18nText("BI-No_Select"), }, - onSearch: function (obj, callback) { - var keyword = obj.keyword; - var finding = BI.Func.getSearchResult(o.items, keyword); - var matched = finding.match, find = finding.find; + onSearch (obj, callback) { + const keyword = obj.keyword; + const finding = BI.Func.getSearchResult( + o.items, + keyword + ); + const matched = finding.match, + find = finding.find; callback(matched, find); }, - listeners: [{ - eventName: BI.Searcher.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.SearchTextValueTrigger.EVENT_CHANGE); - } - }] - } - }, { - el: o.allowClear ? { - type: "bi.vertical_adapt", - horizontalAlign: "left", - scrollable: false, - items: [ + listeners: [ { - el: { - type: "bi.icon_button", - ref: function (_ref) { - self.clearBtn = _ref; - }, - cls: "close-h-font " + (o.allowClear ? "clear-button" : ""), - stopPropagation: true, - invisible: !BI.isNotEmptyString(stateText), - width: o.height, - height: o.height, - handler: function () { - self.fireEvent(BI.SearchTextValueTrigger.EVENT_CLEAR); - }, + eventName: Searcher.EVENT_CHANGE, + action: () => { + this.fireEvent( + SearchTextValueTrigger.EVENT_CHANGE + ); }, - }, { - el: triggerButton, } - ] - } : triggerButton, - width: 24 + ], + }, + }, + { + el: o.allowClear + ? { + type: VerticalAdaptLayout.xtype, + horizontalAlign: "left", + scrollable: false, + items: [ + { + el: { + type: IconButton.xtype, + ref: _ref => { + this.clearBtn = _ref; + }, + cls: + `close-h-font ${ + o.allowClear + ? "clear-button" + : ""}`, + stopPropagation: true, + invisible: + !isNotEmptyString(stateText), + width: o.height, + height: o.height, + handler: () => { + this.fireEvent( + SearchTextValueTrigger.EVENT_CLEAR + ); + }, + }, + }, + { + el: triggerButton, + } + ], + } + : triggerButton, + width: 24, } - ] + ], }; - }, + } - _setState: function (v) { + _setState(v) { this.editor.setState(v); - }, + } - _digest: function (value, items) { - var result = BI.find(items, function (i, item) { - return item.value === value; - }); + _digest(value, items) { + const result = find(items, (i, item) => item.value === value); + return result?.text; - }, + } - stopEditing: function () { + stopEditing() { this.searcher.stopSearch(); - }, + } - getSearcher: function () { + getSearcher() { return this.searcher; - }, + } - populate: function (items) { + populate(items) { this.options.items = items; - }, + } - setValue: function (vals) { - var digestText = this._digest(vals, this.options.items); + setValue(vals) { + const digestText = this._digest(vals, this.options.items); this._setState(digestText); - this.options.allowClear && this.clearBtn.setVisible(BI.isNotEmptyString(digestText)); - }, + this.options.allowClear && + this.clearBtn.setVisible(isNotEmptyString(digestText)); + } - getValue: function () { + getValue() { return this.searcher.getValue(); } -}); -BI.SearchTextValueTrigger.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.SearchTextValueTrigger.EVENT_STOP = "EVENT_STOP"; -BI.SearchTextValueTrigger.EVENT_START = "EVENT_START"; -BI.SearchTextValueTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SearchTextValueTrigger.EVENT_CLEAR = "EVENT_CLEAR"; -BI.shortcut("bi.search_text_value_trigger", BI.SearchTextValueTrigger); +} diff --git a/src/case/combo/textvaluecheckcombo/combo.textvaluecheck.js b/src/case/combo/textvaluecheckcombo/combo.textvaluecheck.js index 9c5f0d0fc..c2fcfe901 100644 --- a/src/case/combo/textvaluecheckcombo/combo.textvaluecheck.js +++ b/src/case/combo/textvaluecheckcombo/combo.textvaluecheck.js @@ -1,92 +1,113 @@ -/** - * @class BI.TextValueCheckCombo - * @extend BI.Widget - * combo : text + icon, popup : check + text - */ -BI.TextValueCheckCombo = BI.inherit(BI.Widget, { - _defaultConfig: function (config) { - return BI.extend(BI.TextValueCheckCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-text-value-check-combo " + (config.simple ? "bi-border-bottom" : "bi-border"), +import { + shortcut, + Widget, + extend, + isFunction, + createWidget, + toPix, + Controller, + isKey, + isNull, + isArray +} from "@/core"; +import { ButtonGroup, Combo } from "@/base"; +import { TextValueCheckComboPopup } from "./popup.textvaluecheck"; +import { SelectTextTrigger } from "../../trigger"; + +@shortcut() +export class TextValueCheckCombo extends Widget { + static xtype = "bi.text_value_check_combo"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig(config) { + return extend(super._defaultConfig(...arguments), { + baseCls: + `bi-text-value-check-combo ${ + config.simple ? "bi-border-bottom" : "bi-border"}`, width: 100, height: 24, - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, + chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, value: "", }); - }, + } - _init: function () { - var self = this, o = this.options; - o.value = BI.isFunction(o.value) ? this.__watch(o.value, function (context, newValue) { - self.setValue(newValue); - }) : o.value; - o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { - self.populate(newValue); - }) : o.items; - BI.TextValueCheckCombo.superclass._init.apply(this, arguments); - this.trigger = BI.createWidget({ - type: "bi.select_text_trigger", + _init() { + const o = this.options; + o.value = isFunction(o.value) + ? this.__watch(o.value, (context, newValue) => { + this.setValue(newValue); + }) + : o.value; + o.items = isFunction(o.items) + ? this.__watch(o.items, (context, newValue) => { + this.populate(newValue); + }) + : o.items; + super._init(...arguments); + this.trigger = createWidget({ + type: SelectTextTrigger.xtype, cls: "text-value-trigger", items: o.items, - height: BI.toPix(o.height, 2), + height: toPix(o.height, 2), text: o.text, - value: o.value + value: o.value, }); - this.popup = BI.createWidget({ - type: "bi.text_value_check_combo_popup", + this.popup = createWidget({ + type: TextValueCheckComboPopup.xtype, chooseType: o.chooseType, items: o.items, - value: o.value + value: o.value, }); - this.popup.on(BI.TextValueCheckComboPopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.textIconCheckCombo.hideView(); - self.fireEvent(BI.TextValueCheckCombo.EVENT_CHANGE); + this.popup.on(TextValueCheckComboPopup.EVENT_CHANGE, () => { + this.setValue(this.popup.getValue()); + this.textIconCheckCombo.hideView(); + this.fireEvent(TextValueCheckCombo.EVENT_CHANGE); }); - this.popup.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.popup.on(Controller.EVENT_CHANGE, ...args => { + this.fireEvent(Controller.EVENT_CHANGE, ...args); }); - this.textIconCheckCombo = BI.createWidget({ - type: "bi.combo", + this.textIconCheckCombo = createWidget({ + type: Combo.xtype, container: o.container, direction: o.direction, element: this, - width: BI.toPix(o.width, 2), - height: BI.toPix(o.height, 2), + width: toPix(o.width, 2), + height: toPix(o.height, 2), adjustLength: 2, el: this.trigger, popup: { el: this.popup, - maxHeight: 300 - } + maxHeight: 300, + }, }); - if (BI.isKey(o.value)) { + if (isKey(o.value)) { this.setValue(o.value); } - }, + } - setTitle: function (title) { + setTitle(title) { this.trigger.setTitle(title); - }, + } - setValue: function (v) { + setValue(v) { this.trigger.setValue(v); this.popup.setValue(v); - }, + } - setWarningTitle: function (title) { + setWarningTitle(title) { this.trigger.setWarningTitle(title); - }, + } - getValue: function () { - var value = this.popup.getValue(); - return BI.isNull(value) ? [] : (BI.isArray(value) ? value : [value]); - }, + getValue() { + const value = this.popup.getValue(); + + return isNull(value) ? [] : isArray(value) ? value : [value]; + } - populate: function (items) { + populate(items) { this.options.items = items; this.textIconCheckCombo.populate(items); } -}); -BI.TextValueCheckCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.text_value_check_combo", BI.TextValueCheckCombo); +} diff --git a/src/case/combo/textvaluecheckcombo/popup.textvaluecheck.js b/src/case/combo/textvaluecheckcombo/popup.textvaluecheck.js index b25ccc141..9c32c2b68 100644 --- a/src/case/combo/textvaluecheckcombo/popup.textvaluecheck.js +++ b/src/case/combo/textvaluecheckcombo/popup.textvaluecheck.js @@ -1,64 +1,83 @@ -BI.TextValueCheckComboPopup = BI.inherit(BI.Pane, { - _defaultConfig: function () { - return BI.extend(BI.TextValueCheckComboPopup.superclass._defaultConfig.apply(this, arguments), { +import { + shortcut, + extend, + createWidget, + Controller, + Events, + VerticalLayout, + map +} from "@/core"; +import { Pane, ButtonGroup } from "@/base"; +import { SingleSelectItem } from "../../button"; + +@shortcut() +export class TextValueCheckComboPopup extends Pane { + static xtype = "bi.text_value_check_combo_popup"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { baseCls: "bi-text-icon-popup", - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE + chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, }); - }, + } - _init: function () { - BI.TextValueCheckComboPopup.superclass._init.apply(this, arguments); - var o = this.options, self = this; - this.popup = BI.createWidget({ - type: "bi.button_group", + _init() { + super._init(...arguments); + const o = this.options; + this.popup = createWidget({ + type: ButtonGroup.xtype, items: this._formatItems(o.items), chooseType: o.chooseType, - layouts: [{ - type: "bi.vertical" - }], - value: o.value + layouts: [ + { + type: VerticalLayout.xtype, + } + ], + value: o.value, }); - this.popup.on(BI.Controller.EVENT_CHANGE, function (type, val, obj) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - if (type === BI.Events.CLICK) { - self.fireEvent(BI.TextValueCheckComboPopup.EVENT_CHANGE, val, obj); + this.popup.on(Controller.EVENT_CHANGE, (...args) => { + const [type, val, obj] = args; + this.fireEvent(Controller.EVENT_CHANGE, ...args); + if (type === Events.CLICK) { + this.fireEvent(TextValueCheckComboPopup.EVENT_CHANGE, val, obj); } }); - BI.createWidget({ - type: "bi.vertical", + createWidget({ + type: VerticalLayout.xtype, element: this, vgap: 5, - items: [this.popup] + items: [this.popup], }); - }, + } - _formatItems: function (items) { - var o = this.options; - return BI.map(items, function (i, item) { - return BI.extend({ - type: "bi.single_select_item", + _formatItems(items) { + const o = this.options; + + return map(items, (i, item) => extend( + { + type: SingleSelectItem.xtype, cls: "bi-list-item", textAlign: o.textAlign, - title: item.title || item.text - }, item); - }); - }, + title: item.title || item.text, + }, + item + )); + } - populate: function (items) { - BI.TextValueCheckComboPopup.superclass.populate.apply(this, arguments); + populate(items) { + super.populate(...arguments); this.popup.populate(this._formatItems(items)); - }, + } - getValue: function () { + getValue() { return this.popup.getValue(); - }, + } - setValue: function (v) { + setValue(v) { this.popup.setValue(v); } - -}); -BI.TextValueCheckComboPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.text_value_check_combo_popup", BI.TextValueCheckComboPopup); +} diff --git a/src/case/combo/textvaluecombo/combo.textvalue.js b/src/case/combo/textvaluecombo/combo.textvalue.js index 9dc088639..a9bf892b5 100644 --- a/src/case/combo/textvaluecombo/combo.textvalue.js +++ b/src/case/combo/textvaluecombo/combo.textvalue.js @@ -1,15 +1,37 @@ -/** - * @class BI.TextValueCombo - * @extend BI.Widget - * combo : text + icon, popup : text - * 参见场景dashboard布局方式选择 - */ -BI.TextValueCombo = BI.inherit(BI.Widget, { - _defaultConfig: function (config) { - return BI.extend(BI.TextValueCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-text-value-combo " + (config.simple ? "bi-border-bottom" : "bi-border bi-border-radius"), +import { + shortcut, + Widget, + extend, + isFunction, + toPix, + isEmptyArray, + Controller, + isKey, + isObject, + isNull, + isArray, + intersection, + map +} from "@/core"; +import { ButtonGroup, Combo } from "@/base"; +import { SelectTextTrigger } from "../../trigger"; +import { TextValueComboPopup } from "./popup.textvalue"; + +@shortcut() +export class TextValueCombo extends Widget { + static xtype = "bi.text_value_combo"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig(config) { + return extend(super._defaultConfig(...arguments), { + baseCls: + `bi-text-value-combo ${ + config.simple + ? "bi-border-bottom" + : "bi-border bi-border-radius"}`, height: 24, - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, + chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, text: "", value: "", defaultText: "", @@ -19,44 +41,48 @@ BI.TextValueCombo = BI.inherit(BI.Widget, { title: null, allowSelectAll: true, }); - }, - - _init: function () { - var self = this, o = this.options; - o.value = BI.isFunction(o.value) ? this.__watch(o.value, function (context, newValue) { - self.setValue(newValue); - }) : o.value; - o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { - self.populate(newValue); - }) : o.items; - BI.TextValueCombo.superclass._init.apply(this, arguments); - }, + } - render: function () { + _init() { + const o = this.options; + o.value = isFunction(o.value) + ? this.__watch(o.value, (context, newValue) => { + this.setValue(newValue); + }) + : o.value; + o.items = isFunction(o.items) + ? this.__watch(o.items, (context, newValue) => { + this.populate(newValue); + }) + : o.items; + super._init(...arguments); + } + render() { const o = this.options; const title = () => { - if (BI.isFunction(o.title)) { + if (isFunction(o.title)) { return o.title(); } if (this.options.status === "error") { return { level: "warning", - text: o.warningTitle + text: o.warningTitle, }; } + return { - level: "success" + level: "success", }; }; const trigger = { - type: "bi.select_text_trigger", - ref: ref => this.trigger = ref, + type: SelectTextTrigger.xtype, + ref: ref => (this.trigger = ref), cls: "text-value-trigger", items: o.items, - height: BI.toPix(o.height, o.simple ? 1 : 2), + height: toPix(o.height, o.simple ? 1 : 2), text: o.text, value: o.value, title, @@ -64,150 +90,169 @@ BI.TextValueCombo = BI.inherit(BI.Widget, { defaultText: o.defaultText, listeners: [ { - eventName: BI.SelectTextTrigger.EVENT_CLEAR, + eventName: SelectTextTrigger.EVENT_CLEAR, action: () => { this._clear(); - this.fireEvent(BI.TextValueCombo.EVENT_CHANGE); - } + this.fireEvent(TextValueCombo.EVENT_CHANGE); + }, } ], - ...o.el + ...o.el, }; let changeTag = false; const popup = { type: "bi.text_value_combo_popup", - ref: ref => this.popup = ref, + ref: ref => (this.popup = ref), chooseType: o.chooseType, items: o.items, allowSelectAll: o.allowSelectAll, listeners: [ { - eventName: BI.TextValueComboPopup.EVENT_CHANGE, + eventName: TextValueComboPopup.EVENT_CHANGE, action: (...args) => { changeTag = true; const value = this.popup.getValue(); this.setValue(value); - if (o.chooseType === BI.ButtonGroup.CHOOSE_TYPE_SINGLE) { + if (o.chooseType === ButtonGroup.CHOOSE_TYPE_SINGLE) { this.combo.hideView(...args); - this.fireEvent(BI.TextValueCombo.EVENT_CHANGE, ...args); + this.fireEvent( + TextValueCombo.EVENT_CHANGE, + ...args + ); } - if (o.chooseType === BI.ButtonGroup.CHOOSE_TYPE_MULTI && BI.isEmptyArray(value)) { + if ( + o.chooseType === ButtonGroup.CHOOSE_TYPE_MULTI && + isEmptyArray(value) + ) { this._clear(); } - } - }, { - eventName: BI.Controller.EVENT_CHANGE, + }, + }, + { + eventName: Controller.EVENT_CHANGE, action: (...args) => { - this.fireEvent(BI.Controller.EVENT_CHANGE, ...args); - } - }, { - eventName: BI.TextValueComboPopup.EVENT_CLEAR, + this.fireEvent(Controller.EVENT_CHANGE, ...args); + }, + }, + { + eventName: TextValueComboPopup.EVENT_CLEAR, action: (...args) => { changeTag = true; this._clear(); this.combo.hideView(); - } - }, { - eventName: BI.TextValueComboPopup.EVENT_CONFIRM, + }, + }, + { + eventName: TextValueComboPopup.EVENT_CONFIRM, action: (...args) => { this.combo.hideView(); - } + }, } - ] + ], }; return { - type: "bi.combo", - height: BI.toPix(o.height, 2), - width: BI.toPix(o.width, 2), - ref: ref => this.combo = ref, + type: Combo.xtype, + height: toPix(o.height, 2), + width: toPix(o.width, 2), + ref: ref => (this.combo = ref), container: o.container, direction: o.direction, adjustLength: 2, el: trigger, listeners: [ { - eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, + eventName: Combo.EVENT_BEFORE_POPUPVIEW, action: () => { changeTag = false; - } - }, { - eventName: BI.Combo.EVENT_AFTER_HIDEVIEW, + }, + }, + { + eventName: Combo.EVENT_AFTER_HIDEVIEW, action: (...args) => { - if (o.chooseType !== BI.ButtonGroup.CHOOSE_TYPE_SINGLE && changeTag) { - this.fireEvent(BI.TextValueCombo.EVENT_CHANGE, ...args); + if ( + o.chooseType !== ButtonGroup.CHOOSE_TYPE_SINGLE && + changeTag + ) { + this.fireEvent( + TextValueCombo.EVENT_CHANGE, + ...args + ); } - } + }, } ], popup: { el: popup, value: o.value, maxHeight: 240, - minHeight: (o.chooseType === BI.ButtonGroup.CHOOSE_TYPE_MULTI && o.allowSelectAll) ? 55 : 25 - } + minHeight: + o.chooseType === ButtonGroup.CHOOSE_TYPE_MULTI && + o.allowSelectAll + ? 55 + : 25, + }, }; - }, + } - mounted: function () { + mounted() { const o = this.options; - if (BI.isKey(o.value) || BI.isObject(o.value)) { + if (isKey(o.value) || isObject(o.value)) { this._checkError(o.value); } - }, + } - _clear: function () { + _clear() { this.trigger.setText(""); this.combo.setValue(); this.setStatus("success"); - }, - - _checkError: function (v) { + } - if (BI.isNull(v)) { + _checkError(v) { + if (isNull(v)) { this.setStatus("success"); + return; } - var vals = BI.isArray(v) ? v : [v]; + const vals = isArray(v) ? v : [v]; - var result = BI.intersection(BI.map(this.options.items, "value"), vals); + const result = intersection(map(this.options.items, "value"), vals); if (result.length !== vals.length) { this.setStatus("error"); } else { this.setStatus("success"); } - }, + } - clear: function () { + clear() { this._clear(); - }, + } - setText: function (text) { + setText(text) { this.trigger.setText(text); - }, + } - setValue: function (v) { + setValue(v) { this.combo.setValue(v); this._checkError(v); - }, + } - setStatus: function (status) { + setStatus(status) { this.element.removeClass(`bi-status-${this.options.status}`); this.element.addClass(`bi-status-${status}`); this.options.status = status; - }, + } - getValue: function () { - var value = this.combo.getValue(); - return BI.isNull(value) ? [] : (BI.isArray(value) ? value : [value]); - }, + getValue() { + const value = this.combo.getValue(); + + return isNull(value) ? [] : isArray(value) ? value : [value]; + } - populate: function (items) { + populate(items) { this.options.items = items; this.combo.populate(items); } -}); -BI.TextValueCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.text_value_combo", BI.TextValueCombo); +} diff --git a/src/case/combo/textvaluecombo/combo.textvaluesmall.js b/src/case/combo/textvaluecombo/combo.textvaluesmall.js index 155b124ce..d531e1885 100644 --- a/src/case/combo/textvaluecombo/combo.textvaluesmall.js +++ b/src/case/combo/textvaluecombo/combo.textvaluesmall.js @@ -1,32 +1,41 @@ -/** - * @class BI.SmallTextValueCombo - * @extend BI.Widget - * combo : text + icon, popup : text - * 参见场景dashboard布局方式选择 - */ -BI.SmallTextValueCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.SmallTextValueCombo.superclass._defaultConfig.apply(this, arguments), { +import { + shortcut, + Widget, + extend +} from "@/core"; +import { ButtonGroup } from "@/base"; +import { SmallSelectTextTrigger } from "../../trigger"; +import { TextValueCombo } from "./combo.textvalue"; + +@shortcut() +export class SmallTextValueCombo extends Widget { + static xtype = "bi.small_text_value_combo"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { width: 100, height: 20, - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, + chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, el: {}, - text: "" + text: "", }); - }, + } - render: function () { - var o = this.options; + render() { + const o = this.options; + return { type: "bi.text_value_combo", - ref: (_ref) => { + ref: _ref => { this.combo = _ref; }, height: o.height, chooseType: o.chooseType, el: { - type: "bi.small_select_text_trigger", - ...o.el + type: SmallSelectTextTrigger.xtype, + ...o.el, }, text: o.text, value: o.value, @@ -34,26 +43,29 @@ BI.SmallTextValueCombo = BI.inherit(BI.Widget, { allowClear: o.allowClear, status: o.status, title: o.title, - listeners: [{ - eventName: BI.TextValueCombo.EVENT_CHANGE, - action: (...args) => { - this.fireEvent(BI.SmallTextValueCombo.EVENT_CHANGE, ...args); + listeners: [ + { + eventName: TextValueCombo.EVENT_CHANGE, + action: (...args) => { + this.fireEvent( + SmallTextValueCombo.EVENT_CHANGE, + ...args + ); + }, } - }] - } - }, + ], + }; + } - setValue: function (v) { + setValue(v) { this.combo.setValue(v); - }, + } - getValue: function () { + getValue() { return this.combo.getValue(); - }, + } - populate: function (items) { + populate(items) { this.combo.populate(items); } -}); -BI.SmallTextValueCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.small_text_value_combo", BI.SmallTextValueCombo); +} diff --git a/src/case/combo/textvaluecombo/popup.textvalue.js b/src/case/combo/textvaluecombo/popup.textvalue.js index aed1b0979..a9fa0caaf 100644 --- a/src/case/combo/textvaluecombo/popup.textvalue.js +++ b/src/case/combo/textvaluecombo/popup.textvalue.js @@ -1,190 +1,240 @@ -BI.TextValueComboPopup = BI.inherit(BI.Pane, { - _defaultConfig: function () { - return BI.extend(BI.TextValueComboPopup.superclass._defaultConfig.apply(this, arguments), { +import { + shortcut, + extend, + Controller, + map, + Events, + VerticalAlign, + createItems, + i18nText, + VerticalLayout, + CenterLayout +} from "@/core"; +import { ButtonGroup, Pane, TextButton } from "@/base"; +import { SelectList } from "../../list/list.select"; +import { ListPane } from "../../layer"; +import { SingleSelectItem, MultiSelectItem } from "../../button"; + +@shortcut() +export class TextValueComboPopup extends Pane { + static xtype = "bi.text_value_combo_popup"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + static EVENT_CLEAR = "EVENT_CLEAR"; + static EVENT_CONFIRM = "EVENT_CONFIRM"; + + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { baseCls: "bi-text-icon-popup", - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, + chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, allowSelectAll: true, }); - }, + } render() { - var o = this.options, self = this; - if (o.chooseType !== BI.ButtonGroup.CHOOSE_TYPE_MULTI) { + const o = this.options; + if (o.chooseType !== ButtonGroup.CHOOSE_TYPE_MULTI) { return { - type: "bi.vertical", + type: VerticalLayout.xtype, vgap: 5, items: [ { - type: "bi.button_group", - ref: (_ref) => { + type: ButtonGroup.xtype, + ref: _ref => { this.popup = _ref; }, items: this._formatItems(o.items), chooseType: o.chooseType, layouts: [ { - type: "bi.vertical" + type: VerticalLayout.xtype, } ], value: o.value, listeners: [ { - eventName: BI.Controller.EVENT_CHANGE, - action: function (type, val, obj) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - if (type === BI.Events.CLICK) { - self.fireEvent(BI.TextValueComboPopup.EVENT_CHANGE, val, obj); + eventName: Controller.EVENT_CHANGE, + action: (type, val, obj) => { + this.fireEvent( + Controller.EVENT_CHANGE, + arguments + ); + if (type === Events.CLICK) { + this.fireEvent( + TextValueComboPopup.EVENT_CHANGE, + val, + obj + ); } - } + }, } - ] + ], } - ] + ], }; } + return { - type: "bi.vertical", - verticalAlign: BI.VerticalAlign.Stretch, - items: o.allowSelectAll ? [ - { - type: "bi.select_list", - logic: { - dynamic: true, - innerVgap: 5, - rowSize: ["", "fill"], - verticalAlign: BI.VerticalAlign.Stretch - }, - ref: (_ref) => { - this.popup = _ref; - }, - el: { + type: VerticalLayout.xtype, + verticalAlign: VerticalAlign.Stretch, + items: o.allowSelectAll + ? [ + { + type: SelectList.xtype, + logic: { + dynamic: true, + innerVgap: 5, + rowSize: ["", "fill"], + verticalAlign: VerticalAlign.Stretch, + }, + ref: _ref => { + this.popup = _ref; + }, el: { - chooseType: o.chooseType, - } - }, - items: this._formatItems(o.items), - value: { - type: BI.ButtonGroup.CHOOSE_TYPE_MULTI, - value: o.value - }, - height: "fill", - listeners: [ - { - eventName: BI.SelectList.EVENT_CHANGE, - action: function (val) { - self.fireEvent(BI.TextValueComboPopup.EVENT_CHANGE, val); - } - } - ] - }, { - type: "bi.center", - cls: "list-view-toolbar bi-high-light bi-split-top", - height: 24, - items: BI.createItems([ - { - type: "bi.text_button", - text: BI.i18nText("BI-Basic_Clears"), - handler: function () { - self.fireEvent(BI.TextValueComboPopup.EVENT_CLEAR); - } - }, { - type: "bi.text_button", - text: BI.i18nText("BI-Basic_OK"), - handler: function () { - self.fireEvent(BI.TextValueComboPopup.EVENT_CONFIRM); + el: { + chooseType: o.chooseType, + }, + }, + items: this._formatItems(o.items), + value: { + type: ButtonGroup.CHOOSE_TYPE_MULTI, + value: o.value, + }, + height: "fill", + listeners: [ + { + eventName: SelectList.EVENT_CHANGE, + action (val) { + this.fireEvent( + TextValueComboPopup.EVENT_CHANGE, + val + ); + }, } - } - ], { - once: false, - shadow: true, - isShadowShowingOnSelected: true - }) - } - ] : [ - { - type: "bi.list_pane", - logic: { - dynamic: true, - innerVgap: 5, - rowSize: ["", "fill"], - verticalAlign: BI.VerticalAlign.Stretch - }, - ref: (_ref) => { - this.popup = _ref; - }, - el: { - chooseType: o.chooseType, + ], }, - items: this._formatItems(o.items), - value: o.value, - height: "fill", - listeners: [ - { - eventName: BI.ListPane.EVENT_CHANGE, - action: function (val) { - self.fireEvent(BI.TextValueComboPopup.EVENT_CHANGE, val); + { + type: CenterLayout.xtype, + cls: "list-view-toolbar bi-high-light bi-split-top", + height: 24, + items: createItems( + [ + { + type: TextButton.xtype, + text: i18nText("BI-Basic_Clears"), + handler: () => { + this.fireEvent( + TextValueComboPopup.EVENT_CLEAR + ); + }, + }, + { + type: TextButton.xtype, + text: i18nText("BI-Basic_OK"), + handler: () => { + this.fireEvent( + TextValueComboPopup.EVENT_CONFIRM + ); + }, + } + ], + { + once: false, + shadow: true, + isShadowShowingOnSelected: true, + } + ), + } + ] + : [ + { + type: ListPane.xtype, + logic: { + dynamic: true, + innerVgap: 5, + rowSize: ["", "fill"], + verticalAlign: VerticalAlign.Stretch, + }, + ref: _ref => { + this.popup = _ref; + }, + el: { + chooseType: o.chooseType, + }, + items: this._formatItems(o.items), + value: o.value, + height: "fill", + listeners: [ + { + eventName: ListPane.EVENT_CHANGE, + action: val => { + this.fireEvent( + TextValueComboPopup.EVENT_CHANGE, + val + ); + }, } - } - ] - } - ], + ], + } + ], }; - }, + } - beforeMount: function () { - if (this.options.chooseType !== BI.ButtonGroup.CHOOSE_TYPE_MULTI) { + beforeMount() { + if (this.options.chooseType !== ButtonGroup.CHOOSE_TYPE_MULTI) { this.check(); } - }, + } - _formatItems: function (items) { - var o = this.options; - return BI.map(items, function (i, item) { - return BI.extend({ - type: o.chooseType !== BI.ButtonGroup.CHOOSE_TYPE_MULTI ? "bi.single_select_item" : "bi.multi_select_item", + _formatItems(items) { + const o = this.options; + + return map(items, (i, item) => extend( + { + type: + o.chooseType !== ButtonGroup.CHOOSE_TYPE_MULTI + ? SingleSelectItem.xtype + : MultiSelectItem.xtype, iconWrapperWidth: 36, textAlign: o.textAlign, - title: item.title || item.text - }, item); - }); - }, + title: item.title || item.text, + }, + item + )); + } - populate: function (items) { - BI.TextValueComboPopup.superclass.populate.apply(this, arguments); + populate(items) { + super.populate(...arguments); this.popup.populate(this._formatItems(items)); - }, + } - getValue: function () { - if (this.options.chooseType !== BI.ButtonGroup.CHOOSE_TYPE_MULTI) { + getValue() { + if (this.options.chooseType !== ButtonGroup.CHOOSE_TYPE_MULTI) { return this.popup.getValue(); } - var val = this.popup.getValue(); + const val = this.popup.getValue(); if (!this.options.allowSelectAll) { return val; } - if (val.type === BI.ButtonGroup.CHOOSE_TYPE_MULTI) { + if (val.type === ButtonGroup.CHOOSE_TYPE_MULTI) { return val.value; } else { return val.assist; } - }, + } - setValue: function (v) { - if (this.options.chooseType !== BI.ButtonGroup.CHOOSE_TYPE_MULTI) { + setValue(v) { + if (this.options.chooseType !== ButtonGroup.CHOOSE_TYPE_MULTI) { return this.popup.setValue(v); } if (!this.options.allowSelectAll) { this.popup.setValue(v); + return; } this.popup.setValue({ - type: BI.ButtonGroup.CHOOSE_TYPE_MULTI, - value: v + type: ButtonGroup.CHOOSE_TYPE_MULTI, + value: v, }); } - -}); -BI.TextValueComboPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.TextValueComboPopup.EVENT_CLEAR = "EVENT_CLEAR"; -BI.TextValueComboPopup.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.shortcut("bi.text_value_combo_popup", BI.TextValueComboPopup); +} diff --git a/src/case/index.js b/src/case/index.js index d2cbe36fc..647534575 100644 --- a/src/case/index.js +++ b/src/case/index.js @@ -11,8 +11,10 @@ import { MultiSelectBar } from "./toolbar/toolbar.multiselect"; import * as layer from "./layer"; import * as linearSegment from "./linearsegment"; import { SelectList } from "./list/list.select"; +import * as combo from "./combo"; Object.assign(BI, { + ...combo, ...button, ...calendarItem, ...pager, @@ -28,6 +30,7 @@ Object.assign(BI, { SelectList, }); +export * from "./combo"; export * from "./button"; export * from "./calendar"; export * from "./pager";