Browse Source

Pull request #3157: 无JIRA任务 增加toPix方法

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit '3157371f890cbb457e68174dd14c9639a0b8bc93':
  增加toPix方法
es6
guy-王川 2 years ago
parent
commit
debe91a7bc
  1. 16
      src/base/layer/layer.popup.js
  2. 14
      src/base/single/1.text.js
  3. 2
      src/base/single/button/buttons/button.icon.js
  4. 10
      src/base/single/button/buttons/button.js
  5. 14
      src/base/single/html/html.js
  6. 8
      src/base/single/label/abstract.label.js
  7. 2
      src/base/single/label/icon.label.js
  8. 4
      src/base/single/tip/tip.toast.js
  9. 2
      src/base/single/tip/tip.tooltip.js
  10. 2
      src/case/list/list.select.js
  11. 4
      src/case/tree/treeexpander/tree.expander.popup.js
  12. 4
      src/core/4.widget.js
  13. 19
      src/core/constant/var.js
  14. 10
      src/core/wrapper/layout.js
  15. 8
      src/core/wrapper/layout/layout.flow.js
  16. 8
      src/core/wrapper/layout/layout.inline.js
  17. 2
      src/widget/multilayerselecttree/multilayerselecttree.popup.js
  18. 2
      src/widget/multilayersingletree/multilayersingletree.popup.js
  19. 2
      src/widget/multiselect/multiselect.loader.nobar.js
  20. 2
      src/widget/singleselect/singleselect.list.js

16
src/base/layer/layer.popup.js

