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",
"isNumber",
"isEmpty",
"isEmptyString",
"any",
"deepContains",
"isNotEmptyString",
"each",
"contains",
"remove",
];
target.forEach(t => {

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

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

3
src/case/index.js

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save