Browse Source

优化代码

es6
guy 3 years ago
parent
commit
8cb6a08f75
  1. 36
      src/base/single/button/buttons/button.js
  2. 5
      src/base/single/label/icon.label.js

36
src/base/single/button/buttons/button.js

@ -41,12 +41,28 @@ BI.Button = BI.inherit(BI.BasicButton, {
render: function () {
var o = this.options, self = this;
// 由于button默认情况下有个边框,所以要主动算行高
var lineHeight, textHeight = o.textHeight;
if (BI.isNumber(o.height)) {
if (o.clear || o.block) {
lineHeight = o.height;
} else {
lineHeight = o.height - 2;
}
}
if (!textHeight) {
if (o.whiteSpace === "nowrap") {
textHeight = lineHeight;
}
}
if (BI.isKey(o.iconCls)) {
this.icon = BI.createWidget({
type: "bi.icon_label",
cls: o.iconCls,
width: this._const.iconWidth,
height: o.height - 2,
height: o.height,
lineHeight: lineHeight,
iconWidth: o.iconWidth,
iconHeight: o.iconHeight
});
@ -54,9 +70,9 @@ BI.Button = BI.inherit(BI.BasicButton, {
type: "bi.label",
text: o.text,
textWidth: BI.isNotNull(o.textWidth) ? o.textWidth - this._const.iconWidth : null,
textHeight: o.textHeight,
value: o.value,
height: o.height - 2
textHeight: textHeight,
height: o.height,
value: o.value
});
BI.createWidget({
type: "bi.center_adapt",
@ -76,7 +92,7 @@ BI.Button = BI.inherit(BI.BasicButton, {
textAlign: o.textAlign,
whiteSpace: o.whiteSpace,
textWidth: o.textWidth,
textHeight: o.textHeight,
textHeight: textHeight,
hgap: o.hgap,
vgap: o.vgap,
tgap: o.tgap,
@ -88,16 +104,6 @@ BI.Button = BI.inherit(BI.BasicButton, {
value: o.value
});
}
if (BI.isNumber(o.height) && !o.clear && !o.block) {
this.element.css({
height: o.height / BI.pixRatio + BI.pixUnit,
lineHeight: (o.height - 2) / BI.pixRatio + BI.pixUnit
});
} else if (o.clear || o.block) {
this.element.css({lineHeight: o.height / BI.pixRatio + BI.pixUnit});
} else {
this.element.css({lineHeight: (o.height - 2) / BI.pixRatio + BI.pixUnit});
}
if (o.block === true) {
this.element.addClass("block");
}

5
src/base/single/label/icon.label.js

@ -8,7 +8,8 @@ BI.IconLabel = BI.inherit(BI.Single, {
props: {
baseCls: "bi-icon-label horizon-center",
iconWidth: null,
iconHeight: null
iconHeight: null,
lineHeight: null,
},
render: function () {
@ -22,7 +23,7 @@ BI.IconLabel = BI.inherit(BI.Single, {
height: o.iconHeight
});
if (BI.isNumber(o.height) && o.height > 0 && BI.isNull(o.iconWidth) && BI.isNull(o.iconHeight)) {
this.element.css("lineHeight", o.height / BI.pixRatio + BI.pixUnit);
this.element.css("lineHeight", (o.lineHeight || o.height) / BI.pixRatio + BI.pixUnit);
BI.createWidget({
type: "bi.default",
element: this,

Loading…
Cancel
Save