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.

80 lines
2.1 KiB

import { shortcut, Widget, extend, toPix, Controller, createWidget, createItems, makeArrayByArray } from "@/core";
import { ButtonGroup } from "@/base";
8 years ago
/**
* 单选按钮组
*
* Created by GUY on 2015/9/7.
* @class Segment
* @extends Widget
8 years ago
*/
@shortcut()
export class Segment extends Widget {
static xtype = "bi.segment"
static EVENT_CHANGE = "EVENT_CHANGE"
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
8 years ago
baseCls: "bi-segment",
items: [],
height: 24,
8 years ago
});
}
_init() {
super._init(...arguments);
const o = this.options;
this.buttonGroup = createWidget({
8 years ago
element: this,
8 years ago
type: "bi.button_group",
value: o.value,
items: [createItems(o.items, {
8 years ago
type: "bi.segment_button",
height: toPix(o.height, 2),
whiteSpace: o.whiteSpace,
})],
layouts: [{
type: "bi.table",
columnSize: makeArrayByArray(o.items, "fill"),
}],
7 years ago
});
this.buttonGroup.on(Controller.EVENT_CHANGE, (...args) => {
this.fireEvent(Controller.EVENT_CHANGE, ...args);
8 years ago
});
this.buttonGroup.on(ButtonGroup.EVENT_CHANGE, (value, obj) => {
this.fireEvent(Segment.EVENT_CHANGE, value, obj);
7 years ago
});
}
8 years ago
_setEnable(enable) {
super._setEnable(...arguments);
if (enable === true) {
this.element.removeClass("base-disabled disabled");
} else if (enable === false) {
this.element.addClass("base-disabled disabled");
}
}
setValue(v) {
8 years ago
this.buttonGroup.setValue(v);
}
8 years ago
setEnabledValue(v) {
8 years ago
this.buttonGroup.setEnabledValue(v);
}
8 years ago
getValue() {
8 years ago
return this.buttonGroup.getValue();
}
populate(buttons) {
const o = this.options;
this.buttonGroup.populate([createItems(buttons, {
type: "bi.segment_button",
height: toPix(o.height, 2),
whiteSpace: o.whiteSpace,
})]);
}
}