fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

86 lines
2.4 KiB

import { IconTextTrigger } from "./trigger.icon.text";
import { shortcut, extend, createWidget, isFunction, isArray, isNotNull, any, deepContains, Tree } from "@/core";
import { Trigger } from "@/base";
/**
* Created by Windy on 2017/12/12.
*/
@shortcut()
export class SelectIconTextTrigger extends Trigger {
static xtype = "bi.select_icon_text_trigger";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-select-text-trigger",
height: 24,
iconHeight: null,
iconWidth: null,
iconCls: "",
});
}
_init() {
super._init(...arguments);
const o = this.options;
const obj = this._digist(o.value, o.items);
this.trigger = createWidget({
type: IconTextTrigger.xtype,
element: this,
text: obj.text,
textCls: obj.textCls,
iconCls: obj.iconCls,
textHgap: o.textHgap,
textVgap: o.textVgap,
textLgap: o.textLgap,
textRgap: o.textRgap,
textTgap: o.textTgap,
textBgap: o.textBgap,
height: o.height,
iconHeight: o.iconHeight,
iconWidth: o.iconWidth,
iconWrapperWidth: o.iconWrapperWidth,
});
}
_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,
};
return true;
}
});
if (isNotNull(result)) {
return {
text: result.text,
textCls: "",
iconCls: result.iconCls,
};
} else {
return {
text: isFunction(o.text) ? o.text() : o.text,
textCls: "bi-water-mark",
iconCls: o.iconCls,
};
}
}
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(items) {
this.options.items = items;
}
}