From c9dc548a2a080c89a175be7a649d511e8e1e3488 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 2 Sep 2021 10:51:58 +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 --- changelog.md | 5 ++- src/core/h.js | 12 +++++- .../adapt/absolute.leftrightvertical.js | 26 +++++++++---- .../layout/adapt/adapt.leftrightvertical.js | 38 +++++++++++++++---- .../flex/flex.leftrightvertical.center.js | 15 +++++++- .../float/float.absolute.leftrightvertical.js | 15 +++++++- 6 files changed, 89 insertions(+), 22 deletions(-) diff --git a/changelog.md b/changelog.md index a8520e128..97ab875a6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,9 @@ # 更新日志 -2.0(2021-07) +2.0(2021-09) +- 支持h函数传递left、right,优化left_right_vertical_adapt布局的jsx写法 - 新增bi.virtual_group_list组件 + +2.0(2021-07) - layout支持forceUpdate刷新方式 - width属性支持calc() - 修改了颜色选择器交互 diff --git a/src/core/h.js b/src/core/h.js index 96b99e5f4..c3c117f91 100644 --- a/src/core/h.js +++ b/src/core/h.js @@ -29,7 +29,17 @@ BI.h = function (type, props, children) { el: children[0] }, props); } + if (type === "left") { + return BI.extend({ + left: children + }, props); + } + if (type === "right") { + return BI.extend({ + right: children + }, props); + } return BI.extend({ - type: type, + type: type }, children.length > 0 ? {items: children} : {}, props); }; diff --git a/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js b/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js index 0ff7ee466..8ea35e148 100644 --- a/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js +++ b/src/core/wrapper/layout/adapt/absolute.leftrightvertical.js @@ -27,17 +27,28 @@ BI.AbsoluteLeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { self.layout = _ref; }, verticalAlign: o.verticalAlign, - items: this._formatItems(), + items: this._formatItems(o.items), scrollx: o.scrollx, scrolly: o.scrolly, scrollable: o.scrollable }; }, - _formatItems: function () { + _formatItems: function (items) { var o = this.options; - var leftItems = o.items.left || []; - var rightItems = o.items.right || []; + var left, right; + if (BI.isArray(items)) { + BI.each(items, function (i, item) { + if (item.left) { + left = item.left; + } + if (item.right) { + right = item.right; + } + }); + } + var leftItems = left || items.left || []; + var rightItems = right || items.right || []; leftItems = BI.map(leftItems, function (i, item) { var json = { el: BI.stripEL(item), @@ -80,7 +91,7 @@ BI.AbsoluteLeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { }, resize: function () { - this.layout.stroke(this._formatItems()) + this.layout.stroke(this._formatItems(this.options.items)); }, addItem: function () { @@ -89,8 +100,7 @@ BI.AbsoluteLeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { }, populate: function (items) { - this.options.items = items; - this.layout.populate(this._formatItems()); + this.layout.populate(this._formatItems(items)); } }); BI.shortcut("bi.absolute_left_right_vertical_adapt", BI.AbsoluteLeftRightVerticalAdaptLayout); @@ -132,7 +142,7 @@ BI.AbsoluteRightVerticalAdaptLayout = BI.inherit(BI.Layout, { }, resize: function () { - this.layout.stroke([{}].concat(this.options.items)) + this.layout.stroke([{}].concat(this.options.items)); }, addItem: function () { diff --git a/src/core/wrapper/layout/adapt/adapt.leftrightvertical.js b/src/core/wrapper/layout/adapt/adapt.leftrightvertical.js index 575f1397c..166728ab3 100644 --- a/src/core/wrapper/layout/adapt/adapt.leftrightvertical.js +++ b/src/core/wrapper/layout/adapt/adapt.leftrightvertical.js @@ -29,8 +29,9 @@ BI.LeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { render: function () { var o = this.options, self = this; BI.LeftRightVerticalAdaptLayout.superclass.render.apply(this, arguments); + var leftRight = this._getLeftRight(o.items); var layoutArray = []; - if ("left" in o.items) { + if (leftRight.left || "left" in o.items) { layoutArray.push({ type: "bi.left", items: [{ @@ -40,7 +41,7 @@ BI.LeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { self.left = _ref; }, height: "100%", - items: o.items.left, + items: leftRight.left || o.items.left, hgap: o.lhgap, lgap: o.llgap, rgap: o.lrgap, @@ -51,7 +52,7 @@ BI.LeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { }] }); } - if ("right" in o.items) { + if (leftRight.right || "right" in o.items) { layoutArray.push({ type: "bi.right", items: [{ @@ -61,7 +62,7 @@ BI.LeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { self.right = _ref; }, height: "100%", - items: o.items.right, + items: leftRight.right || o.items.right, hgap: o.rhgap, lgap: o.rlgap, rgap: o.rrgap, @@ -75,9 +76,29 @@ BI.LeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { return layoutArray; }, + _getLeftRight: function (items) { + var o = this.options; + var left, right; + if (BI.isArray(items)) { + BI.each(items, function (i, item) { + if (item.left) { + left = item.left; + } + if (item.right) { + right = item.right; + } + }); + } + return { + left: left, + right: right + }; + }, + resize: function () { - this.left.stroke(this.options.items.left); - this.right.stroke(this.options.items.right); + var leftRight = this._getLeftRight(this.options.items); + this.left.stroke(leftRight.left || this.options.items.left); + this.right.stroke(leftRight.right || this.options.items.right); }, addItem: function () { @@ -86,8 +107,9 @@ BI.LeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { }, populate: function (items) { - this.left.populate(items.left); - this.right.populate(items.right); + var leftRight = this._getLeftRight(items); + this.left.populate(leftRight.left || items.left); + this.right.populate(leftRight.right || items.right); } }); BI.shortcut("bi.left_right_vertical_adapt", BI.LeftRightVerticalAdaptLayout); diff --git a/src/core/wrapper/layout/flex/flex.leftrightvertical.center.js b/src/core/wrapper/layout/flex/flex.leftrightvertical.center.js index 03915e888..aefb271dd 100644 --- a/src/core/wrapper/layout/flex/flex.leftrightvertical.center.js +++ b/src/core/wrapper/layout/flex/flex.leftrightvertical.center.js @@ -34,8 +34,19 @@ BI.FlexLeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { _formatItems: function (items) { var o = this.options; - var leftItems = items.left || []; - var rightItems = items.right || []; + var left, right; + if (BI.isArray(items)) { + BI.each(items, function (i, item) { + if (item.left) { + left = item.left; + } + if (item.right) { + right = item.right; + } + }); + } + var leftItems = left || items.left || []; + var rightItems = right || items.right || []; leftItems = BI.map(leftItems, function (i, item) { var json = { el: BI.stripEL(item) diff --git a/src/core/wrapper/layout/float/float.absolute.leftrightvertical.js b/src/core/wrapper/layout/float/float.absolute.leftrightvertical.js index 06655b62d..365d2dbcd 100644 --- a/src/core/wrapper/layout/float/float.absolute.leftrightvertical.js +++ b/src/core/wrapper/layout/float/float.absolute.leftrightvertical.js @@ -37,8 +37,19 @@ BI.FloatAbsoluteLeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { _formatItems: function (items) { var o = this.options; - var leftItems = items.left || []; - var rightItems = items.right || []; + var left, right; + if (BI.isArray(items)) { + BI.each(items, function (i, item) { + if (item.left) { + left = item.left; + } + if (item.right) { + right = item.right; + } + }); + } + var leftItems = left || items.left || []; + var rightItems = right || items.right || []; leftItems = BI.map(leftItems, function (i, item) { var el = BI.stripEL(item); if (o.verticalAlign === BI.VerticalAlign.Middle) {