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.

75 lines
2.1 KiB

import { SmallTextTrigger } from "./trigger.text.small";
import { shortcut, extend, toPix, createWidget, isArray, deepContains, each, contains, Tree } from "@/core";
import { Trigger } from "@/base";
8 years ago
/**
* 选择字段trigger小一号的
*
* @class SmallSelectTextTrigger
* @extends Trigger
8 years ago
*/
@shortcut()
export class SmallSelectTextTrigger extends Trigger {
static xtype = "bi.small_select_text_trigger";
8 years ago
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
8 years ago
baseCls: "bi-small-select-text-trigger bi-border",
3 years ago
height: 20,
8 years ago
});
}
8 years ago
_init() {
super._init(...arguments);
const o = this.options;
const obj = this._digest(o.value, o.items);
this.trigger = createWidget({
type: SmallTextTrigger.xtype,
8 years ago
element: this,
height: toPix(o.height, 2),
7 years ago
text: obj.text,
3 years ago
cls: obj.cls,
textHgap: o.textHgap,
textVgap: o.textVgap,
textLgap: o.textLgap,
textRgap: o.textRgap,
textTgap: o.textTgap,
textBgap: o.textBgap,
8 years ago
});
}
8 years ago
_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)) {
8 years ago
result.push(item.text || item.value);
}
});
if (result.length > 0) {
7 years ago
return {
cls: "",
text: result.join(","),
};
8 years ago
} else {
7 years ago
return {
cls: "bi-water-mark",
text: o.text,
};
8 years ago
}
}
8 years ago
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);
}
7 years ago
populate(items) {
8 years ago
this.options.items = items;
}
}