Browse Source

Pull request #2589: 无JIRA任务 bi.table支持grid布局

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

* commit '1243cb674660079287231f2a61679b406d492080':
  feature: 支持align
  bugfix
  bi.table支持grid布局
es6
guy 3 years ago
parent
commit
6167c880e2
  1. 15
      src/core/platform/web/config.js
  2. 129
      src/core/wrapper/layout/layout.table.js
  3. 2
      src/core/wrapper/layout/layout.td.js
  4. 3
      src/less/core/wrapper/table.less

15
src/core/platform/web/config.js

@ -5,13 +5,19 @@ BI.prepares.push(function () {
// 1、支持flex的浏览器下使用flex布局 // 1、支持flex的浏览器下使用flex布局
// 2、不支持flex的浏览器下使用inline布局 // 2、不支持flex的浏览器下使用inline布局
// 3、当列宽既需要自动列宽又需要自适应列宽时,inline布局也处理不了了。当横向出滚动条时使用table布局,不出滚动条时使用float布局 // 3、当列宽既需要自动列宽又需要自适应列宽时,inline布局也处理不了了。当横向出滚动条时使用table布局,不出滚动条时使用float布局
var _isSupportFlex; var _isSupportFlex, _isSupportGrid;
var isSupportFlex = function () { var isSupportFlex = function () {
if (_isSupportFlex == null) { if (_isSupportFlex == null) {
_isSupportFlex = !!(BI.isSupportCss3 && BI.isSupportCss3("flex")); _isSupportFlex = !!(BI.isSupportCss3 && BI.isSupportCss3("flex"));
} }
return _isSupportFlex; return _isSupportFlex;
}; };
var isSupportGrid = function () {
if (_isSupportGrid == null) {
_isSupportGrid = !!(BI.isSupportCss3 && BI.isSupportCss3("grid"));
}
return _isSupportGrid;
};
// 判断浏览器是否支持sticky 属性 // 判断浏览器是否支持sticky 属性
var isSupportSticky = (function () { var isSupportSticky = (function () {
var vendorList = ["", "-webkit-", "-ms-", "-moz-", "-o-"], var vendorList = ["", "-webkit-", "-ms-", "-moz-", "-o-"],
@ -224,6 +230,13 @@ BI.prepares.push(function () {
} }
}); });
BI.Plugin.configWidget("bi.table", function (ob) {
if (!isSupportGrid()) {
return BI.extend({}, ob, {type: "bi.td"});
}
return ob;
});
BI.Plugin.configWidget("bi.radio", function (ob) { BI.Plugin.configWidget("bi.radio", function (ob) {
if (BI.isIE() && BI.getIEVersion() <= 9) { if (BI.isIE() && BI.getIEVersion() <= 9) {
return BI.extend({}, ob, {type: "bi.image_radio"}); return BI.extend({}, ob, {type: "bi.image_radio"});

129
src/core/wrapper/layout/layout.table.js

@ -8,9 +8,12 @@ BI.TableLayout = BI.inherit(BI.Layout, {
props: function () { props: function () {
return BI.extend(BI.TableLayout.superclass.props.apply(this, arguments), { return BI.extend(BI.TableLayout.superclass.props.apply(this, arguments), {
baseCls: "bi-t", baseCls: "bi-t",
scrolly: true, // scrolly: true,
columnSize: [], columnSize: [],
rowSize: 30, // or [30,30,30] rowSize: [],
horizontalAlign: BI.HorizontalAlign.Stretch,
verticalAlign: BI.VerticalAlign.Stretch,
// rowSize: 30, // or [30,30,30]
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
items: [] items: []
@ -18,17 +21,44 @@ BI.TableLayout = BI.inherit(BI.Layout, {
}, },
render: function () { render: function () {
BI.TableLayout.superclass.render.apply(this, arguments); BI.TableLayout.superclass.render.apply(this, arguments);
this.rows = 0;
var self = this, o = this.options; var self = this, o = this.options;
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) {
self.populate(newValue); self.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items);
var columnSize = o.columnSize.length > 0 ? o.columnSize : BI.range(items[0].length).fill("");
if (columnSize.length > 0) {
var template = [];
for (var i = 0; i < columnSize.length; i++) {
if (columnSize[i] === "") {
template.push("auto");
} else if (columnSize[i] === "fill") {
template.push("1fr");
} else {
template.push(this._optimiseGap(columnSize[i]));
}
}
this.element.css({
"grid-template-columns": template.join(" "),
"grid-template-rows": BI.isArray(o.rowSize) ? BI.map(o.rowSize, function (i, size) {
return self._optimiseGap(size);
}).join(" ") : BI.range(o.items.length).fill(this._optimiseGap(o.rowSize)).join(" "),
"grid-row-gap": this._optimiseGap(o.vgap),
"grid-column-gap": this._optimiseGap(o.hgap)
});
}
return {
type: "bi.default",
ref: function (_ref) {
self.layout = _ref;
},
items: this._formatItems(items)
};
}, },
_addElement: function (idx, arr) { _formatItems: function (items) {
var o = this.options; var o = this.options;
var abs = [], left = 0, right = 0, i, j;
function firstElement (item, row, col) { function firstElement (item, row, col) {
if (row === 0) { if (row === 0) {
@ -40,6 +70,7 @@ BI.TableLayout = BI.inherit(BI.Layout, {
item.addClass(BI.isOdd(row + 1) ? "odd-row" : "even-row"); item.addClass(BI.isOdd(row + 1) ? "odd-row" : "even-row");
item.addClass(BI.isOdd(col + 1) ? "odd-col" : "even-col"); item.addClass(BI.isOdd(col + 1) ? "odd-col" : "even-col");
item.addClass("center-element"); item.addClass("center-element");
return item;
} }
function firstObject (item, row, col) { function firstObject (item, row, col) {
@ -53,85 +84,49 @@ BI.TableLayout = BI.inherit(BI.Layout, {
BI.isOdd(row + 1) ? (cls += " odd-row") : (cls += " even-row"); BI.isOdd(row + 1) ? (cls += " odd-row") : (cls += " even-row");
BI.isOdd(col + 1) ? (cls += " odd-col") : (cls += " even-col"); BI.isOdd(col + 1) ? (cls += " odd-col") : (cls += " even-col");
item.cls = (item.cls || "") + cls + " center-element"; item.cls = (item.cls || "") + cls + " center-element";
return item;
} }
function first (item, row, col) { function first (item, row, col) {
if (item instanceof BI.Widget) { if (item instanceof BI.Widget) {
firstElement(item.element, row, col); return firstElement(item.element, row, col);
} else if (item.el instanceof BI.Widget) { } else if (item.el instanceof BI.Widget) {
firstElement(item.el.element, row, col); return firstElement(item.el.element, row, col);
} else if (item.el) { } else if (item.el) {
firstObject(item.el, row, col); return firstObject(item.el, row, col);
} else { } else {
firstObject(item, row, col); return firstObject(item, row, col);
} }
} }
for (i = 0; i < arr.length; i++) { function wrapLayout (item) {
if (BI.isNumber(o.columnSize[i])) { return {
first(arr[i], this.rows, i); type: "bi.horizontal_fill",
abs.push(BI.extend({ columnSize: ["fill"],
top: 0, horizontalAlign: o.horizontalAlign,
bottom: 0, verticalAlign: o.verticalAlign,
left: this._optimiseGap(left), items: [BI.formatEL(item)]
width: this._optimiseGap(o.columnSize[i]) };
}, arr[i]));
left += o.columnSize[i] + (o.columnSize[i] < 1 ? 0 : o.hgap);
} else {
break;
}
}
for (j = arr.length - 1; j > i; j--) {
if (BI.isNumber(o.columnSize[j])) {
first(arr[j], this.rows, j);
abs.push(BI.extend({
top: 0,
bottom: 0,
right: this._optimiseGap(right),
width: this._optimiseGap(o.columnSize[j])
}, arr[j]));
right += o.columnSize[j] + (o.columnSize[j] < 1 ? 0 : o.hgap);
} else {
throw new Error("构造错误", arr);
}
}
if (i >= 0 && i < arr.length) {
first(arr[i], this.rows, i);
abs.push(BI.extend({
top: 0,
bottom: 0,
left: this._optimiseGap(left),
right: this._optimiseGap(right)
}, arr[i]));
}
var w = BI._lazyCreateWidget({
type: "bi.absolute",
height: BI.isArray(o.rowSize) ? o.rowSize[this.rows] : o.rowSize,
items: abs
});
if (this.rows > 0) {
this.getWidgetByName(this._getChildName(this.rows - 1)).element.css({
"margin-bottom": this._optimiseGap(o.vgap)
});
} }
w.element.css({
position: "relative" return BI.reduce(items, function (row, result, i) {
}); return result.concat(BI.map(row, function (j, item) {
this.addWidget(this._getChildName(this.rows++), w); if (BI.isEmpty(item)) {
return w; return first(wrapLayout({
type: "bi.layout"
}), i, j);
}
return first(wrapLayout(item), i, j);
}));
}, []);
}, },
resize: function () { resize: function () {
// console.log("table布局不需要resize"); // console.log("table布局不需要resize");
}, },
update: function (opt) {
return this.forceUpdate(opt);
},
populate: function (items) { populate: function (items) {
BI.TableLayout.superclass.populate.apply(this, arguments); this.layout.populate(this._formatItems(items));
this._mount();
} }
}); });
BI.shortcut("bi.table", BI.TableLayout); BI.shortcut("bi.table", BI.TableLayout);

2
src/core/wrapper/layout/layout.td.js

@ -78,7 +78,7 @@ BI.TdLayout = BI.inherit(BI.Layout, {
} }
} }
var height = o.rowSize[idx] === "" ? this._optimiseGap(1) : this._optimiseGap(o.rowSize[idx]); var height = BI.isNumber(o.rowSize) ? this._optimiseGap(o.rowSize) : (o.rowSize[idx] === "" ? this._optimiseGap(1) : this._optimiseGap(o.rowSize[idx]));
var tr = BI._lazyCreateWidget({ var tr = BI._lazyCreateWidget({
type: "bi.default", type: "bi.default",
tagName: "tr", tagName: "tr",

3
src/less/core/wrapper/table.less

@ -0,0 +1,3 @@
.bi-t {
display: grid;
}
Loading…
Cancel
Save