From 26a6a960889ba6758121e34c51449356fbcae7d5 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 19 Aug 2021 14:44:37 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=95=B4=E4=BD=93=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E7=9A=84resize=E5=92=8Cupdate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/wrapper/layout.js | 15 ++++++++++-- .../wrapper/layout/adapt/absolute.center.js | 4 ---- .../layout/adapt/absolute.horizontal.js | 6 ++++- .../adapt/absolute.leftrightvertical.js | 6 ++++- .../wrapper/layout/adapt/absolute.vertical.js | 6 ++++- src/core/wrapper/layout/adapt/adapt.center.js | 6 ++++- .../layout/adapt/adapt.leftrightvertical.js | 23 +++++++++++++++++-- src/core/wrapper/layout/adapt/adapt.table.js | 4 ---- .../wrapper/layout/adapt/adapt.vertical.js | 6 ++++- .../wrapper/layout/adapt/auto.horizontal.js | 4 ---- .../wrapper/layout/adapt/inline.center.js | 8 +++++++ .../wrapper/layout/adapt/inline.horizontal.js | 8 +++++++ .../wrapper/layout/adapt/inline.vertical.js | 8 +++++++ .../layout/fill/float.fill.horizontal.js | 4 ++++ src/core/wrapper/layout/flex/flex.center.js | 2 +- .../layout/flex/flex.horizontal.center.js | 2 +- .../wrapper/layout/flex/flex.horizontal.js | 4 ---- .../flex/flex.leftrightvertical.center.js | 6 ++++- .../layout/flex/flex.vertical.center.js | 2 +- src/core/wrapper/layout/flex/flex.vertical.js | 4 ---- .../flex/wrapper/flex.wrapper.center.js | 4 ++++ .../wrapper/flex.wrapper.horizontal.center.js | 4 ++++ .../flex/wrapper/flex.wrapper.horizontal.js | 4 ---- .../wrapper/flex.wrapper.vertical.center.js | 4 ++++ .../flex/wrapper/flex.wrapper.vertical.js | 4 ---- .../layout/float/float.absolute.center.js | 4 ---- .../layout/float/float.absolute.horizontal.js | 8 +++++-- .../float/float.absolute.leftrightvertical.js | 10 +++++++- .../layout/float/float.absolute.vertical.js | 6 ++++- src/core/wrapper/layout/layout.absolute.js | 4 ---- src/core/wrapper/layout/layout.adaptive.js | 4 ---- src/core/wrapper/layout/layout.border.js | 7 ++---- src/core/wrapper/layout/layout.card.js | 5 ++-- src/core/wrapper/layout/layout.default.js | 4 ---- src/core/wrapper/layout/layout.division.js | 7 ++---- src/core/wrapper/layout/layout.flow.js | 8 ------- src/core/wrapper/layout/layout.grid.js | 3 ++- src/core/wrapper/layout/layout.inline.js | 8 ------- src/core/wrapper/layout/layout.lattice.js | 16 ------------- src/core/wrapper/layout/layout.table.js | 10 ++------ src/core/wrapper/layout/layout.tape.js | 18 ++++----------- src/core/wrapper/layout/layout.td.js | 14 ++--------- src/core/wrapper/layout/layout.vertical.js | 4 ---- src/core/wrapper/layout/layout.window.js | 7 ++---- 44 files changed, 146 insertions(+), 149 deletions(-) diff --git a/src/core/wrapper/layout.js b/src/core/wrapper/layout.js index 01e50c54f..ca4777f42 100644 --- a/src/core/wrapper/layout.js +++ b/src/core/wrapper/layout.js @@ -550,6 +550,10 @@ BI.Layout = BI.inherit(BI.Widget, { return updated; }, + shouldUpdate: function () { + return true; + }, + update: function (opt) { var o = this.options; var items = opt.items || []; @@ -618,16 +622,23 @@ BI.Layout = BI.inherit(BI.Widget, { populate: function (items) { var self = this, o = this.options; items = items || []; - if (this._isMounted) { + var shouldUpdate = this.shouldUpdate(); + if (this._isMounted && shouldUpdate) { 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); }, resize: function () { - + this.stroke(this.options.items); } }); BI.shortcut("bi.layout", BI.Layout); diff --git a/src/core/wrapper/layout/adapt/absolute.center.js b/src/core/wrapper/layout/adapt/absolute.center.js index 60838983e..f5da01bbc 100644 --- a/src/core/wrapper/layout/adapt/absolute.center.js +++ b/src/core/wrapper/layout/adapt/absolute.center.js @@ -35,10 +35,6 @@ BI.AbsoluteCenterLayout = BI.inherit(BI.Layout, { return w; }, - resize: function () { - // console.log("absolute_center_adapt布局不需要resize"); - }, - populate: function (items) { BI.AbsoluteCenterLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/adapt/absolute.horizontal.js b/src/core/wrapper/layout/adapt/absolute.horizontal.js index 53c8a05cc..bbae5ff4c 100644 --- a/src/core/wrapper/layout/adapt/absolute.horizontal.js +++ b/src/core/wrapper/layout/adapt/absolute.horizontal.js @@ -42,7 +42,11 @@ BI.AbsoluteHorizontalLayout = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("absolute_horizontal_adapt布局不需要resize"); + this.layout.resize(); + }, + + update: function (opt) { + return this.layout.update(opt); }, populate: function (items) { diff --git a/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js b/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js index 1ac9c37b3..dc745b307 100644 --- a/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js +++ b/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js @@ -80,7 +80,7 @@ BI.AbsoluteLeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("absolute_left_right_vertical_adapt布局不需要resize"); + this.layout.stroke(this._formatItems()) }, addItem: function () { @@ -132,7 +132,11 @@ BI.AbsoluteRightVerticalAdaptLayout = BI.inherit(BI.Layout, { }, resize: function () { + this.layout.stroke([{}].concat(this.options.items)) + }, + update: function (opt) { + return this.layout.update(opt); }, addItem: function () { diff --git a/src/core/wrapper/layout/adapt/absolute.vertical.js b/src/core/wrapper/layout/adapt/absolute.vertical.js index f4c9552e2..a2ea783fe 100644 --- a/src/core/wrapper/layout/adapt/absolute.vertical.js +++ b/src/core/wrapper/layout/adapt/absolute.vertical.js @@ -42,7 +42,11 @@ BI.AbsoluteVerticalLayout = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("absolute_vertical_adapt布局不需要resize"); + this.layout.resize(); + }, + + update: function (opt) { + return this.layout.update(opt); }, populate: function (items) { diff --git a/src/core/wrapper/layout/adapt/adapt.center.js b/src/core/wrapper/layout/adapt/adapt.center.js index 4158a3ccc..ba8c82f10 100644 --- a/src/core/wrapper/layout/adapt/adapt.center.js +++ b/src/core/wrapper/layout/adapt/adapt.center.js @@ -43,7 +43,11 @@ BI.CenterAdaptLayout = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("center_adapt布局不需要resize"); + this.layout.resize(); + }, + + update: function (opt) { + return this.layout.update(opt); }, populate: function (items) { diff --git a/src/core/wrapper/layout/adapt/adapt.leftrightvertical.js b/src/core/wrapper/layout/adapt/adapt.leftrightvertical.js index b2dabf32a..4e0dbeb57 100644 --- a/src/core/wrapper/layout/adapt/adapt.leftrightvertical.js +++ b/src/core/wrapper/layout/adapt/adapt.leftrightvertical.js @@ -76,7 +76,18 @@ BI.LeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("left_right_vertical_adapt布局不需要resize"); + this.left.stroke(this.options.items.left); + this.right.stroke(this.options.items.right); + }, + + update: function (opt) { + this.left.update({ + items: opt.items.left + }); + this.right.update({ + items: opt.items.right + }); + return true; }, addItem: function () { @@ -129,7 +140,11 @@ BI.LeftVerticalAdaptLayout = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("left_vertical_adapt布局不需要resize"); + this.layout.resize(); + }, + + update: function (opt) { + return this.layout.update(opt); }, addItem: function () { @@ -181,7 +196,11 @@ BI.RightVerticalAdaptLayout = BI.inherit(BI.Layout, { }, resize: function () { + this.layout.resize(); + }, + update: function (opt) { + return this.layout.update(opt); }, addItem: function () { diff --git a/src/core/wrapper/layout/adapt/adapt.table.js b/src/core/wrapper/layout/adapt/adapt.table.js index f1391c29b..8ea7025a8 100644 --- a/src/core/wrapper/layout/adapt/adapt.table.js +++ b/src/core/wrapper/layout/adapt/adapt.table.js @@ -100,10 +100,6 @@ BI.TableAdaptLayout = BI.inherit(BI.Layout, { this.element.append(this.$table); }, - resize: function () { - // console.log("center_adapt布局不需要resize"); - }, - populate: function (items) { BI.TableAdaptLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/adapt/adapt.vertical.js b/src/core/wrapper/layout/adapt/adapt.vertical.js index 15fc8e7c0..3f5f2a405 100644 --- a/src/core/wrapper/layout/adapt/adapt.vertical.js +++ b/src/core/wrapper/layout/adapt/adapt.vertical.js @@ -43,7 +43,11 @@ BI.VerticalAdaptLayout = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("vertical_adapt布局不需要resize"); + this.layout.resize(); + }, + + update: function (opt) { + return this.layout.update(opt); }, populate: function (items) { diff --git a/src/core/wrapper/layout/adapt/auto.horizontal.js b/src/core/wrapper/layout/adapt/auto.horizontal.js index 27b64bd9c..197b2badc 100644 --- a/src/core/wrapper/layout/adapt/auto.horizontal.js +++ b/src/core/wrapper/layout/adapt/auto.horizontal.js @@ -32,10 +32,6 @@ BI.HorizontalAutoLayout = BI.inherit(BI.Layout, { return w; }, - resize: function () { - // console.log("horizontal_adapt布局不需要resize"); - }, - populate: function (items) { BI.HorizontalAutoLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/adapt/inline.center.js b/src/core/wrapper/layout/adapt/inline.center.js index 0aea35ef1..d8bc184db 100644 --- a/src/core/wrapper/layout/adapt/inline.center.js +++ b/src/core/wrapper/layout/adapt/inline.center.js @@ -44,6 +44,14 @@ BI.InlineCenterAdaptLayout = BI.inherit(BI.Layout, { }; }, + resize: function () { + this.layout.resize(); + }, + + update: function (opt) { + return this.layout.update(opt); + }, + populate: function (items) { this.layout.populate.apply(this.layout, arguments); } diff --git a/src/core/wrapper/layout/adapt/inline.horizontal.js b/src/core/wrapper/layout/adapt/inline.horizontal.js index 3ad1bc602..734c2bd3d 100644 --- a/src/core/wrapper/layout/adapt/inline.horizontal.js +++ b/src/core/wrapper/layout/adapt/inline.horizontal.js @@ -44,6 +44,14 @@ BI.InlineHorizontalAdaptLayout = BI.inherit(BI.Layout, { }; }, + resize: function () { + this.layout.resize(); + }, + + update: function (opt) { + return this.layout.update(opt); + }, + populate: function (items) { this.layout.populate.apply(this.layout, arguments); } diff --git a/src/core/wrapper/layout/adapt/inline.vertical.js b/src/core/wrapper/layout/adapt/inline.vertical.js index 1e7401e46..ba7bf54f5 100644 --- a/src/core/wrapper/layout/adapt/inline.vertical.js +++ b/src/core/wrapper/layout/adapt/inline.vertical.js @@ -44,6 +44,14 @@ BI.InlineVerticalAdaptLayout = BI.inherit(BI.Layout, { }; }, + resize: function () { + this.layout.resize(); + }, + + update: function (opt) { + return this.layout.update(opt); + }, + populate: function (items) { this.layout.populate.apply(this.layout, arguments); } diff --git a/src/core/wrapper/layout/fill/float.fill.horizontal.js b/src/core/wrapper/layout/fill/float.fill.horizontal.js index b19b31b0a..648c5aace 100644 --- a/src/core/wrapper/layout/fill/float.fill.horizontal.js +++ b/src/core/wrapper/layout/fill/float.fill.horizontal.js @@ -123,6 +123,10 @@ BI.FloatHorizontalFillLayout = BI.inherit(BI.Layout, { }); }, + shouldUpdate: function () { + return false; + }, + populate: function (items) { BI.FloatHorizontalFillLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/flex/flex.center.js b/src/core/wrapper/layout/flex/flex.center.js index 23c81d318..09c81b792 100644 --- a/src/core/wrapper/layout/flex/flex.center.js +++ b/src/core/wrapper/layout/flex/flex.center.js @@ -42,7 +42,7 @@ BI.FlexCenterLayout = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("flex_center_adapt布局不需要resize"); + this.wrapper.resize(); }, update: function (opt) { diff --git a/src/core/wrapper/layout/flex/flex.horizontal.center.js b/src/core/wrapper/layout/flex/flex.horizontal.center.js index 0c4207484..028ef748f 100644 --- a/src/core/wrapper/layout/flex/flex.horizontal.center.js +++ b/src/core/wrapper/layout/flex/flex.horizontal.center.js @@ -43,7 +43,7 @@ BI.FlexHorizontalCenter = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("flex_vertical_center_adapt布局不需要resize"); + this.wrapper.resize(); }, update: function (opt) { diff --git a/src/core/wrapper/layout/flex/flex.horizontal.js b/src/core/wrapper/layout/flex/flex.horizontal.js index 7c4fbcc0d..59108c851 100644 --- a/src/core/wrapper/layout/flex/flex.horizontal.js +++ b/src/core/wrapper/layout/flex/flex.horizontal.js @@ -78,10 +78,6 @@ BI.FlexHorizontalLayout = BI.inherit(BI.Layout, { return w; }, - resize: function () { - // console.log("flex_horizontal布局不需要resize"); - }, - populate: function (items) { BI.FlexHorizontalLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/flex/flex.leftrightvertical.center.js b/src/core/wrapper/layout/flex/flex.leftrightvertical.center.js index f2cc78c0c..20e05b2ef 100644 --- a/src/core/wrapper/layout/flex/flex.leftrightvertical.center.js +++ b/src/core/wrapper/layout/flex/flex.leftrightvertical.center.js @@ -72,7 +72,11 @@ BI.FlexLeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("left_right_vertical_adapt布局不需要resize"); + this.layout.stroke(this._formatItems()); + }, + + update: function (opt) { + return this.layout.update(opt); }, addItem: function () { diff --git a/src/core/wrapper/layout/flex/flex.vertical.center.js b/src/core/wrapper/layout/flex/flex.vertical.center.js index 24559546d..533ac2fa9 100644 --- a/src/core/wrapper/layout/flex/flex.vertical.center.js +++ b/src/core/wrapper/layout/flex/flex.vertical.center.js @@ -44,7 +44,7 @@ BI.FlexVerticalCenter = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("flex_vertical_center_adapt布局不需要resize"); + this.wrapper.resize(); }, update: function (opt) { diff --git a/src/core/wrapper/layout/flex/flex.vertical.js b/src/core/wrapper/layout/flex/flex.vertical.js index 515541e46..eb38d07a3 100644 --- a/src/core/wrapper/layout/flex/flex.vertical.js +++ b/src/core/wrapper/layout/flex/flex.vertical.js @@ -77,10 +77,6 @@ BI.FlexVerticalLayout = BI.inherit(BI.Layout, { return w; }, - resize: function () { - // console.log("flex_vertical布局不需要resize"); - }, - populate: function (items) { BI.FlexVerticalLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.center.js b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.center.js index ae7612780..740030e76 100644 --- a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.center.js +++ b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.center.js @@ -44,6 +44,10 @@ BI.FlexWrapperCenterLayout = BI.inherit(BI.Layout, { }; }, + resize: function () { + this.wrapper.resize(); + }, + update: function (opt) { return this.wrapper.update(opt); }, diff --git a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.center.js b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.center.js index fc8ef31a8..3d4d28c2c 100644 --- a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.center.js +++ b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.center.js @@ -44,6 +44,10 @@ BI.FlexWrapperHorizontalCenter = BI.inherit(BI.Layout, { }; }, + resize: function () { + this.wrapper.resize(); + }, + update: function (opt) { return this.wrapper.update(opt); }, diff --git a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.js b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.js index 075ffe8cb..fb4ea738a 100644 --- a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.js +++ b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.js @@ -84,10 +84,6 @@ BI.FlexWrapperHorizontalLayout = BI.inherit(BI.Layout, { return this.$wrapper; }, - resize: function () { - // console.log("flex_wrapper_horizontal布局不需要resize"); - }, - populate: function (items) { BI.FlexWrapperHorizontalLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.center.js b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.center.js index 0a461c74c..af072c1a6 100644 --- a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.center.js +++ b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.center.js @@ -44,6 +44,10 @@ BI.FlexWrapperVerticalCenter = BI.inherit(BI.Layout, { }; }, + resize: function () { + this.wrapper.resize(); + }, + update: function (opt) { return this.wrapper.update(opt); }, diff --git a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.js b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.js index 89214e9a8..413bb0fa2 100644 --- a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.js +++ b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.js @@ -84,10 +84,6 @@ BI.FlexWrapperVerticalLayout = BI.inherit(BI.Layout, { return this.$wrapper; }, - resize: function () { - // console.log("flex_wrapper_vertical布局不需要resize"); - }, - populate: function (items) { BI.FlexWrapperVerticalLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/float/float.absolute.center.js b/src/core/wrapper/layout/float/float.absolute.center.js index 566b5d738..afe3e77b7 100644 --- a/src/core/wrapper/layout/float/float.absolute.center.js +++ b/src/core/wrapper/layout/float/float.absolute.center.js @@ -24,10 +24,6 @@ BI.FloatAbsoluteCenterLayout = BI.inherit(BI.Layout, { return w; }, - resize: function () { - // console.log("float_absolute_center_adapt布局不需要resize"); - }, - populate: function (items) { BI.FloatAbsoluteCenterLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/float/float.absolute.horizontal.js b/src/core/wrapper/layout/float/float.absolute.horizontal.js index eb59723eb..d044fbe23 100644 --- a/src/core/wrapper/layout/float/float.absolute.horizontal.js +++ b/src/core/wrapper/layout/float/float.absolute.horizontal.js @@ -57,11 +57,15 @@ BI.FloatAbsoluteHorizontalLayout = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("float_absolute_horizontal_adapt布局不需要resize"); + this.layout.stroke(this._formatItems(this.options.items)); + }, + + update: function (opt) { + return this.layout.update(opt); }, populate: function (items) { - this.layout.populate.apply(this, arguments); + this.layout.populate(this._formatItems(items)); } }); BI.shortcut("bi.absolute_horizontal_float", BI.FloatAbsoluteHorizontalLayout); diff --git a/src/core/wrapper/layout/float/float.absolute.leftrightvertical.js b/src/core/wrapper/layout/float/float.absolute.leftrightvertical.js index c56d101eb..f2b70a53a 100644 --- a/src/core/wrapper/layout/float/float.absolute.leftrightvertical.js +++ b/src/core/wrapper/layout/float/float.absolute.leftrightvertical.js @@ -97,7 +97,11 @@ BI.FloatAbsoluteLeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("absolute_left_right_vertical_adapt布局不需要resize"); + this.layout.stroke(this._formatItems()); + }, + + update: function (opt) { + return this.layout.update(opt); }, addItem: function () { @@ -162,7 +166,11 @@ BI.FloatAbsoluteRightVerticalAdaptLayout = BI.inherit(BI.Layout, { }, resize: function () { + this.layout.stroke([{}].concat(this._formatItems(this.options.items))); + }, + update: function (opt) { + return this.layout.update(opt); }, addItem: function () { diff --git a/src/core/wrapper/layout/float/float.absolute.vertical.js b/src/core/wrapper/layout/float/float.absolute.vertical.js index 2cb1042bf..9b5609030 100644 --- a/src/core/wrapper/layout/float/float.absolute.vertical.js +++ b/src/core/wrapper/layout/float/float.absolute.vertical.js @@ -57,7 +57,11 @@ BI.FloatAbsoluteVerticalLayout = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("float_absolute_vertical_adapt布局不需要resize"); + this.layout.stroke(this._formatItems(this.options.items)); + }, + + update: function (opt) { + return this.layout.update(opt); }, populate: function (items) { diff --git a/src/core/wrapper/layout/layout.absolute.js b/src/core/wrapper/layout/layout.absolute.js index d392ccc56..6a59eb133 100644 --- a/src/core/wrapper/layout/layout.absolute.js +++ b/src/core/wrapper/layout/layout.absolute.js @@ -81,10 +81,6 @@ BI.AbsoluteLayout = BI.inherit(BI.Layout, { return w; }, - resize: function () { - this.stroke(this.options.items); - }, - populate: function (items) { BI.AbsoluteLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/layout.adaptive.js b/src/core/wrapper/layout/layout.adaptive.js index f82a9e321..7c19e1928 100644 --- a/src/core/wrapper/layout/layout.adaptive.js +++ b/src/core/wrapper/layout/layout.adaptive.js @@ -51,10 +51,6 @@ BI.AdaptiveLayout = BI.inherit(BI.Layout, { return w; }, - resize: function () { - this.stroke(this.options.items); - }, - populate: function (items) { BI.AbsoluteLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/layout.border.js b/src/core/wrapper/layout/layout.border.js index 47907c572..fb6f6ca94 100644 --- a/src/core/wrapper/layout/layout.border.js +++ b/src/core/wrapper/layout/layout.border.js @@ -16,10 +16,6 @@ BI.BorderLayout = BI.inherit(BI.Layout, { this.populate(this.options.items); }, - resize: function () { - this.stroke(this.options.items); - }, - addItem: function (item) { // do nothing throw new Error("不能添加子组件"); @@ -130,7 +126,8 @@ BI.BorderLayout = BI.inherit(BI.Layout, { } }, - update: function (opt) { + shouldUpdate: function () { + return false; }, populate: function (items) { diff --git a/src/core/wrapper/layout/layout.card.js b/src/core/wrapper/layout/layout.card.js index 65fa9fcf6..ac59fa873 100644 --- a/src/core/wrapper/layout/layout.card.js +++ b/src/core/wrapper/layout/layout.card.js @@ -20,7 +20,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { }, resize: function () { - // console.log("default布局不需要resize"); + // console.log("Card布局不需要resize"); }, stroke: function (items) { @@ -48,7 +48,8 @@ BI.CardLayout = BI.inherit(BI.Layout, { }); }, - update: function () { + shouldUpdate: function () { + return false; }, empty: function () { diff --git a/src/core/wrapper/layout/layout.default.js b/src/core/wrapper/layout/layout.default.js index 516b7e3a1..a35f99a07 100644 --- a/src/core/wrapper/layout/layout.default.js +++ b/src/core/wrapper/layout/layout.default.js @@ -27,10 +27,6 @@ BI.DefaultLayout = BI.inherit(BI.Layout, { return w; }, - resize: function () { - // console.log("default布局不需要resize") - }, - populate: function (items) { BI.DefaultLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/layout.division.js b/src/core/wrapper/layout/layout.division.js index 1aac78bc8..2c5b8e1d1 100644 --- a/src/core/wrapper/layout/layout.division.js +++ b/src/core/wrapper/layout/layout.division.js @@ -41,10 +41,6 @@ BI.DivisionLayout = BI.inherit(BI.Layout, { this.populate(this.options.items); }, - resize: function () { - this.stroke(this.opitons.items); - }, - addItem: function (item) { // do nothing throw new Error("不能添加子组件"); @@ -151,7 +147,8 @@ BI.DivisionLayout = BI.inherit(BI.Layout, { } }, - update: function () { + shouldUpdate: function () { + return false; }, populate: function (items) { diff --git a/src/core/wrapper/layout/layout.flow.js b/src/core/wrapper/layout/layout.flow.js index be0ff5481..2061b4513 100644 --- a/src/core/wrapper/layout/layout.flow.js +++ b/src/core/wrapper/layout/layout.flow.js @@ -64,10 +64,6 @@ BI.FloatLeftLayout = BI.inherit(BI.Layout, { return w; }, - resize: function () { - this.stroke(this.options.items); - }, - populate: function (items) { BI.FloatLeftLayout.superclass.populate.apply(this, arguments); this._mount(); @@ -141,10 +137,6 @@ BI.FloatRightLayout = BI.inherit(BI.Layout, { return w; }, - resize: function () { - this.stroke(this.options.items); - }, - populate: function (items) { BI.FloatRightLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/layout.grid.js b/src/core/wrapper/layout/layout.grid.js index a787c449b..665993694 100644 --- a/src/core/wrapper/layout/layout.grid.js +++ b/src/core/wrapper/layout/layout.grid.js @@ -119,7 +119,8 @@ BI.GridLayout = BI.inherit(BI.Layout, { } }, - update: function () { + shouldUpdate: function () { + return false; }, populate: function (items) { diff --git a/src/core/wrapper/layout/layout.inline.js b/src/core/wrapper/layout/layout.inline.js index 053b49562..322d7252d 100644 --- a/src/core/wrapper/layout/layout.inline.js +++ b/src/core/wrapper/layout/layout.inline.js @@ -76,14 +76,6 @@ BI.InlineLayout = BI.inherit(BI.Layout, { return w; }, - resize: function () { - this.stroke(this.options.items); - }, - - addItem: function (item) { - throw new Error("不能添加子组件"); - }, - populate: function (items) { BI.InlineLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/layout.lattice.js b/src/core/wrapper/layout/layout.lattice.js index b9779db94..9b5731815 100644 --- a/src/core/wrapper/layout/layout.lattice.js +++ b/src/core/wrapper/layout/layout.lattice.js @@ -31,22 +31,6 @@ BI.LatticeLayout = BI.inherit(BI.Layout, { return w; }, - addItem: function (item) { - var w = BI.LatticeLayout.superclass.addItem.apply(this, arguments); - this.resize(); - return w; - }, - - addItemAt: function (item) { - var w = BI.LatticeLayout.superclass.addItemAt.apply(this, arguments); - this.resize(); - return w; - }, - - resize: function () { - this.stroke(this.options.items); - }, - populate: function (items) { BI.LatticeLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/layout.table.js b/src/core/wrapper/layout/layout.table.js index faec5d7fa..ef2e25bfe 100644 --- a/src/core/wrapper/layout/layout.table.js +++ b/src/core/wrapper/layout/layout.table.js @@ -121,14 +121,8 @@ BI.TableLayout = BI.inherit(BI.Layout, { // console.log("table布局不需要resize"); }, - addItem: function (arr) { - if (!BI.isArray(arr)) { - throw new Error("必须是数组", arr); - } - return BI.TableLayout.superclass.addItem.apply(this, arguments); - }, - - update: function () { + shouldUpdate: function () { + return false; }, populate: function (items) { diff --git a/src/core/wrapper/layout/layout.tape.js b/src/core/wrapper/layout/layout.tape.js index 7c5a85b2f..3889f65d3 100644 --- a/src/core/wrapper/layout/layout.tape.js +++ b/src/core/wrapper/layout/layout.tape.js @@ -23,9 +23,6 @@ BI.HTapeLayout = BI.inherit(BI.Layout, { this.populate(this.options.items); }, - resize: function () { - this.stroke(this.options.items); - }, addItem: function (item) { // do nothing throw new Error("不能添加子组件"); @@ -122,12 +119,8 @@ BI.HTapeLayout = BI.inherit(BI.Layout, { }); }, - update: function () { - var updated; - BI.each(this._children, function (i, child) { - updated = child.update() || updated; - }); - return updated; + shouldUpdate: function () { + return false; }, populate: function (items) { @@ -162,10 +155,6 @@ BI.VTapeLayout = BI.inherit(BI.Layout, { this.populate(this.options.items); }, - resize: function () { - this.stroke(this.options.items); - }, - addItem: function (item) { // do nothing throw new Error("不能添加子组件"); @@ -262,7 +251,8 @@ BI.VTapeLayout = BI.inherit(BI.Layout, { }); }, - update: function () { + shouldUpdate: function () { + return false; }, populate: function (items) { diff --git a/src/core/wrapper/layout/layout.td.js b/src/core/wrapper/layout/layout.td.js index a5aefb300..0ba970792 100644 --- a/src/core/wrapper/layout/layout.td.js +++ b/src/core/wrapper/layout/layout.td.js @@ -172,18 +172,8 @@ BI.TdLayout = BI.inherit(BI.Layout, { this.element.append(this.$table); }, - resize: function () { - // console.log("td布局不需要resize"); - }, - - addItem: function (arr) { - if (!BI.isArray(arr)) { - throw new Error("必须是数组", arr); - } - return BI.TdLayout.superclass.addItem.apply(this, arguments); - }, - - update: function () { + shouldUpdate: function () { + return false; }, populate: function (items) { diff --git a/src/core/wrapper/layout/layout.vertical.js b/src/core/wrapper/layout/layout.vertical.js index d34e14d31..90c78e1b7 100644 --- a/src/core/wrapper/layout/layout.vertical.js +++ b/src/core/wrapper/layout/layout.vertical.js @@ -42,10 +42,6 @@ BI.VerticalLayout = BI.inherit(BI.Layout, { return w; }, - resize: function () { - this.stroke(this.options.items); - }, - populate: function (items) { BI.VerticalLayout.superclass.populate.apply(this, arguments); this._mount(); diff --git a/src/core/wrapper/layout/layout.window.js b/src/core/wrapper/layout/layout.window.js index d7037f923..f09b6b0b1 100644 --- a/src/core/wrapper/layout/layout.window.js +++ b/src/core/wrapper/layout/layout.window.js @@ -25,10 +25,6 @@ BI.WindowLayout = BI.inherit(BI.Layout, { this.populate(this.options.items); }, - resize: function () { - this.stroke(this.options.items); - }, - addItem: function (item) { // do nothing throw new Error("不能添加子组件"); @@ -171,7 +167,8 @@ BI.WindowLayout = BI.inherit(BI.Layout, { } }, - update: function () { + shouldUpdate: function () { + return false; }, populate: function (items) { From 777e3ea3e398688643048bfb63022a2d31482b79 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 19 Aug 2021 14:46:15 +0800 Subject: [PATCH 2/8] =?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/flex/flex.center.js | 8 ++++---- src/core/wrapper/layout/flex/flex.horizontal.center.js | 8 ++++---- src/core/wrapper/layout/flex/flex.vertical.center.js | 8 ++++---- .../wrapper/layout/flex/wrapper/flex.wrapper.center.js | 8 ++++---- .../layout/flex/wrapper/flex.wrapper.horizontal.center.js | 8 ++++---- .../layout/flex/wrapper/flex.wrapper.vertical.center.js | 8 ++++---- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/core/wrapper/layout/flex/flex.center.js b/src/core/wrapper/layout/flex/flex.center.js index 09c81b792..0bf886ca8 100644 --- a/src/core/wrapper/layout/flex/flex.center.js +++ b/src/core/wrapper/layout/flex/flex.center.js @@ -24,7 +24,7 @@ BI.FlexCenterLayout = BI.inherit(BI.Layout, { return { type: "bi.flex_horizontal", ref: function (_ref) { - self.wrapper = _ref; + self.layout = _ref; }, horizontalAlign: o.horizontalAlign, verticalAlign: o.verticalAlign, @@ -42,15 +42,15 @@ BI.FlexCenterLayout = BI.inherit(BI.Layout, { }, resize: function () { - this.wrapper.resize(); + this.layout.resize(); }, update: function (opt) { - return this.wrapper.update(opt); + return this.layout.update(opt); }, populate: function (items) { - this.wrapper.populate(items); + this.layout.populate(items); } }); BI.shortcut("bi.flex_center_adapt", BI.FlexCenterLayout); diff --git a/src/core/wrapper/layout/flex/flex.horizontal.center.js b/src/core/wrapper/layout/flex/flex.horizontal.center.js index 028ef748f..8af01988c 100644 --- a/src/core/wrapper/layout/flex/flex.horizontal.center.js +++ b/src/core/wrapper/layout/flex/flex.horizontal.center.js @@ -25,7 +25,7 @@ BI.FlexHorizontalCenter = BI.inherit(BI.Layout, { return { type: "bi.flex_vertical", ref: function (_ref) { - self.wrapper = _ref; + self.layout = _ref; }, horizontalAlign: o.horizontalAlign, verticalAlign: o.verticalAlign, @@ -43,15 +43,15 @@ BI.FlexHorizontalCenter = BI.inherit(BI.Layout, { }, resize: function () { - this.wrapper.resize(); + this.layout.resize(); }, update: function (opt) { - return this.wrapper.update(opt); + return this.layout.update(opt); }, populate: function (items) { - this.wrapper.populate(items); + this.layout.populate(items); } }); BI.shortcut("bi.flex_horizontal_adapt", BI.FlexHorizontalCenter); diff --git a/src/core/wrapper/layout/flex/flex.vertical.center.js b/src/core/wrapper/layout/flex/flex.vertical.center.js index 533ac2fa9..8b27066af 100644 --- a/src/core/wrapper/layout/flex/flex.vertical.center.js +++ b/src/core/wrapper/layout/flex/flex.vertical.center.js @@ -26,7 +26,7 @@ BI.FlexVerticalCenter = BI.inherit(BI.Layout, { return { type: "bi.flex_horizontal", ref: function (_ref) { - self.wrapper = _ref; + self.layout = _ref; }, verticalAlign: o.verticalAlign, horizontalAlign: o.horizontalAlign, @@ -44,15 +44,15 @@ BI.FlexVerticalCenter = BI.inherit(BI.Layout, { }, resize: function () { - this.wrapper.resize(); + this.layout.resize(); }, update: function (opt) { - return this.wrapper.update(opt); + return this.layout.update(opt); }, populate: function (items) { - this.wrapper.populate(items); + this.layout.populate(items); } }); BI.shortcut("bi.flex_vertical_adapt", BI.FlexVerticalCenter); diff --git a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.center.js b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.center.js index 740030e76..eeb66dd20 100644 --- a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.center.js +++ b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.center.js @@ -27,7 +27,7 @@ BI.FlexWrapperCenterLayout = BI.inherit(BI.Layout, { return { type: "bi.flex_scrollable_horizontal", ref: function (_ref) { - self.wrapper = _ref; + self.layout = _ref; }, horizontalAlign: o.horizontalAlign, verticalAlign: o.verticalAlign, @@ -45,15 +45,15 @@ BI.FlexWrapperCenterLayout = BI.inherit(BI.Layout, { }, resize: function () { - this.wrapper.resize(); + this.layout.resize(); }, update: function (opt) { - return this.wrapper.update(opt); + return this.layout.update(opt); }, populate: function (items) { - this.wrapper.populate(items); + this.layout.populate(items); } }); BI.shortcut("bi.flex_scrollable_center_adapt", BI.FlexWrapperCenterLayout); diff --git a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.center.js b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.center.js index 3d4d28c2c..e03babc6c 100644 --- a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.center.js +++ b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.horizontal.center.js @@ -27,7 +27,7 @@ BI.FlexWrapperHorizontalCenter = BI.inherit(BI.Layout, { return { type: "bi.flex_scrollable_vertical", ref: function (_ref) { - self.wrapper = _ref; + self.layout = _ref; }, horizontalAlign: o.horizontalAlign, verticalAlign: o.verticalAlign, @@ -45,15 +45,15 @@ BI.FlexWrapperHorizontalCenter = BI.inherit(BI.Layout, { }, resize: function () { - this.wrapper.resize(); + this.layout.resize(); }, update: function (opt) { - return this.wrapper.update(opt); + return this.layout.update(opt); }, populate: function (items) { - this.wrapper.populate(items); + this.layout.populate(items); } }); BI.shortcut("bi.flex_scrollable_horizontal_adapt", BI.FlexWrapperHorizontalCenter); diff --git a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.center.js b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.center.js index af072c1a6..d5e7096b1 100644 --- a/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.center.js +++ b/src/core/wrapper/layout/flex/wrapper/flex.wrapper.vertical.center.js @@ -27,7 +27,7 @@ BI.FlexWrapperVerticalCenter = BI.inherit(BI.Layout, { return { type: "bi.flex_scrollable_horizontal", ref: function (_ref) { - self.wrapper = _ref; + self.layout = _ref; }, verticalAlign: o.verticalAlign, horizontalAlign: o.horizontalAlign, @@ -45,15 +45,15 @@ BI.FlexWrapperVerticalCenter = BI.inherit(BI.Layout, { }, resize: function () { - this.wrapper.resize(); + this.layout.resize(); }, update: function (opt) { - return this.wrapper.update(opt); + return this.layout.update(opt); }, populate: function (items) { - this.wrapper.populate(items); + this.layout.populate(items); } }); BI.shortcut("bi.flex_scrollable_vertical_adapt", BI.FlexWrapperVerticalCenter); From 2d95922fa44943f583d4cd3dcbfac7b097b41255 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 19 Aug 2021 14:53:07 +0800 Subject: [PATCH 3/8] =?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/adapt/absolute.leftrightvertical.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js b/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js index dc745b307..57ed23db9 100644 --- a/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js +++ b/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js @@ -145,7 +145,7 @@ BI.AbsoluteRightVerticalAdaptLayout = BI.inherit(BI.Layout, { }, populate: function (items) { - this.layout.populate(items); + this.layout.populate([{}].concat(items)); } }); BI.shortcut("bi.absolute_right_vertical_adapt", BI.AbsoluteRightVerticalAdaptLayout); From 1bc5c90ad185e36e77654592bc2e34a3283d3c64 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 19 Aug 2021 14:57:34 +0800 Subject: [PATCH 4/8] =?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 --- .../wrapper/layout/float/float.absolute.leftrightvertical.js | 2 +- src/core/wrapper/layout/float/float.absolute.vertical.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/wrapper/layout/float/float.absolute.leftrightvertical.js b/src/core/wrapper/layout/float/float.absolute.leftrightvertical.js index f2b70a53a..e6efbdff4 100644 --- a/src/core/wrapper/layout/float/float.absolute.leftrightvertical.js +++ b/src/core/wrapper/layout/float/float.absolute.leftrightvertical.js @@ -179,7 +179,7 @@ BI.FloatAbsoluteRightVerticalAdaptLayout = BI.inherit(BI.Layout, { }, populate: function (items) { - this.layout.populate(items); + this.layout.populate([{}].concat(this._formatItems(items))); } }); BI.shortcut("bi.absolute_right_vertical_float", BI.FloatAbsoluteRightVerticalAdaptLayout); diff --git a/src/core/wrapper/layout/float/float.absolute.vertical.js b/src/core/wrapper/layout/float/float.absolute.vertical.js index 9b5609030..b53abb144 100644 --- a/src/core/wrapper/layout/float/float.absolute.vertical.js +++ b/src/core/wrapper/layout/float/float.absolute.vertical.js @@ -65,7 +65,7 @@ BI.FloatAbsoluteVerticalLayout = BI.inherit(BI.Layout, { }, populate: function (items) { - this.layout.populate.apply(this, arguments); + this.layout.populate(this._formatItems(items)); } }); BI.shortcut("bi.absolute_vertical_float", BI.FloatAbsoluteVerticalLayout); From e801e4bee90f5c3cf5e177f3a5f543f9060f78bf Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 19 Aug 2021 15:41:55 +0800 Subject: [PATCH 5/8] =?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); From d4bba4651065b0dd84f49177cdcea5db2be4c53b Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 19 Aug 2021 16:24:44 +0800 Subject: [PATCH 6/8] =?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/layout.card.js | 8 ++++---- src/core/wrapper/layout/layout.grid.js | 8 ++++---- src/core/wrapper/layout/layout.td.js | 4 ++++ src/core/wrapper/layout/layout.window.js | 4 ++++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/core/wrapper/layout/layout.card.js b/src/core/wrapper/layout/layout.card.js index 962bfc2a7..5ca2bec63 100644 --- a/src/core/wrapper/layout/layout.card.js +++ b/src/core/wrapper/layout/layout.card.js @@ -19,10 +19,6 @@ BI.CardLayout = BI.inherit(BI.Layout, { this.populate(this.options.items); }, - resize: function () { - // console.log("Card布局不需要resize"); - }, - stroke: function (items) { var self = this, o = this.options; this.showIndex = void 0; @@ -48,6 +44,10 @@ BI.CardLayout = BI.inherit(BI.Layout, { }); }, + resize: function () { + // console.log("Card布局不需要resize"); + }, + update: function (opt) { return this.forceUpdate(opt); }, diff --git a/src/core/wrapper/layout/layout.grid.js b/src/core/wrapper/layout/layout.grid.js index 9b95f03e5..97ad39862 100644 --- a/src/core/wrapper/layout/layout.grid.js +++ b/src/core/wrapper/layout/layout.grid.js @@ -18,10 +18,6 @@ BI.GridLayout = BI.inherit(BI.Layout, { this.populate(this.options.items); }, - resize: function () { - // console.log("grid布局不需要resize") - }, - addItem: function () { throw new Error("不能添加子组件"); }, @@ -101,6 +97,10 @@ BI.GridLayout = BI.inherit(BI.Layout, { } }, + resize: function () { + // console.log("grid布局不需要resize") + }, + update: function (opt) { return this.forceUpdate(opt); }, diff --git a/src/core/wrapper/layout/layout.td.js b/src/core/wrapper/layout/layout.td.js index c7c99d712..ba5b2adef 100644 --- a/src/core/wrapper/layout/layout.td.js +++ b/src/core/wrapper/layout/layout.td.js @@ -172,6 +172,10 @@ BI.TdLayout = BI.inherit(BI.Layout, { this.element.append(this.$table); }, + resize: function () { + // console.log("td布局不需要resize"); + }, + update: function (opt) { return this.forceUpdate(opt); }, diff --git a/src/core/wrapper/layout/layout.window.js b/src/core/wrapper/layout/layout.window.js index ca6df6362..7094bb7ee 100644 --- a/src/core/wrapper/layout/layout.window.js +++ b/src/core/wrapper/layout/layout.window.js @@ -167,6 +167,10 @@ BI.WindowLayout = BI.inherit(BI.Layout, { } }, + resize: function () { + // console.log("window布局不需要resize"); + }, + update: function (opt) { return this.forceUpdate(opt); }, From 6704e10365ad458a926a222881524c22a0cf1f82 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 19 Aug 2021 16:40:27 +0800 Subject: [PATCH 7/8] =?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 | 46 +++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/src/core/wrapper/layout.js b/src/core/wrapper/layout.js index b69c6a652..ac421a7d0 100644 --- a/src/core/wrapper/layout.js +++ b/src/core/wrapper/layout.js @@ -198,6 +198,21 @@ BI.Layout = BI.inherit(BI.Widget, { return this.element; }, + // 不依赖于this.options.items进行更新 + _updateItemAt: function (index, item) { + var del = this._children[this._getChildName(index)]; + delete this._children[this._getChildName(index)]; + var w = this._addElement(index, item); + this._children[this._getChildName(index)] = w; + if (index > 0) { + this._children[this._getChildName(index - 1)].element.after(w.element); + } else { + w.element.prependTo(this._getWrapper()); + } + del._destroy(); + w._mount(); + }, + _addItemAt: function (index, item) { for (var i = this.options.items.length; i > index; i--) { this._children[this._getChildName(i)] = this._children[this._getChildName(i - 1)]; @@ -286,35 +301,13 @@ BI.Layout = BI.inherit(BI.Widget, { }, shouldUpdateItem: function (index, item) { - if (index < 0 || index > this.options.items.length - 1) { - return false; - } var child = this._children[this._getChildName(index)]; - if (!child.shouldUpdate) { + if (!child || !child.shouldUpdate) { return null; } return child.shouldUpdate(this._getOptions(item)); }, - updateItemAt: function (index, item) { - if (index < 0 || index > this.options.items.length - 1) { - return; - } - var del = this._children[this._getChildName(index)]; - delete this._children[this._getChildName(index)]; - this.options.items.splice(index, 1); - var w = this._addElement(index, item); - this.options.items.splice(index, 0, item); - this._children[this._getChildName(index)] = w; - if (index > 0) { - this._children[this._getChildName(index - 1)].element.after(w.element); - } else { - w.element.prependTo(this._getWrapper()); - } - del._destroy(); - w._mount(); - }, - addItems: function (items, context) { var self = this, o = this.options; var fragment = BI.Widget._renderEngine.createFragment(); @@ -394,8 +387,9 @@ BI.Layout = BI.inherit(BI.Widget, { // if (child.update) { // return child.update(this._getOptions(vnode)); // } - return this.updateItemAt(index, vnode); + return this._updateItemAt(index, vnode); } + }, updateChildren: function (oldCh, newCh) { @@ -564,9 +558,9 @@ BI.Layout = BI.inherit(BI.Widget, { update: function (opt) { var o = this.options; var items = opt.items || []; - var updated = this.updateChildren(o.items, items); + var oldItems = o.items; this.options.items = items; - return updated; + return this.updateChildren(oldItems, items); }, stroke: function (items) { From 14ce46f10eb2000eca4ba910aa5deeba0b534fc8 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 19 Aug 2021 16:44:04 +0800 Subject: [PATCH 8/8] =?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 --- changelog.md | 1 + src/core/wrapper/layout.js | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index d9159329c..8c8bb9ba5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # 更新日志 2.0(2021-07) +- layout支持forceUpdate刷新方式 - width属性支持calc() - 修改了颜色选择器交互 - 新增bi.horizontal_fill、bi.vertical_fill布局 diff --git a/src/core/wrapper/layout.js b/src/core/wrapper/layout.js index ac421a7d0..03564167a 100644 --- a/src/core/wrapper/layout.js +++ b/src/core/wrapper/layout.js @@ -389,7 +389,6 @@ BI.Layout = BI.inherit(BI.Widget, { // } return this._updateItemAt(index, vnode); } - }, updateChildren: function (oldCh, newCh) {