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.

400 lines
14 KiB

/**
* Created by dailer on 2019/6/19.
*/
5 years ago
!(function () {
BI.AbstractLabel = BI.inherit(BI.Single, {
5 years ago
_defaultConfig: function (props) {
var conf = BI.AbstractLabel.superclass._defaultConfig.apply(this, arguments);
5 years ago
return BI.extend(conf, {
textAlign: "center",
whiteSpace: "nowrap", // normal or nowrap
textWidth: null,
textHeight: null,
hgap: 0,
vgap: 0,
lgap: 0,
rgap: 0,
tgap: 0,
bgap: 0,
highLight: false,
handler: null,
enableHover: props.title !== null,
5 years ago
});
},
5 years ago
_createJson: function () {
var o = this.options;
5 years ago
return {
type: "bi.text",
textAlign: o.textAlign,
5 years ago
whiteSpace: o.whiteSpace,
lineHeight: o.textHeight,
maxWidth: "100%",
5 years ago
text: o.text,
value: o.value,
py: o.py,
keyword: o.keyword,
highLight: o.highLight,
handler: o.handler,
5 years ago
};
},
render: function () {
5 years ago
if (this.options.textAlign === "center") {
this._createCenterEl();
} else {
this._createNotCenterEl();
}
},
5 years ago
_createCenterEl: function () {
var o = this.options;
var json = this._createJson();
json.textAlign = "left";
5 years ago
if (BI.isNumber(o.width) && o.width > 0) {
if (BI.isNumber(o.textWidth) && o.textWidth > 0) {
json.maxWidth = o.textWidth;
if (BI.isNumber(o.height) && o.height > 0) { // 1.1
BI.createWidget({
type: "bi.center_adapt",
height: o.height,
4 years ago
columnSize: ["auto"], // important! 让文字在flex布局下shrink为1
5 years ago
scrollable: o.whiteSpace === "normal",
element: this,
items: [
{
el: (this.text = BI.createWidget(json)),
5 years ago
}
],
5 years ago
});
5 years ago
return;
}
BI.createWidget({ // 1.2
type: "bi.center_adapt",
4 years ago
columnSize: ["auto"], // important! 让文字在flex布局下shrink为1
scrollable: o.whiteSpace === "normal",
element: this,
items: [
{
el: (this.text = BI.createWidget(json)),
}
],
});
return;
}
4 years ago
if (o.whiteSpace === "normal") { // 1.3
5 years ago
BI.extend(json, {
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
5 years ago
});
this.text = BI.createWidget(json);
BI.createWidget({
type: "bi.center_adapt",
4 years ago
columnSize: ["auto"], // important! 让文字在flex布局下shrink为1
5 years ago
scrollable: o.whiteSpace === "normal",
element: this,
items: [this.text],
5 years ago
});
5 years ago
return;
}
if (BI.isNumber(o.height) && o.height > 0) { // 1.4
this.element.css({
"line-height": BI.pixFormat(o.height),
5 years ago
});
json.textAlign = o.textAlign;
delete json.maxWidth;
5 years ago
this.text = BI.createWidget(BI.extend(json, {
element: this,
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
5 years ago
}));
5 years ago
return;
}
BI.extend(json, { // 1.5
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
maxWidth: "100%",
5 years ago
});
this.text = BI.createWidget(json);
BI.createWidget({
type: "bi.center_adapt",
4 years ago
columnSize: ["auto"], // important! 让文字在flex布局下shrink为1
5 years ago
scrollable: o.whiteSpace === "normal",
element: this,
items: [this.text],
5 years ago
});
5 years ago
return;
}
if (BI.isNumber(o.textWidth) && o.textWidth > 0) { // 1.6
5 years ago
json.maxWidth = o.textWidth;
BI.createWidget({
type: "bi.center_adapt",
4 years ago
columnSize: ["auto"], // important! 让文字在flex布局下shrink为1
scrollable: o.whiteSpace === "normal",
element: this,
items: [
{
el: (this.text = BI.createWidget(json)),
}
],
});
return;
}
4 years ago
if (o.whiteSpace === "normal") { // 1.7
BI.extend(json, {
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
});
this.text = BI.createWidget(json);
BI.createWidget({
type: "bi.center_adapt",
4 years ago
columnSize: ["auto"], // important! 让文字在flex布局下shrink为1
5 years ago
scrollable: true,
element: this,
items: [this.text],
});
return;
}
5 years ago
if (BI.isNumber(o.height) && o.height > 0) { // 1.8
this.element.css({
"line-height": BI.pixFormat(o.height),
});
json.textAlign = o.textAlign;
delete json.maxWidth;
this.text = BI.createWidget(BI.extend(json, {
element: this,
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
}));
return;
}
this.text = BI.createWidget(BI.extend(json, {
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
5 years ago
}));
BI.createWidget({
type: "bi.center_adapt",
4 years ago
columnSize: ["auto"], // important! 让文字在flex布局下shrink为1
element: this,
items: [this.text],
});
5 years ago
},
5 years ago
_createNotCenterEl: function () {
var o = this.options;
var adaptLayout = "bi.vertical_adapt";
var json = this._createJson();
if (BI.isNumber(o.width) && o.width > 0) {
if (BI.isNumber(o.textWidth) && o.textWidth > 0) {
json.maxWidth = o.textWidth;
5 years ago
if (BI.isNumber(o.height) && o.height > 0) { // 2.1
BI.createWidget({
type: adaptLayout,
horizontalAlign: o.textAlign,
4 years ago
columnSize: ["auto"], // important! 让文字在flex布局下shrink为1
5 years ago
height: o.height,
scrollable: o.whiteSpace === "normal",
element: this,
items: [
{
el: (this.text = BI.createWidget(json)),
5 years ago
}
],
5 years ago
});
5 years ago
return;
}
BI.createWidget({ // 2.2
type: adaptLayout,
5 years ago
horizontalAlign: o.textAlign,
4 years ago
columnSize: ["auto"], // important! 让文字在flex布局下shrink为1
scrollable: o.whiteSpace === "normal",
5 years ago
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
element: this,
items: [
{
el: (this.text = BI.createWidget(json)),
}
],
});
return;
}
5 years ago
if (BI.isNumber(o.height) && o.height > 0) { // 2.3
if (o.whiteSpace !== "normal") {
this.element.css({
"line-height": BI.pixFormat(o.height - (o.vgap * 2)),
});
}
delete json.maxWidth;
5 years ago
this.text = BI.createWidget(BI.extend(json, {
element: this,
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
5 years ago
}));
5 years ago
return;
}
json.maxWidth = o.width - 2 * o.hgap - o.lgap - o.rgap;
5 years ago
BI.createWidget({ // 2.4
type: adaptLayout,
horizontalAlign: o.textAlign,
4 years ago
columnSize: ["auto"], // important! 让文字在flex布局下shrink为1
5 years ago
scrollable: o.whiteSpace === "normal",
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
element: this,
items: [{
el: (this.text = BI.createWidget(json)),
}],
5 years ago
});
5 years ago
return;
}
if (BI.isNumber(o.textWidth) && o.textWidth > 0) {
json.maxWidth = o.textWidth;
BI.createWidget({ // 2.5
type: adaptLayout,
5 years ago
horizontalAlign: o.textAlign,
4 years ago
columnSize: ["auto"], // important! 让文字在flex布局下shrink为1
scrollable: o.whiteSpace === "normal",
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
element: this,
items: [
{
el: (this.text = BI.createWidget(json)),
}
],
});
return;
}
5 years ago
if (BI.isNumber(o.height) && o.height > 0) {
if (o.whiteSpace !== "normal") {
this.element.css({
"line-height": BI.pixFormat(o.height - (o.vgap * 2)),
5 years ago
});
}
delete json.maxWidth;
5 years ago
this.text = BI.createWidget(BI.extend(json, { // 2.6
element: this,
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
}));
return;
}
this.text = BI.createWidget(BI.extend(json, {
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
5 years ago
}));
BI.createWidget({
type: adaptLayout,
5 years ago
horizontalAlign: o.textAlign,
4 years ago
columnSize: ["auto"], // important! 让文字在flex布局下shrink为1
element: this,
5 years ago
scrollable: o.whiteSpace === "normal",
items: [this.text],
});
5 years ago
},
5 years ago
doRedMark: function () {
this.text.doRedMark.apply(this.text, arguments);
},
5 years ago
unRedMark: function () {
this.text.unRedMark.apply(this.text, arguments);
},
5 years ago
doHighLight: function () {
this.text.doHighLight.apply(this.text, arguments);
},
5 years ago
unHighLight: function () {
this.text.unHighLight.apply(this.text, arguments);
},
5 years ago
setText: function (v) {
this.options.text = v;
this.text.setText(v);
},
5 years ago
getText: function () {
return this.options.text;
},
5 years ago
setStyle: function (css) {
this.text.setStyle(css);
},
5 years ago
setValue: function (v) {
BI.AbstractLabel.superclass.setValue.apply(this, arguments);
if (!this.isReadOnly()) {
this.options.text = v;
5 years ago
this.text.setValue(v);
}
},
5 years ago
});
}());