From ef3c3dff5d8d30cb5dc3fc3f1a2110e9699153be Mon Sep 17 00:00:00 2001 From: guy Date: Sat, 19 Jun 2021 23:08:40 +0800 Subject: [PATCH] update --- .../adapt/absolute.leftrightvertical.js | 147 ++++++++++++++++++ src/core/wrapper/layout/layout.tape.js | 26 +++- 2 files changed, 169 insertions(+), 4 deletions(-) create mode 100644 src/core/wrapper/layout/adapt/absolute.leftrightvertical.js diff --git a/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js b/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js new file mode 100644 index 0000000000..a9af9ce1a9 --- /dev/null +++ b/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js @@ -0,0 +1,147 @@ +BI.AbsoluteLeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { + props: function () { + return BI.extend(BI.AbsoluteLeftRightVerticalAdaptLayout.superclass.props.apply(this, arguments), { + baseCls: "bi-abs-lr-v-a", + verticalAlign: BI.VerticalAlign.Middle, + items: {}, + llgap: 0, + lrgap: 0, + lhgap: 0, + ltgap: 0, + lbgap: 0, + lvgap: 0, + rlgap: 0, + rrgap: 0, + rhgap: 0, + rtgap: 0, + rbgap: 0, + rvgap: 0 + }); + }, + render: function () { + var o = this.options, self = this; + BI.AbsoluteLeftRightVerticalAdaptLayout.superclass.render.apply(this, arguments); + return { + type: "bi.htape", + ref: function (_ref) { + self.layout = _ref; + }, + verticalAlign: o.verticalAlign, + items: this._formatItems(), + scrollx: o.scrollx, + scrolly: o.scrolly, + scrollable: o.scrollable + }; + }, + + _formatItems: function () { + var o = this.options; + var leftItems = o.items.left || []; + var rightItems = o.items.right || []; + leftItems = BI.map(leftItems, function (i, item) { + var json = { + el: BI.stripEL(item), + width: item.width + }; + if (o.lvgap + o.ltgap + (item.tgap || 0) + (item.vgap || 0) !== 0) { + json.tgap = o.lvgap + o.ltgap + (item.tgap || 0) + (item.vgap || 0); + } + if (o.lhgap + o.llgap + (item.lgap || 0) + (item.hgap || 0) !== 0) { + json.lgap = (i === 0 ? o.lhgap : 0) + o.llgap + (item.lgap || 0) + (item.hgap || 0); + } + if (o.lhgap + o.lrgap + (item.rgap || 0) + (item.hgap || 0) !== 0) { + json.rgap = o.lhgap + o.lrgap + (item.rgap || 0) + (item.hgap || 0); + } + if (o.lvgap + o.lbgap + (item.bgap || 0) + (item.vgap || 0) !== 0) { + json.bgap = o.lvgap + o.lbgap + (item.bgap || 0) + (item.vgap || 0); + } + return json; + }); + rightItems = BI.map(rightItems, function (i, item) { + var json = { + el: BI.stripEL(item), + width: item.width + }; + if (o.rvgap + o.rtgap + (item.tgap || 0) + (item.vgap || 0) !== 0) { + json.tgap = o.rvgap + o.rtgap + (item.tgap || 0) + (item.vgap || 0); + } + if (o.rhgap + o.rlgap + (item.lgap || 0) + (item.hgap || 0) !== 0) { + json.lgap = (i === 0 ? o.rhgap : 0) + o.rlgap + (item.lgap || 0) + (item.hgap || 0); + } + if (o.rhgap + o.rrgap + (item.rgap || 0) + (item.hgap || 0) !== 0) { + json.rgap = o.rhgap + o.rrgap + (item.rgap || 0) + (item.hgap || 0); + } + if (o.rvgap + o.rbgap + (item.bgap || 0) + (item.vgap || 0) !== 0) { + json.bgap = o.rvgap + o.rbgap + (item.bgap || 0) + (item.vgap || 0); + } + return json; + }); + return leftItems.concat({}, rightItems); + }, + + resize: function () { + // console.log("absolute_left_right_vertical_adapt布局不需要resize"); + }, + + addItem: function () { + // do nothing + throw new Error("cannot be added"); + }, + + populate: function (items) { + this.options.items = items; + this.layout.populate(this._formatItems()); + } +}); +BI.shortcut("bi.absolute_left_right_vertical_adapt", BI.AbsoluteLeftRightVerticalAdaptLayout); + +BI.AbsoluteRightVerticalAdaptLayout = BI.inherit(BI.Layout, { + props: function () { + return BI.extend(BI.AbsoluteRightVerticalAdaptLayout.superclass.props.apply(this, arguments), { + baseCls: "bi-abs-r-v-a", + verticalAlign: BI.VerticalAlign.Middle, + items: [], + lgap: 0, + rgap: 0, + hgap: 0, + tgap: 0, + bgap: 0, + vgap: 0 + }); + }, + render: function () { + var o = this.options, self = this; + BI.AbsoluteRightVerticalAdaptLayout.superclass.render.apply(this, arguments); + return { + type: "bi.htape", + ref: function (_ref) { + self.layout = _ref; + }, + verticalAlign: o.verticalAlign, + items: [{}].concat(o.items), + hgap: o.hgap, + lgap: o.lgap, + rgap: o.rgap, + tgap: o.tgap, + bgap: o.bgap, + vgap: o.vgap, + scrollx: o.scrollx, + scrolly: o.scrolly, + scrollable: o.scrollable + }; + }, + + resize: function () { + + }, + + addItem: function () { + // do nothing + throw new Error("cannot be added"); + }, + + populate: function (items) { + this.layout.populate(items); + } +}); +BI.shortcut("bi.absolute_right_vertical_adapt", BI.AbsoluteRightVerticalAdaptLayout); \ No newline at end of file diff --git a/src/core/wrapper/layout/layout.tape.js b/src/core/wrapper/layout/layout.tape.js index e0e103d325..3a9430383c 100644 --- a/src/core/wrapper/layout/layout.tape.js +++ b/src/core/wrapper/layout/layout.tape.js @@ -35,6 +35,9 @@ BI.HTapeLayout = BI.inherit(BI.Layout, { var self = this, o = this.options; items = BI.compact(items); BI.each(items, function (i, item) { + if (BI.isEmptyObject(item)) { + return; + } if (!self.hasWidget(self._getChildName(i))) { var w = BI._lazyCreateWidget(item); self.addWidget(self._getChildName(i), w); @@ -63,6 +66,9 @@ BI.HTapeLayout = BI.inherit(BI.Layout, { right[items.length - 1] = 0; BI.any(items, function (i, item) { + if (BI.isEmptyObject(item)) { + return true; + } var w = self.getWidgetByName(self._getChildName(i)); var columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width; if (o.columnSize.length > 0) { @@ -72,7 +78,7 @@ BI.HTapeLayout = BI.inherit(BI.Layout, { } if (BI.isNull(left[i])) { var preColumnSize = o.columnSize.length > 0 ? o.columnSize[i - 1] : items[i - 1].width; - left[i] = left[i - 1] + preColumnSize + (items[i - 1].lgap || 0) + 2 * (items[i - 1].hgap || 0) + o.hgap + o.lgap + o.rgap; + left[i] = left[i - 1] + preColumnSize + (items[i - 1].lgap || 0) + (items[i - 1].rgap || 0) + 2 * (items[i - 1].hgap || 0) + o.hgap + o.lgap + o.rgap; } if (columnSize < 1 && columnSize > 0) { w.element.css({ @@ -90,11 +96,14 @@ BI.HTapeLayout = BI.inherit(BI.Layout, { } }); BI.backAny(items, function (i, item) { + if (BI.isEmptyObject(item)) { + return true; + } var w = self.getWidgetByName(self._getChildName(i)); var columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width; if (BI.isNull(right[i])) { var nextColumnSize = o.columnSize.length > 0 ? o.columnSize[i + 1] : items[i + 1].width; - right[i] = right[i + 1] + nextColumnSize + (items[i + 1].rgap || 0) + 2 * (items[i + 1].hgap || 0) + o.hgap + o.lgap + o.rgap; + right[i] = right[i + 1] + nextColumnSize + (items[i + 1].lgap || 0) + (items[i + 1].rgap || 0) + 2 * (items[i + 1].hgap || 0) + o.hgap + o.lgap + o.rgap; } if (columnSize < 1 && columnSize > 0) { w.element.css({ @@ -166,6 +175,9 @@ BI.VTapeLayout = BI.inherit(BI.Layout, { var self = this, o = this.options; items = BI.compact(items); BI.each(items, function (i, item) { + if (BI.isEmptyObject(item)) { + return; + } if (!self.hasWidget(self._getChildName(i))) { var w = BI._lazyCreateWidget(item); self.addWidget(self._getChildName(i), w); @@ -194,6 +206,9 @@ BI.VTapeLayout = BI.inherit(BI.Layout, { bottom[items.length - 1] = 0; BI.any(items, function (i, item) { + if (BI.isEmptyObject(item)) { + return true; + } var w = self.getWidgetByName(self._getChildName(i)); var rowSize = o.rowSize.length > 0 ? o.rowSize[i] : item.height; if (o.rowSize.length > 0) { @@ -203,7 +218,7 @@ BI.VTapeLayout = BI.inherit(BI.Layout, { } if (BI.isNull(top[i])) { var preRowSize = o.rowSize.length > 0 ? o.rowSize[i - 1] : items[i - 1].height; - top[i] = top[i - 1] + preRowSize + (items[i - 1].tgap || 0) + 2 * (items[i - 1].vgap || 0) + o.vgap + o.tgap + o.bgap; + top[i] = top[i - 1] + preRowSize + (items[i - 1].tgap || 0) + (items[i - 1].bgap || 0) + 2 * (items[i - 1].vgap || 0) + o.vgap + o.tgap + o.bgap; } if (rowSize < 1 && rowSize > 0) { w.element.css({ @@ -221,11 +236,14 @@ BI.VTapeLayout = BI.inherit(BI.Layout, { } }); BI.backAny(items, function (i, item) { + if (BI.isEmptyObject(item)) { + return true; + } var w = self.getWidgetByName(self._getChildName(i)); var rowSize = o.rowSize.length > 0 ? o.rowSize[i] : item.height; if (BI.isNull(bottom[i])) { var nextRowSize = o.rowSize.length > 0 ? o.rowSize[i + 1] : items[i + 1].height; - bottom[i] = bottom[i + 1] + nextRowSize + (items[i + 1].bgap || 0) + 2 * (items[i + 1].vgap || 0) + o.vgap + o.tgap + o.bgap; + bottom[i] = bottom[i + 1] + nextRowSize + (items[i + 1].tgap || 0) + (items[i + 1].bgap || 0) + 2 * (items[i + 1].vgap || 0) + o.vgap + o.tgap + o.bgap; } if (rowSize < 1 && rowSize > 0) { w.element.css({