Browse Source

KERNEL-14071 refactor: case/trigger的es6化

es6
Zhenfei.Li 2 years ago
parent
commit
0c009add2c
  1. 7
      es6.js
  2. 2
      src/base/single/trigger/trigger.js
  3. 3
      src/case/index.js
  4. 8
      src/case/trigger/index.js
  5. 105
      src/case/trigger/trigger.editor.js
  6. 33
      src/case/trigger/trigger.icon.js
  7. 84
      src/case/trigger/trigger.icon.text.js
  8. 67
      src/case/trigger/trigger.icon.text.select.js
  9. 159
      src/case/trigger/trigger.text.js
  10. 102
      src/case/trigger/trigger.text.select.js
  11. 66
      src/case/trigger/trigger.text.select.small.js
  12. 64
      src/case/trigger/trigger.text.small.js

7
es6.js

@ -97,6 +97,13 @@ collection.methods.forEach(el => {
"isString", "isString",
"isNumber", "isNumber",
"isEmpty", "isEmpty",
"isEmptyString",
"any",
"deepContains",
"isNotEmptyString",
"each",
"contains",
"remove",
]; ];
target.forEach(t => { target.forEach(t => {

2
src/base/single/trigger/trigger.js

@ -12,7 +12,7 @@ export class Trigger extends Single {
const conf = super._defaultConfig(...arguments); const conf = super._defaultConfig(...arguments);
return extend(conf, { return extend(conf, {
_baseCls: (conf._baseCls || "") + " bi-trigger cursor-pointer", _baseCls: `${conf._baseCls || ""} bi-trigger cursor-pointer`,
height: 24, height: 24,
}); });
} }

3
src/case/index.js

@ -2,16 +2,19 @@ import * as button from "./button";
import * as calendarItem from "./calendar"; import * as calendarItem from "./calendar";
import * as pager from "./pager"; import * as pager from "./pager";
import * as editor from "./editor"; import * as editor from "./editor";
import * as trigger from "./trigger";
Object.assign(BI, { Object.assign(BI, {
...button, ...button,
...calendarItem, ...calendarItem,
...pager, ...pager,
...editor, ...editor,
...trigger,
}); });
export * from "./button"; export * from "./button";
export * from "./calendar"; export * from "./calendar";
export * from "./pager"; export * from "./pager";
export * from "./editor"; export * from "./editor";
export * from "./trigger";

8
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";

105
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 * 文本输入框trigger
* *
* Created by GUY on 2015/9/15. * Created by GUY on 2015/9/15.
* @class BI.EditorTrigger * @class EditorTrigger
* @extends BI.Trigger * @extends Trigger
*/ */
BI.EditorTrigger = BI.inherit(BI.Trigger, { @shortcut()
_defaultConfig: function (config) { export class EditorTrigger extends Trigger {
var conf = BI.EditorTrigger.superclass._defaultConfig.apply(this, arguments); static xtype = "bi.editor_trigger";
return BI.extend(conf, { static EVENT_CHANGE = "EVENT_CHANGE";
baseCls: (conf.baseCls || "") + " bi-editor-trigger bi-border-radius " + (config.simple ? "bi-border-bottom" : "bi-border"), 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, height: 24,
validationChecker: BI.emptyFn, validationChecker: emptyFn,
quitChecker: BI.emptyFn, quitChecker: emptyFn,
allowBlank: false, allowBlank: false,
watermark: "", watermark: "",
errorText: "" errorText: "",
}); });
}, }
_init: function () { _init() {
BI.EditorTrigger.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options, c = this._const; const o = this.options;
this.editor = BI.createWidget({ this.editor = createWidget({
type: "bi.sign_editor", type: "bi.sign_editor",
height: BI.toPix(o.height, 2), height: toPix(o.height, 2),
value: o.value, value: o.value,
validationChecker: o.validationChecker, validationChecker: o.validationChecker,
quitChecker: o.quitChecker, quitChecker: o.quitChecker,
allowBlank: o.allowBlank, allowBlank: o.allowBlank,
watermark: o.watermark, watermark: o.watermark,
errorText: o.errorText, errorText: o.errorText,
title: function () { title: () => this.getValue(),
return self.getValue();
}
}); });
this.editor.on(BI.Controller.EVENT_CHANGE, function () { this.editor.on(Controller.EVENT_CHANGE, (...args) => {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); this.fireEvent(Controller.EVENT_CHANGE, ...args);
}); });
this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { this.editor.on(SignEditor.EVENT_CHANGE, (...args) => {
self.fireEvent(BI.EditorTrigger.EVENT_CHANGE, arguments); this.fireEvent(EditorTrigger.EVENT_CHANGE, ...args);
}); });
this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { this.editor.on(SignEditor.EVENT_FOCUS, (...args) => {
self.fireEvent(BI.EditorTrigger.EVENT_FOCUS, arguments); this.fireEvent(EditorTrigger.EVENT_FOCUS, ...args);
}); });
this.editor.on(BI.SignEditor.EVENT_EMPTY, function () { this.editor.on(SignEditor.EVENT_EMPTY, (...args) => {
self.fireEvent(BI.EditorTrigger.EVENT_EMPTY, arguments); this.fireEvent(EditorTrigger.EVENT_EMPTY, ...args);
}); });
this.editor.on(BI.SignEditor.EVENT_VALID, function () { this.editor.on(SignEditor.EVENT_VALID, (...args) => {
self.fireEvent(BI.EditorTrigger.EVENT_VALID, arguments); this.fireEvent(EditorTrigger.EVENT_VALID, ...args);
}); });
this.editor.on(BI.SignEditor.EVENT_ERROR, function () { this.editor.on(SignEditor.EVENT_ERROR, (...args) => {
self.fireEvent(BI.EditorTrigger.EVENT_ERROR, arguments); this.fireEvent(EditorTrigger.EVENT_ERROR, ...args);
}); });
BI.createWidget({ createWidget({
element: this, element: this,
type: "bi.horizontal_fill", type: "bi.horizontal_fill",
height: BI.toPix(o.height, 2), height: toPix(o.height, 2),
items: [ items: [
{ {
el: this.editor, el: this.editor,
width: "fill" width: "fill",
}, { }, {
el: { el: {
type: "bi.trigger_icon_button", 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(); return this.editor.getValue();
}, }
setValue: function (value) { setValue(value) {
this.editor.setValue(value); this.editor.setValue(value);
}, }
setText: function (text) { setText(text) {
this.editor.setState(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);

33
src/case/trigger/trigger.icon.js

@ -1,30 +1,35 @@
import { shortcut, extend, createWidget } from "@/core";
import { Trigger } from "@/base";
/** /**
* 图标按钮trigger * 图标按钮trigger
* *
* Created by GUY on 2015/10/8. * Created by GUY on 2015/10/8.
* @class BI.IconTrigger * @class IconTrigger
* @extends BI.Trigger * @extends Trigger
*/ */
BI.IconTrigger = BI.inherit(BI.Trigger, { @shortcut()
export class IconTrigger extends Trigger {
static xtype = "bi.icon_trigger"
_defaultConfig: function () { _defaultConfig() {
return BI.extend(BI.IconTrigger.superclass._defaultConfig.apply(this, arguments), { return extend(super._defaultConfig(...arguments), {
baseCls: "bi-icon-trigger", baseCls: "bi-icon-trigger",
extraCls: "pull-down-font", extraCls: "pull-down-font",
el: {}, el: {},
height: 24 height: 24,
}); });
}, }
_init: function () {
var o = this.options; _init() {
BI.IconTrigger.superclass._init.apply(this, arguments); const o = this.options;
this.iconButton = BI.createWidget(o.el, { super._init(...arguments);
this.iconButton = createWidget(o.el, {
type: "bi.trigger_icon_button", type: "bi.trigger_icon_button",
element: this, element: this,
width: o.width, width: o.width,
height: o.height, height: o.height,
extraCls: o.extraCls extraCls: o.extraCls,
}); });
} }
}); }
BI.shortcut("bi.icon_trigger", BI.IconTrigger);

84
src/case/trigger/trigger.icon.text.js

@ -1,29 +1,35 @@
import { shortcut, extend, isKey, createWidget, isEmptyString } from "@/core";
import { Trigger } from "@/base";
/** /**
* 文字trigger * 文字trigger
* *
* Created by GUY on 2015/9/15. * Created by GUY on 2015/9/15.
* @class BI.IconTextTrigger * @class IconTextTrigger
* @extends BI.Trigger * @extends Trigger
*/ */
BI.IconTextTrigger = BI.inherit(BI.Trigger, { @shortcut()
export class IconTextTrigger extends Trigger {
static xtype = "bi.icon_text_trigger"
_defaultConfig() {
const conf = super._defaultConfig(...arguments);
_defaultConfig: function () { return extend(conf, {
var conf = BI.IconTextTrigger.superclass._defaultConfig.apply(this, arguments); baseCls: `${conf.baseCls || ""} bi-text-trigger`,
return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-text-trigger",
height: 24, height: 24,
iconHeight: null, iconHeight: null,
iconWidth: null, iconWidth: null,
textCls: "" textCls: "",
}); });
}, }
_init: function () { _init() {
BI.IconTextTrigger.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const o = this.options;
this.text = BI.createWidget({ this.text = createWidget({
type: "bi.label", type: "bi.label",
cls: "select-text-label" + (BI.isKey(o.textCls) ? (" " + o.textCls) : ""), cls: `select-text-label${isKey(o.textCls) ? (` ${o.textCls}`) : ""}`,
textAlign: "left", textAlign: "left",
height: o.height, height: o.height,
hgap: o.textHgap, hgap: o.textHgap,
@ -32,19 +38,19 @@ BI.IconTextTrigger = BI.inherit(BI.Trigger, {
rgap: o.textRgap, rgap: o.textRgap,
tgap: o.textTgap, tgap: o.textTgap,
bgap: o.textBgap, bgap: o.textBgap,
text: o.text text: o.text,
}); });
this.trigerButton = BI.createWidget({ this.trigerButton = createWidget({
type: "bi.trigger_icon_button", type: "bi.trigger_icon_button",
width: o.triggerWidth || o.height width: o.triggerWidth || o.height,
}); });
BI.createWidget({ createWidget({
element: this, element: this,
type: "bi.horizontal_fill", type: "bi.horizontal_fill",
columnSize: ["", "fill", ""], columnSize: ["", "fill", ""],
ref: function (_ref) { ref: _ref => {
self.wrapper = _ref; this.wrapper = _ref;
}, },
items: [{ items: [{
el: { el: {
@ -53,41 +59,39 @@ BI.IconTextTrigger = BI.inherit(BI.Trigger, {
width: o.triggerWidth || o.height, width: o.triggerWidth || o.height,
iconCls: o.iconCls, iconCls: o.iconCls,
invisible: !o.iconCls, invisible: !o.iconCls,
ref: function (_ref) { ref: _ref => {
self.icon = _ref; this.icon = _ref;
}, },
iconHeight: o.iconHeight, iconHeight: o.iconHeight,
iconWidth: o.iconWidth, iconWidth: o.iconWidth,
disableSelected: true disableSelected: true,
} },
}, { }, {
el: this.text, 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); this.text.setValue(value);
}, }
setIcon: function (iconCls) { setIcon(iconCls) {
var o = this.options;
this.icon.setIcon(iconCls); this.icon.setIcon(iconCls);
this.icon.setVisible(!!iconCls); this.icon.setVisible(!!iconCls);
}, }
setTextCls: function (cls) { setTextCls(cls) {
var o = this.options; const o = this.options;
var oldCls = o.textCls; const oldCls = o.textCls;
o.textCls = cls; o.textCls = cls;
this.text.element.removeClass(oldCls).addClass(cls); this.text.element.removeClass(oldCls).addClass(cls);
}, }
setText: function (text) { setText(text) {
this.text.setText(text); this.text.setText(text);
} }
}); }
BI.shortcut("bi.icon_text_trigger", BI.IconTextTrigger);

67
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. * 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 () { _defaultConfig() {
return BI.extend(BI.SelectIconTextTrigger.superclass._defaultConfig.apply(this, arguments), { return extend(super._defaultConfig(...arguments), {
baseCls: "bi-select-text-trigger", baseCls: "bi-select-text-trigger",
height: 24, height: 24,
iconHeight: null, iconHeight: null,
iconWidth: null, iconWidth: null,
iconCls: "" iconCls: "",
}); });
}, }
_init: function () { _init() {
BI.SelectIconTextTrigger.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const o = this.options;
var obj = this._digist(o.value, o.items); const obj = this._digist(o.value, o.items);
this.trigger = BI.createWidget({ this.trigger = createWidget({
type: "bi.icon_text_trigger", type: "bi.icon_text_trigger",
element: this, element: this,
text: obj.text, text: obj.text,
@ -32,49 +37,49 @@ BI.SelectIconTextTrigger = BI.inherit(BI.Trigger, {
height: o.height, height: o.height,
iconHeight: o.iconHeight, iconHeight: o.iconHeight,
iconWidth: o.iconWidth, iconWidth: o.iconWidth,
iconWrapperWidth: o.iconWrapperWidth iconWrapperWidth: o.iconWrapperWidth,
}); });
}, }
_digist: function (vals, items) { _digist(vals, items) {
var o = this.options; const o = this.options;
vals = BI.isArray(vals) ? vals : [vals]; vals = isArray(vals) ? vals : [vals];
var result; let result;
var formatItems = BI.Tree.transformToArrayFormat(items); const formatItems = Tree.transformToArrayFormat(items);
BI.any(formatItems, function (i, item) { any(formatItems, (i, item) => {
if (BI.deepContains(vals, item.value)) { if (deepContains(vals, item.value)) {
result = { result = {
text: item.text || item.value, text: item.text || item.value,
iconCls: item.iconCls iconCls: item.iconCls,
}; };
return true; return true;
} }
}); });
if (BI.isNotNull(result)) { if (isNotNull(result)) {
return { return {
text: result.text, text: result.text,
textCls: "", textCls: "",
iconCls: result.iconCls iconCls: result.iconCls,
}; };
} else { } else {
return { return {
text: BI.isFunction(o.text) ? o.text() : o.text, text: isFunction(o.text) ? o.text() : o.text,
textCls: "bi-water-mark", textCls: "bi-water-mark",
iconCls: o.iconCls iconCls: o.iconCls,
}; };
} }
}, }
setValue: function (vals) { setValue(vals) {
var obj = this._digist(vals, this.options.items); const obj = this._digist(vals, this.options.items);
this.trigger.setText(obj.text); this.trigger.setText(obj.text);
this.trigger.setIcon(obj.iconCls); this.trigger.setIcon(obj.iconCls);
this.trigger.setTextCls(obj.textCls); this.trigger.setTextCls(obj.textCls);
}, }
populate: function (items) { populate(items) {
this.options.items = items; this.options.items = items;
} }
}); }
BI.shortcut("bi.select_icon_text_trigger", BI.SelectIconTextTrigger);

159
src/case/trigger/trigger.text.js

@ -1,41 +1,45 @@
import { shortcut, isFunction, isKey, isNotEmptyString } from "@/core";
import { Trigger } from "@/base";
/** /**
* 文字trigger * 文字trigger
* *
* Created by GUY on 2015/9/15. * Created by GUY on 2015/9/15.
* @class BI.TextTrigger * @class TextTrigger
* @extends BI.Trigger * @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 () { props() {
var self = this;
return { return {
baseCls: "bi-text-trigger", baseCls: "bi-text-trigger",
height: 24, height: 24,
textHgap: 6, textHgap: 6,
textCls: "", textCls: "",
allowClear: false, allowClear: false,
title: function () { title: () => this.text.getText(),
return self.text.getText();
},
defaultText: "", defaultText: "",
text: "", text: "",
}; };
}, }
render: function () { render() {
var self = this, o = this.options, c = this._const; 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", type: "bi.label",
ref: function (_ref) { ref: _ref => {
self.text = _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", textAlign: "left",
height: o.height, height: o.height,
text: text || o.defaultText, text: text || o.defaultText,
@ -47,98 +51,93 @@ BI.TextTrigger = BI.inherit(BI.Trigger, {
rgap: o.textRgap, rgap: o.textRgap,
tgap: o.textTgap, tgap: o.textTgap,
bgap: o.textBgap, bgap: o.textBgap,
readonly: o.readonly readonly: o.readonly,
}; };
var triggerButton = { const triggerButton = {
type: "bi.trigger_icon_button", type: "bi.trigger_icon_button",
ref: function (_ref) { ref: _ref => {
self.triggerButton = _ref; this.triggerButton = _ref;
}, },
width: o.triggerWidth || o.height width: o.triggerWidth || o.height,
}; };
return ({ return ({
type: "bi.horizontal_fill", type: "bi.horizontal_fill",
columnSize: ["fill", ""], columnSize: ["fill", ""],
items: [ items: [{
{ el: label,
el: label, width: "fill",
width: "fill" }, {
}, { el: o.allowClear ? {
el: o.allowClear ? { type: "bi.vertical_adapt",
type: "bi.vertical_adapt", width: o.triggerWidth || o.height,
width: o.triggerWidth || o.height, height: o.height,
height: o.height, horizontalAlign: "left",
horizontalAlign: "left", scrollable: false,
scrollable: false, items: [{
items: [ el: {
{ type: "bi.icon_button",
el: { ref: _ref => {
type: "bi.icon_button", this.clearBtn = _ref;
ref: function (_ref) { },
self.clearBtn = _ref; cls: `close-h-font ${o.allowClear ? "clear-button" : ""}`,
}, stopPropagation: true,
cls: "close-h-font " + (o.allowClear ? "clear-button" : ""), width: o.triggerWidth || o.height,
stopPropagation: true, invisible: !isNotEmptyString(o.text),
width: o.triggerWidth || o.height, handler: () => {
invisible: !BI.isNotEmptyString(o.text), this.fireEvent(TextTrigger.EVENT_CLEAR);
handler: function () { },
self.fireEvent(BI.TextTrigger.EVENT_CLEAR); },
}, }, {
}, el: triggerButton,
}, { }],
el: triggerButton, } : triggerButton,
} }],
]
} : triggerButton,
}
]
}); });
}, }
getText() {
const o = this.options;
getText: function () { return isFunction(o.text) ? o.text() : o.text;
var o = this.options; }
return BI.isFunction(o.text) ? o.text() : o.text;
},
getDefaultText: function () { getDefaultText() {
var o = this.options; const o = this.options;
return BI.isFunction(o.defaultText) ? o.defaultText() : o.defaultText;
},
getTextor: function () { return isFunction(o.defaultText) ? o.defaultText() : o.defaultText;
}
getTextor() {
return this.text; return this.text;
}, }
setTextCls: function (cls) { setTextCls(cls) {
var o = this.options; const o = this.options;
var oldCls = o.textCls; const oldCls = o.textCls;
o.textCls = cls; o.textCls = cls;
this.text.element.removeClass(oldCls).addClass(cls); this.text.element.removeClass(oldCls).addClass(cls);
}, }
setText: function (text) { setText(text) {
if (this.options.allowClear) { 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.setText(text);
this.text.element.removeClass("bi-tips"); 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.setText(this.options.defaultText);
this.text.element.addClass("bi-tips"); this.text.element.addClass("bi-tips");
} else { } else {
this.text.setText(""); this.text.setText("");
this.text.element.removeClass("bi-tips"); this.text.element.removeClass("bi-tips");
} }
}, }
setTipType: function (v) { setTipType(v) {
this.text.options.tipType = v; this.text.options.tipType = v;
this.options.tipType = v; this.options.tipType = v;
} }
}); }
BI.TextTrigger.EVENT_CLEAR = "EVENT_CLEAR";
BI.shortcut("bi.text_trigger", BI.TextTrigger);

102
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 * 选择字段trigger
* *
* Created by GUY on 2015/9/15. * Created by GUY on 2015/9/15.
* @class BI.SelectTextTrigger * @class SelectTextTrigger
* @extends BI.Trigger * @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 () { _defaultConfig() {
return BI.extend(BI.SelectTextTrigger.superclass._defaultConfig.apply(this, arguments), { return extend(super._defaultConfig(...arguments), {
baseCls: "bi-select-text-trigger", baseCls: "bi-select-text-trigger",
height: 24, height: 24,
allowClear: false, allowClear: false,
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
defaultText: "", defaultText: "",
}); });
}, }
_init: function () { _init() {
BI.SelectTextTrigger.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const o = this.options;
var text = this._digest(o.value, o.items); const text = this._digest(o.value, o.items);
this.trigger = BI.createWidget({ this.trigger = createWidget({
type: "bi.text_trigger", type: "bi.text_trigger",
element: this, element: this,
height: o.height, height: o.height,
readonly: o.readonly, readonly: o.readonly,
text: text, text,
defaultText: o.defaultText, defaultText: o.defaultText,
textHgap: o.textHgap, textHgap: o.textHgap,
textVgap: o.textVgap, textVgap: o.textVgap,
@ -37,71 +45,67 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
tipType: o.tipType, tipType: o.tipType,
title: null, title: null,
allowClear: o.allowClear, allowClear: o.allowClear,
listeners: [ listeners: [{
{ eventName: TextTrigger.EVENT_CLEAR,
eventName: BI.TextTrigger.EVENT_CLEAR, action: () => {
action: function () { this.setText("");
self.setText(""); this.fireEvent(SelectTextTrigger.EVENT_CLEAR);
self.fireEvent(BI.SelectTextTrigger.EVENT_CLEAR); },
} }],
}
]
}); });
}, }
_digest: function (val, items) { _digest(val, items) {
var o = this.options; const o = this.options;
val = BI.isArray(val) ? val.slice() : [val]; val = isArray(val) ? val.slice() : [val];
var result = []; const result = [];
// 提升valueFormatter的优先级 // 提升valueFormatter的优先级
if (o.valueFormatter !== BI.emptyFn && BI.isFunction(o.valueFormatter)) { if (o.valueFormatter !== emptyFn && isFunction(o.valueFormatter)) {
BI.each(val, function (index, v) { each(val, (index, v) => {
result.push(o.valueFormatter(v)); result.push(o.valueFormatter(v));
}); });
return result.join(","); return result.join(",");
} }
var formatItems = BI.Tree.transformToArrayFormat(items); const formatItems = Tree.transformToArrayFormat(items);
BI.each(formatItems, function (i, item) { each(formatItems, (i, item) => {
if (BI.contains(val, item.value) && !BI.contains(result, item.text || item.value)) { if (contains(val, item.value) && !contains(result, item.text || item.value)) {
result.push(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) { if (result.length > 0 && val.length === 0) {
return result.join(","); return result.join(",");
} else { } 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.options.text = text;
this.trigger.setText(text); this.trigger.setText(text);
}, }
setValue: function (val) { setValue(val) {
var formatText = this._digest(val, this.options.items); const formatText = this._digest(val, this.options.items);
this.trigger.setText(formatText); this.trigger.setText(formatText);
}, }
setTipType: function (v) { setTipType(v) {
this.options.tipType = v; this.options.tipType = v;
this.trigger.setTipType(v); this.trigger.setTipType(v);
}, }
getTextor: function () { getTextor() {
return this.trigger.getTextor(); return this.trigger.getTextor();
}, }
populate: function (items) { populate(items) {
this.options.items = items; this.options.items = items;
} }
}); }
BI.SelectTextTrigger.EVENT_CLEAR = "EVENT_CLEAR";
BI.shortcut("bi.select_text_trigger", BI.SelectTextTrigger);

66
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小一号的 * 选择字段trigger小一号的
* *
* @class BI.SmallSelectTextTrigger * @class SmallSelectTextTrigger
* @extends BI.Trigger * @extends Trigger
*/ */
BI.SmallSelectTextTrigger = BI.inherit(BI.Trigger, { @shortcut()
export class SmallSelectTextTrigger extends Trigger {
static xtype = "bi.small_select_text_trigger"
_defaultConfig: function () { _defaultConfig() {
return BI.extend(BI.SmallSelectTextTrigger.superclass._defaultConfig.apply(this, arguments), { return extend(super._defaultConfig(...arguments), {
baseCls: "bi-small-select-text-trigger bi-border", baseCls: "bi-small-select-text-trigger bi-border",
height: 20, height: 20,
}); });
}, }
_init: function () { _init() {
BI.SmallSelectTextTrigger.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const o = this.options;
var obj = this._digest(o.value, o.items); const obj = this._digest(o.value, o.items);
this.trigger = BI.createWidget({ this.trigger = createWidget({
type: "bi.small_text_trigger", type: "bi.small_text_trigger",
element: this, element: this,
height: BI.toPix(o.height, 2), height: toPix(o.height, 2),
text: obj.text, text: obj.text,
cls: obj.cls, cls: obj.cls,
textHgap: o.textHgap, textHgap: o.textHgap,
@ -30,15 +35,15 @@ BI.SmallSelectTextTrigger = BI.inherit(BI.Trigger, {
textTgap: o.textTgap, textTgap: o.textTgap,
textBgap: o.textBgap, textBgap: o.textBgap,
}); });
}, }
_digest: function(vals, items){ _digest(vals, items) {
var o = this.options; const o = this.options;
vals = BI.isArray(vals) ? vals : [vals]; vals = isArray(vals) ? vals : [vals];
var result = []; const result = [];
var formatItems = BI.Tree.transformToArrayFormat(items); const formatItems = Tree.transformToArrayFormat(items);
BI.each(formatItems, function (i, item) { each(formatItems, (i, item) => {
if (BI.deepContains(vals, item.value) && !BI.contains(result, item.text || item.value)) { if (deepContains(vals, item.value) && !contains(result, item.text || item.value)) {
result.push(item.text || item.value); result.push(item.text || item.value);
} }
}); });
@ -46,24 +51,23 @@ BI.SmallSelectTextTrigger = BI.inherit(BI.Trigger, {
if (result.length > 0) { if (result.length > 0) {
return { return {
cls: "", cls: "",
text: result.join(",") text: result.join(","),
} };
} else { } else {
return { return {
cls: "bi-water-mark", cls: "bi-water-mark",
text: o.text text: o.text,
} };
} }
}, }
setValue: function (vals) { setValue(vals) {
var formatValue = this._digest(vals, this.options.items); const formatValue = this._digest(vals, this.options.items);
this.trigger.element.removeClass("bi-water-mark").addClass(formatValue.cls); this.trigger.element.removeClass("bi-water-mark").addClass(formatValue.cls);
this.trigger.setText(formatValue.text); this.trigger.setText(formatValue.text);
}, }
populate: function (items) { populate(items) {
this.options.items = items; this.options.items = items;
} }
}); }
BI.shortcut("bi.small_select_text_trigger", BI.SmallSelectTextTrigger);

64
src/case/trigger/trigger.text.small.js

@ -1,23 +1,30 @@
import { shortcut, extend, createWidget } from "@/core";
import { Trigger } from "@/base";
/** /**
* 文字trigger(右边小三角小一号的) == * 文字trigger(右边小三角小一号的) ==
* *
* @class BI.SmallTextTrigger * @class SmallTextTrigger
* @extends BI.Trigger * @extends Trigger
*/ */
BI.SmallTextTrigger = BI.inherit(BI.Trigger, { @shortcut()
_defaultConfig: function () { export class SmallTextTrigger extends Trigger {
var conf = BI.SmallTextTrigger.superclass._defaultConfig.apply(this, arguments); static xtype = "bi.small_text_trigger"
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: 20, height: 20,
textHgap: 6, textHgap: 6,
}); });
}, }
_init: function () { _init() {
BI.SmallTextTrigger.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options, c = this._const; const o = this.options;
this.text = BI.createWidget({ this.text = createWidget({
type: "bi.label", type: "bi.label",
textAlign: "left", textAlign: "left",
height: o.height, height: o.height,
@ -29,32 +36,29 @@ BI.SmallTextTrigger = BI.inherit(BI.Trigger, {
tgap: o.textTgap, tgap: o.textTgap,
bgap: o.textBgap, bgap: o.textBgap,
}); });
this.trigerButton = BI.createWidget({ this.trigerButton = createWidget({
type: "bi.trigger_icon_button", type: "bi.trigger_icon_button",
width: o.triggerWidth || o.height width: o.triggerWidth || o.height,
}); });
BI.createWidget({ createWidget({
element: this, element: this,
type: "bi.horizontal_fill", type: "bi.horizontal_fill",
items: [ items: [{
{ el: this.text,
el: this.text, width: "fill",
width: "fill" }, {
}, { el: this.trigerButton,
el: this.trigerButton, width: "",
width: "" }],
}
]
}); });
}, }
setValue: function (value) { setValue(value) {
this.text.setValue(value); this.text.setValue(value);
}, }
setText: function (text) { setText(text) {
this.text.setText(text); this.text.setText(text);
} }
}); }
BI.shortcut("bi.small_text_trigger", BI.SmallTextTrigger);

Loading…
Cancel
Save