From e801e4bee90f5c3cf5e177f3a5f543f9060f78bf Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 19 Aug 2021 15:41:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/wrapper/layout.js | 43 +++++-------------- .../layout/fill/float.fill.horizontal.js | 4 +- src/core/wrapper/layout/layout.border.js | 4 +- src/core/wrapper/layout/layout.card.js | 4 +- src/core/wrapper/layout/layout.division.js | 27 +----------- src/core/wrapper/layout/layout.grid.js | 22 +--------- src/core/wrapper/layout/layout.inline.js | 27 ++++++++---- src/core/wrapper/layout/layout.table.js | 4 +- src/core/wrapper/layout/layout.tape.js | 8 ++-- src/core/wrapper/layout/layout.td.js | 4 +- src/core/wrapper/layout/layout.window.js | 4 +- .../wrapper/layout/middle/middle.center.js | 6 +-- .../layout/middle/middle.float.center.js | 6 +-- .../layout/middle/middle.horizontal.js | 6 +-- .../wrapper/layout/middle/middle.vertical.js | 6 +-- 15 files changed, 60 insertions(+), 115 deletions(-) diff --git a/src/core/wrapper/layout.js b/src/core/wrapper/layout.js index ca4777f42..b69c6a652 100644 --- a/src/core/wrapper/layout.js +++ b/src/core/wrapper/layout.js @@ -550,8 +550,15 @@ BI.Layout = BI.inherit(BI.Widget, { return updated; }, - shouldUpdate: function () { - return true; + forceUpdate: function (opt) { + if (this._isMounted) { + BI.each(this._children, function (i, c) { + c.destroy(); + }); + this._children = {}; + } + this.options.items = opt.items; + this.stroke(opt.items); }, update: function (opt) { @@ -560,28 +567,6 @@ BI.Layout = BI.inherit(BI.Widget, { var updated = this.updateChildren(o.items, items); this.options.items = items; return updated; - // var updated, i, len; - // for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) { - // if (!this._compare(o.items[i], items[i])) { - // updated = this.updateItemAt(i, items[i]) || updated; - // } - // } - // if (o.items.length > items.length) { - // var deleted = []; - // for (i = items.length; i < o.items.length; i++) { - // deleted.push(this._children[this._getChildName(i)]); - // delete this._children[this._getChildName(i)]; - // } - // o.items.splice(items.length); - // BI.each(deleted, function (i, w) { - // w._destroy(); - // }) - // } else if (items.length > o.items.length) { - // for (i = o.items.length; i < items.length; i++) { - // this.addItemAt(i, items[i]); - // } - // } - // return updated; }, stroke: function (items) { @@ -620,19 +605,11 @@ BI.Layout = BI.inherit(BI.Widget, { }, populate: function (items) { - var self = this, o = this.options; items = items || []; - var shouldUpdate = this.shouldUpdate(); - if (this._isMounted && shouldUpdate) { + if (this._isMounted) { this.update({items: items}); return; } - if (this._isMounted && !shouldUpdate){ - BI.each(this._children, function (i, c) { - c.destroy(); - }); - this._children = {}; - } this.options.items = items; this.stroke(items); }, diff --git a/src/core/wrapper/layout/fill/float.fill.horizontal.js b/src/core/wrapper/layout/fill/float.fill.horizontal.js index 648c5aace..e90c7b0cd 100644 --- a/src/core/wrapper/layout/fill/float.fill.horizontal.js +++ b/src/core/wrapper/layout/fill/float.fill.horizontal.js @@ -123,8 +123,8 @@ BI.FloatHorizontalFillLayout = BI.inherit(BI.Layout, { }); }, - shouldUpdate: function () { - return false; + update: function (opt) { + return this.forceUpdate(opt); }, populate: function (items) { diff --git a/src/core/wrapper/layout/layout.border.js b/src/core/wrapper/layout/layout.border.js index fb6f6ca94..212c545d4 100644 --- a/src/core/wrapper/layout/layout.border.js +++ b/src/core/wrapper/layout/layout.border.js @@ -126,8 +126,8 @@ BI.BorderLayout = BI.inherit(BI.Layout, { } }, - shouldUpdate: function () { - return false; + update: function (opt) { + return this.forceUpdate(opt); }, populate: function (items) { diff --git a/src/core/wrapper/layout/layout.card.js b/src/core/wrapper/layout/layout.card.js index ac59fa873..962bfc2a7 100644 --- a/src/core/wrapper/layout/layout.card.js +++ b/src/core/wrapper/layout/layout.card.js @@ -48,8 +48,8 @@ BI.CardLayout = BI.inherit(BI.Layout, { }); }, - shouldUpdate: function () { - return false; + update: function (opt) { + return this.forceUpdate(opt); }, empty: function () { diff --git a/src/core/wrapper/layout/layout.division.js b/src/core/wrapper/layout/layout.division.js index 2c5b8e1d1..54fe3dbcc 100644 --- a/src/core/wrapper/layout/layout.division.js +++ b/src/core/wrapper/layout/layout.division.js @@ -11,29 +11,6 @@ BI.DivisionLayout = BI.inherit(BI.Layout, { columns: null, rows: null, items: [] - // [ - // { - // column: 0, - // row: 0, - // width: 0.25, - // height: 0.33, - // el: {type: 'bi.button', text: 'button1'} - // }, - // { - // column: 1, - // row: 1, - // width: 0.25, - // height: 0.33, - // el: {type: 'bi.button', text: 'button2'} - // }, - // { - // column: 3, - // row: 2, - // width: 0.25, - // height: 0.33, - // el: {type: 'bi.button', text: 'button3'} - // } - // ] }); }, render: function () { @@ -147,8 +124,8 @@ BI.DivisionLayout = BI.inherit(BI.Layout, { } }, - shouldUpdate: function () { - return false; + update: function (opt) { + return this.forceUpdate(opt); }, populate: function (items) { diff --git a/src/core/wrapper/layout/layout.grid.js b/src/core/wrapper/layout/layout.grid.js index 665993694..9b95f03e5 100644 --- a/src/core/wrapper/layout/layout.grid.js +++ b/src/core/wrapper/layout/layout.grid.js @@ -11,23 +11,6 @@ BI.GridLayout = BI.inherit(BI.Layout, { columns: null, rows: null, items: [] - /* [ - { - column: 0, - row: 0, - el: {type: 'bi.button', text: 'button1'} - }, - { - column: 1, - row: 1, - el: {type: 'bi.button', text: 'button2'} - }, - { - column: 3, - row: 2, - el: {type: 'bi.button', text: 'button3'} - } - ]*/ }); }, render: function () { @@ -40,7 +23,6 @@ BI.GridLayout = BI.inherit(BI.Layout, { }, addItem: function () { - // do nothing throw new Error("不能添加子组件"); }, @@ -119,8 +101,8 @@ BI.GridLayout = BI.inherit(BI.Layout, { } }, - shouldUpdate: function () { - return false; + update: function (opt) { + return this.forceUpdate(opt); }, populate: function (items) { diff --git a/src/core/wrapper/layout/layout.inline.js b/src/core/wrapper/layout/layout.inline.js index 322d7252d..9759c8751 100644 --- a/src/core/wrapper/layout/layout.inline.js +++ b/src/core/wrapper/layout/layout.inline.js @@ -52,19 +52,28 @@ BI.InlineLayout = BI.inherit(BI.Layout, { }); w.element.addClass("i-item"); if (columnSize === "fill" || columnSize === "") { - var left = o.hgap + o.lgap + (item.lgap || 0) + (item.hgap || 0), - right = o.hgap + o.rgap + (item.rgap || 0) + (item.hgap || 0); - for (var k = 0; k < i; k++) { - left += o.hgap + o.lgap + o.rgap + (o.items[k].lgap || 0) + (o.items[k].rgap || 0) + (o.items[k].hgap || 0) + (o.columnSize[k] || o.items[k].width); - } - for (var k = i + 1, len = o.columnSize.length || o.items.length; k < len; k++) { - right += o.hgap + o.lgap + o.rgap + (o.items[k].lgap || 0) + (o.items[k].rgap || 0) + (o.items[k].hgap || 0) + (o.columnSize[k] || o.items[k].width); + var length = o.hgap; + var fillCount = 0, autoCount = 0; + for (var k = 0, len = o.columnSize.length || o.items.length; k < len; k++) { + var cz = o.columnSize.length > 0 ? o.columnSize[k] : o.items[k].width; + if (cz === "fill") { + fillCount++; + cz = 0; + } else if (cz === "" || BI.isNull(cz)) { + autoCount++; + cz = 0; + } + length += o.hgap + o.lgap + o.rgap + (o.items[k].lgap || 0) + (o.items[k].rgap || 0) + (o.items[k].hgap || 0) + cz; } if (columnSize === "fill") { - w.element.css("min-width", "calc(100% - " + ((left + right) / BI.pixRatio + BI.pixUnit) + ")"); + w.element.css("min-width", "calc((100% - " + (length / BI.pixRatio + BI.pixUnit) + ")" + (fillCount > 1 ? "/" + fillCount : "") + ")"); } if (o.horizontalAlign === BI.HorizontalAlign.Stretch || !(o.scrollable === true || o.scrollx === true)) { - w.element.css("max-width", "calc(100% - " + ((left + right) / BI.pixRatio + BI.pixUnit) + ")"); + if (columnSize === "fill") { + w.element.css("max-width", "calc((100% - " + (length / BI.pixRatio + BI.pixUnit) + ")" + (fillCount > 1 ? "/" + fillCount : "") + ")"); + } else { + w.element.css("max-width", "calc((100% - " + (length / BI.pixRatio + BI.pixUnit) + ")" + (autoCount > 1 ? "/" + autoCount : "") + ")"); + } } } this._handleGap(w, item, i); diff --git a/src/core/wrapper/layout/layout.table.js b/src/core/wrapper/layout/layout.table.js index ef2e25bfe..82ffd3973 100644 --- a/src/core/wrapper/layout/layout.table.js +++ b/src/core/wrapper/layout/layout.table.js @@ -121,8 +121,8 @@ BI.TableLayout = BI.inherit(BI.Layout, { // console.log("table布局不需要resize"); }, - shouldUpdate: function () { - return false; + update: function (opt) { + return this.forceUpdate(opt); }, populate: function (items) { diff --git a/src/core/wrapper/layout/layout.tape.js b/src/core/wrapper/layout/layout.tape.js index 3889f65d3..996017abd 100644 --- a/src/core/wrapper/layout/layout.tape.js +++ b/src/core/wrapper/layout/layout.tape.js @@ -119,8 +119,8 @@ BI.HTapeLayout = BI.inherit(BI.Layout, { }); }, - shouldUpdate: function () { - return false; + update: function (opt) { + return this.forceUpdate(opt); }, populate: function (items) { @@ -251,8 +251,8 @@ BI.VTapeLayout = BI.inherit(BI.Layout, { }); }, - shouldUpdate: function () { - return false; + update: function (opt) { + return this.forceUpdate(opt); }, populate: function (items) { diff --git a/src/core/wrapper/layout/layout.td.js b/src/core/wrapper/layout/layout.td.js index 0ba970792..c7c99d712 100644 --- a/src/core/wrapper/layout/layout.td.js +++ b/src/core/wrapper/layout/layout.td.js @@ -172,8 +172,8 @@ BI.TdLayout = BI.inherit(BI.Layout, { this.element.append(this.$table); }, - shouldUpdate: function () { - return false; + update: function (opt) { + return this.forceUpdate(opt); }, populate: function (items) { diff --git a/src/core/wrapper/layout/layout.window.js b/src/core/wrapper/layout/layout.window.js index f09b6b0b1..ca6df6362 100644 --- a/src/core/wrapper/layout/layout.window.js +++ b/src/core/wrapper/layout/layout.window.js @@ -167,8 +167,8 @@ BI.WindowLayout = BI.inherit(BI.Layout, { } }, - shouldUpdate: function () { - return false; + update: function (opt) { + return this.forceUpdate(opt); }, populate: function (items) { diff --git a/src/core/wrapper/layout/middle/middle.center.js b/src/core/wrapper/layout/middle/middle.center.js index 73af27053..d445f6a6e 100644 --- a/src/core/wrapper/layout/middle/middle.center.js +++ b/src/core/wrapper/layout/middle/middle.center.js @@ -48,7 +48,7 @@ BI.CenterLayout = BI.inherit(BI.Layout, { return { type: "bi.grid", ref: function (_ref) { - self.wrapper = _ref; + self.layout = _ref; }, columns: list.length, rows: 1, @@ -66,11 +66,11 @@ BI.CenterLayout = BI.inherit(BI.Layout, { }, update: function (opt) { - return this.wrapper.update(opt); + return this.layout.update(opt); }, populate: function (items) { - this.wrapper.populate.apply(this.wrapper, arguments); + this.layout.populate.apply(this.layout, arguments); } }); BI.shortcut("bi.center", BI.CenterLayout); diff --git a/src/core/wrapper/layout/middle/middle.float.center.js b/src/core/wrapper/layout/middle/middle.float.center.js index f5b2de702..6754528f7 100644 --- a/src/core/wrapper/layout/middle/middle.float.center.js +++ b/src/core/wrapper/layout/middle/middle.float.center.js @@ -49,7 +49,7 @@ BI.FloatCenterLayout = BI.inherit(BI.Layout, { return { type: "bi.left", ref: function (_ref) { - self.wrapper = _ref; + self.layout = _ref; }, items: list }; @@ -65,11 +65,11 @@ BI.FloatCenterLayout = BI.inherit(BI.Layout, { }, update: function (opt) { - return this.wrapper.update(opt); + return this.layout.update(opt); }, populate: function (items) { - this.wrapper.populate.apply(this.wrapper, arguments); + this.layout.populate.apply(this.layout, arguments); } }); BI.shortcut("bi.float_center", BI.FloatCenterLayout); diff --git a/src/core/wrapper/layout/middle/middle.horizontal.js b/src/core/wrapper/layout/middle/middle.horizontal.js index bf802e315..2876d3542 100644 --- a/src/core/wrapper/layout/middle/middle.horizontal.js +++ b/src/core/wrapper/layout/middle/middle.horizontal.js @@ -46,7 +46,7 @@ BI.HorizontalCenterLayout = BI.inherit(BI.Layout, { return { type: "bi.grid", ref: function (_ref) { - self.wrapper = _ref; + self.layout = _ref; }, columns: list.length, rows: 1, @@ -64,11 +64,11 @@ BI.HorizontalCenterLayout = BI.inherit(BI.Layout, { }, update: function (opt) { - return this.wrapper.update(opt); + return this.layout.update(opt); }, populate: function (items) { - this.wrapper.populate.apply(this.wrapper, arguments); + this.layout.populate.apply(this.layout, arguments); } }); BI.shortcut("bi.horizontal_center", BI.HorizontalCenterLayout); diff --git a/src/core/wrapper/layout/middle/middle.vertical.js b/src/core/wrapper/layout/middle/middle.vertical.js index df4ca51ff..c8c6b6d36 100644 --- a/src/core/wrapper/layout/middle/middle.vertical.js +++ b/src/core/wrapper/layout/middle/middle.vertical.js @@ -47,7 +47,7 @@ BI.VerticalCenterLayout = BI.inherit(BI.Layout, { return { type: "bi.grid", ref: function (_ref) { - self.wrapper = _ref; + self.layout = _ref; }, columns: 1, rows: list.length, @@ -65,11 +65,11 @@ BI.VerticalCenterLayout = BI.inherit(BI.Layout, { }, update: function (opt) { - return this.wrapper.update(opt); + return this.layout.update(opt); }, populate: function (items) { - this.wrapper.populate.apply(this.wrapper, arguments); + this.layout.populate.apply(this.layout, arguments); } }); BI.shortcut("bi.vertical_center", BI.VerticalCenterLayout);