@ -60,8 +60,8 @@ BI.PopupView = BI.inherit(BI.Widget, {
}
this.element.css({
"z-index": BI.zIndex_popup,
"min-width": BI.isNumeric(o.minWidth) ? (BI.pixFormat(o.minWidth)) : o.minWidth,
"max-width": BI.isNumeric(o.maxWidth) ? (BI.pixFormat(o.maxWidth)) : o.maxWidth,
"min-width": BI.toPix(o.minWidth),
"max-width": BI.toPix(o.maxWidth),
}).bind({ click: fn });
this.element.bind("mousewheel", fn);
@ -135,11 +135,11 @@ BI.PopupView = BI.inherit(BI.Widget, {
var o = this.options;
this.button_group = BI.createWidget(o.el, { type: "bi.button_group", value: o.value });
this.button_group.element.css({
"min-height": BI.isNumeric(o.minHeight) ? (BI.pixFormat(o.minHeight)) : o.minHeight,
"padding-top": BI.pixFormat(o.innerVgap),
"padding-bottom": BI.pixFormat(o.innerVgap),
"padding-left": BI.pixFormat(o.innerHgap),
"padding-right": BI.pixFormat(o.innerHgap),
"min-height": BI.toPix(o.minHeight),
"padding-top": BI.toPix(o.innerVgap),
"padding-bottom": BI.toPix(o.innerVgap),
"padding-left": BI.toPix(o.innerHgap),
"padding-right": BI.toPix(o.innerHgap),
});
return this.button_group;
@ -411,7 +411,7 @@ BI.PopupView = BI.inherit(BI.Widget, {
toolHeight = ((this.tool && this.tool.attr("height")) || 24) * ((this.tool && this.tool.isVisible()) ? 1 : 0);
var resetHeight = h - tbHeight - tabHeight - toolHeight - 2 * this.options.innerVgap;
this.view.resetHeight ? this.view.resetHeight(resetHeight) :
this.view.element.css({ "max-height": BI.pixFormat(resetHeight) });
this.view.element.css({ "max-height": BI.toPix(resetHeight) });
},
setValue: function (selectedValues) {

14
src/base/single/1.text.js

@ -26,32 +26,32 @@
var self = this, o = this.options;
if (o.hgap + o.lgap > 0) {
this.element.css({
"padding-left": BI.pixFormat(o.hgap + o.lgap),
"padding-left": BI.toPix(o.hgap + o.lgap),
});
}
if (o.hgap + o.rgap > 0) {
this.element.css({
"padding-right": BI.pixFormat(o.hgap + o.rgap),
"padding-right": BI.toPix(o.hgap + o.rgap),
});
}
if (o.vgap + o.tgap > 0) {
this.element.css({
"padding-top": BI.pixFormat(o.vgap + o.tgap),
"padding-top": BI.toPix(o.vgap + o.tgap),
});
}
if (o.vgap + o.bgap > 0) {
this.element.css({
"padding-bottom": BI.pixFormat(o.vgap + o.bgap),
"padding-bottom": BI.toPix(o.vgap + o.bgap),
});
}
if (BI.isWidthOrHeight(o.height)) {
this.element.css({ lineHeight: BI.isNumber(o.height) ? BI.pixFormat(o.height) : o.height });
this.element.css({ lineHeight: BI.toPix(o.height) });
}
if (BI.isWidthOrHeight(o.lineHeight)) {
this.element.css({ lineHeight: BI.isNumber(o.lineHeight) ? BI.pixFormat(o.lineHeight) : o.lineHeight });
this.element.css({ lineHeight: BI.toPix(o.lineHeight) });
}
if (BI.isWidthOrHeight(o.maxWidth)) {
this.element.css({ maxWidth: BI.isNumber(o.maxWidth) ? BI.pixFormat(o.maxWidth) : o.maxWidth });
this.element.css({ maxWidth: BI.toPix(o.maxWidth) });
}
this.element.css({
textAlign: o.textAlign,

2
src/base/single/button/buttons/button.icon.js

@ -31,7 +31,7 @@ BI.IconButton = BI.inherit(BI.BasicButton, {
height: o.iconHeight,
});
if (BI.isNumber(o.height) && o.height > 0 && BI.isNull(o.iconWidth) && BI.isNull(o.iconHeight)) {
this.element.css("lineHeight", BI.pixFormat(o.height));
this.element.css("lineHeight", BI.toPix(o.height));
BI.createWidget({
type: "bi.default",
element: this,

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

@ -98,8 +98,8 @@
type: "bi.icon_label",
cls: o.loading ? loadingCls : (o.iconCls || o.icon),
width: this._const.iconWidth,
height: BI.pixFormat(lineHeight, hasBorder ? 2 : 0),
lineHeight: BI.pixFormat(lineHeight, hasBorder ? 2 : 0),
height: BI.toPix(lineHeight, hasBorder ? 2 : 0),
lineHeight: BI.toPix(lineHeight, hasBorder ? 2 : 0),
// 不设置,自定义按钮无法居中
iconWidth: o.iconWidth,
iconHeight: o.iconHeight,
@ -120,8 +120,8 @@
whiteSpace: o.whiteSpace,
textAlign: o.textAlign,
textWidth: textWidth,
textHeight: BI.pixFormat(textHeight, hasBorder ? 2 : 0),
height: BI.pixFormat(lineHeight, hasBorder ? 2 : 0),
textHeight: BI.toPix(textHeight, hasBorder ? 2 : 0),
height: BI.toPix(lineHeight, hasBorder ? 2 : 0),
value: o.value,
title: null,
});
@ -163,7 +163,7 @@
});
if (o.minWidth > 0) {
this.element.css({ "min-width": BI.pixFormat(o.minWidth) });
this.element.css({ "min-width": BI.toPix(o.minWidth) });
}
},

14
src/base/single/html/html.js

@ -25,35 +25,35 @@ BI.Html = BI.inherit(BI.Single, {
var self = this, o = this.options;
if (o.hgap + o.lgap > 0) {
this.element.css({
"padding-left": BI.pixFormat(o.hgap + o.lgap),
"padding-left": BI.toPix(o.hgap + o.lgap),
});
}
if (o.hgap + o.rgap > 0) {
this.element.css({
"padding-right": BI.pixFormat(o.hgap + o.rgap),
"padding-right": BI.toPix(o.hgap + o.rgap),
});
}
if (o.vgap + o.tgap > 0) {
this.element.css({
"padding-top": BI.pixFormat(o.vgap + o.tgap),
"padding-top": BI.toPix(o.vgap + o.tgap),
});
}
if (o.vgap + o.bgap > 0) {
this.element.css({
"padding-bottom": BI.pixFormat(o.vgap + o.bgap),
"padding-bottom": BI.toPix(o.vgap + o.bgap),
});
}
if (BI.isNumber(o.height)) {
this.element.css({ lineHeight: BI.pixFormat(o.height) });
this.element.css({ lineHeight: BI.toPix(o.height) });
}
if (BI.isNumber(o.lineHeight)) {
this.element.css({ lineHeight: BI.pixFormat(o.lineHeight) });
this.element.css({ lineHeight: BI.toPix(o.lineHeight) });
}
if (BI.isWidthOrHeight(o.maxWidth)) {
this.element.css({ maxWidth: o.maxWidth });
}
if (BI.isNumber(o.maxWidth)) {
this.element.css({ maxWidth: BI.pixFormat(o.maxWidth) })
this.element.css({ maxWidth: BI.toPix(o.maxWidth) })
}
this.element.css({
textAlign: o.textAlign,

8
src/base/single/label/abstract.label.js

@ -109,7 +109,7 @@
}
if (BI.isNumber(o.height) && o.height > 0) { // 1.4
this.element.css({
"line-height": BI.pixFormat(o.height),
"line-height": BI.toPix(o.height),
});
json.textAlign = o.textAlign;
delete json.maxWidth;
@ -183,7 +183,7 @@
}
if (BI.isNumber(o.height) && o.height > 0) { // 1.8
this.element.css({
"line-height": BI.pixFormat(o.height),
"line-height": BI.toPix(o.height),
});
json.textAlign = o.textAlign;
delete json.maxWidth;
@ -263,7 +263,7 @@
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)),
"line-height": BI.toPix(o.height - (o.vgap * 2)),
});
}
delete json.maxWidth;
@ -325,7 +325,7 @@
if (BI.isNumber(o.height) && o.height > 0) {
if (o.whiteSpace !== "normal") {
this.element.css({
"line-height": BI.pixFormat(o.height - (o.vgap * 2)),
"line-height": BI.toPix(o.height - (o.vgap * 2)),
});
}
delete json.maxWidth;

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

@ -29,7 +29,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", BI.pixFormat(o.lineHeight || o.height));
this.element.css("lineHeight", BI.toPix(o.lineHeight || o.height));
BI.createWidget({
type: "bi.default",
element: this,

4
src/base/single/tip/tip.toast.js

@ -31,8 +31,8 @@ BI.Toast = BI.inherit(BI.Tip, {
var self = this, o = this.options, c = this._const;
this.element.css({
// 这里直接使用px即可
minWidth: BI.pixFormat(o.closable ? c.closableMinWidth : c.minWidth),
maxWidth: BI.pixFormat(o.closable ? c.closableMaxWidth : c.maxWidth),
minWidth: BI.toPix(o.closable ? c.closableMinWidth : c.minWidth),
maxWidth: BI.toPix(o.closable ? c.closableMaxWidth : c.maxWidth),
});
this.element.addClass("toast-" + o.level);
function fn(e) {

2
src/base/single/tip/tip.tooltip.js

@ -73,7 +73,7 @@ BI.Tooltip = BI.inherit(BI.Tip, {
},
setWidth: function (width) {
this.element.width(BI.pixFormat(width - 2 * this._const.hgap));
this.element.width(BI.toPix(width - 2 * this._const.hgap));
},
setText: function (text) {

2
src/case/list/list.select.js

@ -192,7 +192,7 @@ BI.SelectList = BI.inherit(BI.Widget, {
resetHeight: function (h) {
var toolHeight = ( this.toolbar.element.outerHeight() || 25) * ( this.toolbar.isVisible() ? 1 : 0);
this.list.resetHeight ? this.list.resetHeight(h - toolHeight) :
this.list.element.css({"max-height": BI.pixFormat(h - toolHeight)});
this.list.element.css({"max-height": BI.toPix(h - toolHeight)});
},
setNotSelectedValue: function () {

4
src/case/tree/treeexpander/tree.expander.popup.js

@ -25,8 +25,8 @@
});
if (o.showLine) {
this.popupView.element.css("margin-left", BI.pixFormat(-offset * (o.layer + 1)));
this.element.css("margin-left", BI.pixFormat(offset * (o.layer + 1)));
this.popupView.element.css("margin-left", BI.toPix(-offset * (o.layer + 1)));
this.element.css("margin-left", BI.toPix(offset * (o.layer + 1)));
}
return {

4
src/core/4.widget.js

@ -289,14 +289,14 @@
_initElementWidth: function () {
var o = this.options;
if (BI.isWidthOrHeight(o.width)) {
this.element.css("width", BI.isNumber(o.width) ? BI.pixFormat(o.width) : o.width);
this.element.css("width", BI.toPix(o.width));
}
},
_initElementHeight: function () {
var o = this.options;
if (BI.isWidthOrHeight(o.height)) {
this.element.css("height", BI.isNumber(o.height) ? BI.pixFormat(o.height) : o.height);
this.element.css("height", BI.toPix(o.height));
}
},

19
src/core/constant/var.js

@ -15,12 +15,13 @@ BI._.extend(BI, {
emptyStr: "",
pixUnit: "px",
pixRatio: 1,
pixFormat: function (pix, border) {
// 一定返回最终的单位
toPix: function (pix, border) {
if (!BI.isNumber(pix)) {
return pix;
}
if (BI.pixUnit === "px" && BI.pixRatio === 1) {
return (pix - (border || 0)) / BI.pixRatio + BI.pixUnit;
if (BI.pixUnit === "px") {
return (pix / BI.pixRatio - (border || 0)) + BI.pixUnit;
}
var length = pix / BI.pixRatio + BI.pixUnit;
if (border > 0) {
@ -28,6 +29,18 @@ BI._.extend(BI, {
}
return length;
},
pixFormat: function (pix, border) {
if (!BI.isNumber(pix)) {
return pix;
}
if (BI.pixUnit === "px") {
return pix - (border || 0) * BI.pixRatio;
}
if (border > 0) {
return `calc(${pix / BI.pixRatio + BI.pixUnit} - ${border + "px"})`;
}
return pix;
},
emptyFn: function () {
},
empty: null,

10
src/core/wrapper/layout.js

@ -42,16 +42,16 @@ BI.Layout = BI.inherit(BI.Widget, {
_init4Margin: function () {
if (this.options.top) {
this.element.css("top", BI.isNumber(this.options.top) ? BI.pixFormat(this.options.top) : this.options.top);
this.element.css("top", BI.toPix(this.options.top));
}
if (this.options.left) {
this.element.css("left", BI.isNumber(this.options.left) ? BI.pixFormat(this.options.left) : this.options.left);
this.element.css("left", BI.toPix(this.options.left));
}
if (this.options.bottom) {
this.element.css("bottom", BI.isNumber(this.options.bottom) ? BI.pixFormat(this.options.bottom) : this.options.bottom);
this.element.css("bottom", BI.toPix(this.options.bottom));
}
if (this.options.right) {
this.element.css("right", BI.isNumber(this.options.right) ? BI.pixFormat(this.options.right) : this.options.right);
this.element.css("right", BI.toPix(this.options.right));
}
},
@ -289,7 +289,7 @@ BI.Layout = BI.inherit(BI.Widget, {
},
_optimiseGap: function (gap) {
return (gap > 0 && gap < 1) ? (gap * 100).toFixed(1) + "%" : BI.pixFormat(gap);
return (gap > 0 && gap < 1) ? (gap * 100).toFixed(1) + "%" : BI.toPix(gap);
},
_optimiseItemLgap: function (item) {

8
src/core/wrapper/layout/layout.flow.js

@ -137,16 +137,16 @@ BI.FloatRightLayout = BI.inherit(BI.Layout, {
var w = BI.FloatRightLayout.superclass._addElement.apply(this, arguments);
w.element.css({position: "relative", float: "right"});
if (BI.isNotNull(item.left)) {
w.element.css({left: BI.isNumber(item.left) ? BI.pixFormat(item.left) : item.left});
w.element.css({left: BI.toPix(item.left)});
}
if (BI.isNotNull(item.right)) {
w.element.css({right: BI.isNumber(item.right) ? BI.pixFormat(item.right) : item.right});
w.element.css({right: BI.toPix(item.right)});
}
if (BI.isNotNull(item.top)) {
w.element.css({top: BI.isNumber(item.top) ? BI.pixFormat(item.top) : item.top});
w.element.css({top: BI.toPix(item.top)});
}
if (BI.isNotNull(item.bottom)) {
w.element.css({bottom: BI.isNumber(item.bottom) ? BI.pixFormat(item.bottom) : item.bottom});
w.element.css({bottom: BI.toPix(item.bottom)});
}
if (o.vgap + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item) !== 0) {
var top = o.vgap / 2 + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item);

8
src/core/wrapper/layout/layout.inline.js

@ -47,7 +47,7 @@ BI.InlineLayout = BI.inherit(BI.Layout, {
}
}
if (columnSize > 0) {
w.element.width(columnSize < 1 ? ((columnSize * 100).toFixed(1) + "%") : BI.pixFormat(columnSize));
w.element.width(columnSize < 1 ? ((columnSize * 100).toFixed(1) + "%") : BI.toPix(columnSize));
}
w.element.css({
position: "relative",
@ -69,8 +69,8 @@ BI.InlineLayout = BI.inherit(BI.Layout, {
gap += o.hgap + o.lgap + o.rgap + this._optimiseItemLgap(o.items[k]) + this._optimiseItemRgap(o.items[k]) + this._optimiseItemHgap(o.items[k]);
length += cz;
}
length = length > 0 && length < 1 ? (length * 100).toFixed(1) + "%" : BI.pixFormat(length);
gap = gap > 0 && gap < 1 ? (gap * 100).toFixed(1) + "%" : BI.pixFormat(gap);
length = length > 0 && length < 1 ? (length * 100).toFixed(1) + "%" : BI.toPix(length);
gap = gap > 0 && gap < 1 ? (gap * 100).toFixed(1) + "%" : BI.toPix(gap);
if (columnSize === "fill") {
w.element.css("min-width", "calc((100% - " + length + " - " + gap + ")" + (fillCount > 1 ? "/" + fillCount : "") + ")");
}
@ -86,7 +86,7 @@ BI.InlineLayout = BI.inherit(BI.Layout, {
if (o.verticalAlign === BI.VerticalAlign.Stretch && BI.isNull(item.height)) {
var top = o.innerVgap + o.vgap + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item),
bottom = o.innerVgap + o.vgap + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item);
var gap = (top + bottom) > 0 && (top + bottom) < 1 ? ((top + bottom) * 100).toFixed(1) + "%" : BI.pixFormat(top + bottom);
var gap = (top + bottom) > 0 && (top + bottom) < 1 ? ((top + bottom) * 100).toFixed(1) + "%" : BI.toPix(top + bottom);
w.element.css("height", "calc(100% - " + gap + ")");
}
return w;

2
src/widget/multilayerselecttree/multilayerselecttree.popup.js

@ -56,7 +56,7 @@ BI.MultiLayerSelectTreePopup = BI.inherit(BI.Widget, {
self.fireEvent(BI.MultiLayerSelectTreePopup.EVENT_CHANGE);
});
this.tree.css("min-height", BI.pixFormat(o.minHeight - 10));
this.tree.css("min-height", BI.toPix(o.minHeight - 10));
},
getValue: function () {

2
src/widget/multilayersingletree/multilayersingletree.popup.js

@ -55,7 +55,7 @@ BI.MultiLayerSingleTreePopup = BI.inherit(BI.Widget, {
self.fireEvent(BI.MultiLayerSingleTreePopup.EVENT_CHANGE);
});
this.tree.css("min-height", BI.pixFormat(o.minHeight - 10));
this.tree.css("min-height", BI.toPix(o.minHeight - 10));
},
getValue: function () {

2
src/widget/multiselect/multiselect.loader.nobar.js

@ -173,7 +173,7 @@ BI.MultiSelectNoBarLoader = BI.inherit(BI.Widget, {
},
resetHeight: function (h) {
this.button_group.element.css({ "max-height": BI.pixFormat(h) });
this.button_group.element.css({ "max-height": BI.toPix(h) });
},
resetWidth: function () {

2
src/widget/singleselect/singleselect.list.js

@ -120,7 +120,7 @@ BI.SingleSelectList = BI.inherit(BI.Widget, {
resetHeight: function (h) {
this.list.resetHeight ? this.list.resetHeight(h) :
this.list.element.css({"max-height": BI.pixFormat(h - (this.options.allowNoSelect ? this._constants.itemHeight : 0))});
this.list.element.css({"max-height": BI.toPix(h - (this.options.allowNoSelect ? this._constants.itemHeight : 0))});
},
setNotSelectedValue: function () {

Loading…
Cancel
Save