From 424153c948b0d768e41bd179239d58254687efdd Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 12 Nov 2020 14:27:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=88=B6=E5=AD=90=E7=BB=84=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E7=9A=84=E5=91=BD=E5=90=8D=E4=BC=98=E5=8C=96=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/wrapper/layout.js | 11 ++++---- src/core/wrapper/layout/layout.border.js | 30 +++++++++++----------- src/core/wrapper/layout/layout.card.js | 27 +++++++++---------- src/core/wrapper/layout/layout.division.js | 12 ++++----- src/core/wrapper/layout/layout.grid.js | 2 +- src/core/wrapper/layout/layout.table.js | 4 +-- src/core/wrapper/layout/layout.tape.js | 20 +++++++-------- src/core/wrapper/layout/layout.td.js | 2 +- src/core/wrapper/layout/layout.window.js | 13 +++++----- 9 files changed, 61 insertions(+), 60 deletions(-) diff --git a/src/core/wrapper/layout.js b/src/core/wrapper/layout.js index 5b5b7970fd..d56ec53446 100644 --- a/src/core/wrapper/layout.js +++ b/src/core/wrapper/layout.js @@ -83,7 +83,7 @@ BI.Layout = BI.inherit(BI.Widget, { }, _getChildName: function (index) { - return index + ""; + return this.getName() + "_" + index; }, _addElement: function (i, item, context) { @@ -94,7 +94,7 @@ BI.Layout = BI.inherit(BI.Widget, { BI.each(self._children, function (name, child) { if (child === w) { BI.remove(self._children, child); - self.removeItemAt(name | 0); + self.removeItemAt(name.replace(self.getName() + "_", "") | 0); } }); }); @@ -316,14 +316,13 @@ BI.Layout = BI.inherit(BI.Widget, { }, prependItems: function (items, context) { - var self = this; items = items || []; var fragment = BI.Widget._renderEngine.createFragment(); var added = []; for (var i = items.length - 1; i >= 0; i--) { this._addItemAt(0, items[i]); var w = this._addElement(0, items[i], context); - self._children[self._getChildName(0)] = w; + this._children[this._getChildName(0)] = w; this.options.items.unshift(items[i]); added.push(w); fragment.appendChild(w.element[0]); @@ -565,11 +564,11 @@ BI.Layout = BI.inherit(BI.Widget, { }, removeWidget: function (nameOrWidget) { - var removeIndex; + var removeIndex, self = this; if (BI.isWidget(nameOrWidget)) { BI.each(this._children, function (name, child) { if (child === nameOrWidget) { - removeIndex = name; + removeIndex = name.replace(self.getName() + "_", ""); } }); } else { diff --git a/src/core/wrapper/layout/layout.border.js b/src/core/wrapper/layout/layout.border.js index 4f2028b43b..77702f8b1a 100644 --- a/src/core/wrapper/layout/layout.border.js +++ b/src/core/wrapper/layout/layout.border.js @@ -35,11 +35,11 @@ BI.BorderLayout = BI.inherit(BI.Layout, { item = regions["north"]; if (item != null) { if (item.el) { - if (!this.hasWidget(this.getName() + "north")) { + if (!this.hasWidget(this._getChildName("north"))) { var w = BI._lazyCreateWidget(item); - this.addWidget(this.getName() + "north", w); + this.addWidget(this._getChildName("north"), w); } - this.getWidgetByName(this.getName() + "north").element.height(item.height) + this.getWidgetByName(this._getChildName("north")).element.height(item.height) .css({ position: "absolute", top: (item.top || 0), @@ -55,11 +55,11 @@ BI.BorderLayout = BI.inherit(BI.Layout, { item = regions["south"]; if (item != null) { if (item.el) { - if (!this.hasWidget(this.getName() + "south")) { + if (!this.hasWidget(this._getChildName("south"))) { var w = BI._lazyCreateWidget(item); - this.addWidget(this.getName() + "south", w); + this.addWidget(this._getChildName("south"), w); } - this.getWidgetByName(this.getName() + "south").element.height(item.height) + this.getWidgetByName(this._getChildName("south")).element.height(item.height) .css({ position: "absolute", bottom: (item.bottom || 0), @@ -75,11 +75,11 @@ BI.BorderLayout = BI.inherit(BI.Layout, { item = regions["west"]; if (item != null) { if (item.el) { - if (!this.hasWidget(this.getName() + "west")) { + if (!this.hasWidget(this._getChildName("west"))) { var w = BI._lazyCreateWidget(item); - this.addWidget(this.getName() + "west", w); + this.addWidget(this._getChildName("west"), w); } - this.getWidgetByName(this.getName() + "west").element.width(item.width) + this.getWidgetByName(this._getChildName("west")).element.width(item.width) .css({ position: "absolute", left: (item.left || 0), @@ -95,11 +95,11 @@ BI.BorderLayout = BI.inherit(BI.Layout, { item = regions["east"]; if (item != null) { if (item.el) { - if (!this.hasWidget(this.getName() + "east")) { + if (!this.hasWidget(this._getChildName("east"))) { var w = BI._lazyCreateWidget(item); - this.addWidget(this.getName() + "east", w); + this.addWidget(this._getChildName("east"), w); } - this.getWidgetByName(this.getName() + "east").element.width(item.width) + this.getWidgetByName(this._getChildName("east")).element.width(item.width) .css({ position: "absolute", right: (item.right || 0), @@ -114,11 +114,11 @@ BI.BorderLayout = BI.inherit(BI.Layout, { if ("center" in regions) { item = regions["center"]; if (item != null) { - if (!this.hasWidget(this.getName() + "center")) { + if (!this.hasWidget(this._getChildName("center"))) { var w = BI._lazyCreateWidget(item); - this.addWidget(this.getName() + "center", w); + this.addWidget(this._getChildName("center"), w); } - this.getWidgetByName(this.getName() + "center").element + this.getWidgetByName(this._getChildName("center")).element .css({position: "absolute", top: top, bottom: bottom, left: left, right: right}); } } diff --git a/src/core/wrapper/layout/layout.card.js b/src/core/wrapper/layout/layout.card.js index ad266ca79b..6a40ea856a 100644 --- a/src/core/wrapper/layout/layout.card.js +++ b/src/core/wrapper/layout/layout.card.js @@ -13,6 +13,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { items: [] }); }, + render: function () { BI.CardLayout.superclass.render.apply(this, arguments); this.populate(this.options.items); @@ -37,9 +38,9 @@ BI.CardLayout = BI.inherit(BI.Layout, { o.items.splice(index, 1); } }); - self.addWidget(item.cardName, w); + self.addWidget(self._getChildName(item.cardName), w); } else { - var w = self.getWidgetByName(item.cardName); + var w = self.getWidgetByName(self._getChildName(item.cardName)); } w.element.css({position: "absolute", top: "0", right: "0", bottom: "0", left: "0"}); w.setVisible(false); @@ -71,11 +72,11 @@ BI.CardLayout = BI.inherit(BI.Layout, { if (!this.isCardExisted(cardName)) { throw new Error("cardName is not exist"); } - return this._children[cardName]; + return this._children[this._getChildName(cardName)]; }, _deleteCardByName: function (cardName) { - delete this._children[cardName]; + delete this._children[this.getName() + "_" + cardName]; var index = BI.findIndex(this.options.items, function (i, item) { return item.cardName == cardName; }); @@ -89,7 +90,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { throw new Error("cardName is not exist"); } - var child = this._children[cardName]; + var child = this._children[this._getChildName(cardName)]; this._deleteCardByName(cardName); child && child._destroy(); }, @@ -107,7 +108,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { height: "100%" }).appendTo(this.element); widget.invisible(); - this.addWidget(cardName, widget); + this.addWidget(this._getChildName(cardName), widget); this.options.items.push({el: cardItem, cardName: cardName}); return widget; }, @@ -122,7 +123,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { this.showIndex = name; var flag = false; BI.each(this.options.items, function (i, item) { - var el = self._children[item.cardName]; + var el = self._children[self._getChildName(item.cardName)]; if (el) { if (name != item.cardName) { // 动画效果只有在全部都隐藏的时候才有意义,且只要执行一次动画操作就够了 @@ -138,7 +139,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { var self = this; this.showIndex = this.lastShowIndex; BI.each(this.options.items, function (i, item) { - self._children[item.cardName].setVisible(self.showIndex == i); + self._children[self._getChildName(item.cardName)].setVisible(self.showIndex == i); }); }, @@ -161,7 +162,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { if (!BI.isKey(this.showIndex)) { return void 0; } - return this.getWidgetByName(this.showIndex); + return this.getWidgetByName(this._getChildName(this.showIndex)); }, deleteAllCard: function () { @@ -174,7 +175,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { hideAllCard: function () { var self = this; BI.each(this.options.items, function (i, item) { - self._children[item.cardName].invisible(); + self._children[self._getChildName(item.cardName)].invisible(); }); }, @@ -182,7 +183,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { var self = this; var flag = true; BI.some(this.options.items, function (i, item) { - if (self._children[item.cardName].isVisible()) { + if (self._children[self._getChildName(item.cardName)].isVisible()) { flag = false; return false; } @@ -191,11 +192,11 @@ BI.CardLayout = BI.inherit(BI.Layout, { }, removeWidget: function (nameOrWidget) { - var removeName; + var removeName, self = this; if (BI.isWidget(nameOrWidget)) { BI.each(this._children, function (name, child) { if (child === nameOrWidget) { - removeName = name; + removeName = name.replace(self.getName() + "_", ""); } }); } else { diff --git a/src/core/wrapper/layout/layout.division.js b/src/core/wrapper/layout/layout.division.js index 59ca653d1d..82021b130a 100644 --- a/src/core/wrapper/layout/layout.division.js +++ b/src/core/wrapper/layout/layout.division.js @@ -114,16 +114,16 @@ BI.DivisionLayout = BI.inherit(BI.Layout, { if (!map[i][j]) { throw new Error("item be required"); } - if (!this.hasWidget(this.getName() + i + "_" + j)) { + if (!this.hasWidget(this._getChildName(i + "_" + j))) { var w = BI._lazyCreateWidget(map[i][j]); - this.addWidget(this.getName() + i + "_" + j, w); + this.addWidget(this._getChildName(i + "_" + j), w); } else { - w = this.getWidgetByName(this.getName() + i + "_" + j); + w = this.getWidgetByName(this._getChildName(i + "_" + j)); } var left = totalW * 100 / widths[i]; w.element.css({position: "absolute", left: left + "%"}); if (j > 0) { - var lastW = this.getWidgetByName(this.getName() + i + "_" + (j - 1)); + var lastW = this.getWidgetByName(this._getChildName(i + "_" + (j - 1))); lastW.element.css({right: (100 - left) + "%"}); } if (j == o.columns - 1) { @@ -136,11 +136,11 @@ BI.DivisionLayout = BI.inherit(BI.Layout, { for (var j = 0; j < o.columns; j++) { var totalH = 0; for (var i = 0; i < o.rows; i++) { - var w = this.getWidgetByName(this.getName() + i + "_" + j); + var w = this.getWidgetByName(this._getChildName(i + "_" + j)); var top = totalH * 100 / heights[j]; w.element.css({top: top + "%"}); if (i > 0) { - var lastW = this.getWidgetByName(this.getName() + (i - 1) + "_" + j); + var lastW = this.getWidgetByName(this._getChildName((i - 1) + "_" + j)); lastW.element.css({bottom: (100 - top) + "%"}); } if (i == o.rows - 1) { diff --git a/src/core/wrapper/layout/layout.grid.js b/src/core/wrapper/layout/layout.grid.js index 125b150803..7db7e7240e 100644 --- a/src/core/wrapper/layout/layout.grid.js +++ b/src/core/wrapper/layout/layout.grid.js @@ -114,7 +114,7 @@ BI.GridLayout = BI.inherit(BI.Layout, { right: (100 - (width * (j + 1))) + "%", bottom: (100 - (height * (i + 1))) + "%" }); - this.addWidget(els[i][j]); + this.addWidget(this._getChildName(i + "_" + j), els[i][j]); } } }, diff --git a/src/core/wrapper/layout/layout.table.js b/src/core/wrapper/layout/layout.table.js index 39e40ccd4c..3820ed99c6 100644 --- a/src/core/wrapper/layout/layout.table.js +++ b/src/core/wrapper/layout/layout.table.js @@ -116,14 +116,14 @@ BI.TableLayout = BI.inherit(BI.Layout, { items: abs }); if (this.rows > 0) { - this.getWidgetByName(this.getName() + (this.rows - 1)).element.css({ + this.getWidgetByName(this._getChildName(this.rows - 1)).element.css({ "margin-bottom": o.vgap }); } w.element.css({ position: "relative" }); - this.addWidget(this.getName() + (this.rows++), w); + this.addWidget(this._getChildName(this.rows++), w); return w; }, diff --git a/src/core/wrapper/layout/layout.tape.js b/src/core/wrapper/layout/layout.tape.js index 4f4730ddd0..0938ac549b 100644 --- a/src/core/wrapper/layout/layout.tape.js +++ b/src/core/wrapper/layout/layout.tape.js @@ -46,11 +46,11 @@ BI.HTapeLayout = BI.inherit(BI.Layout, { var self = this, o = this.options; items = BI.compact(items); BI.each(items, function (i, item) { - if (!self.hasWidget(self.getName() + i + "")) { + if (!self.hasWidget(self.getName() + "_" + i)) { var w = BI._lazyCreateWidget(item); - self.addWidget(self.getName() + i + "", w); + self.addWidget(self._getChildName(i), w); } else { - w = self.getWidgetByName(self.getName() + i + ""); + w = self.getWidgetByName(self._getChildName(i)); } w.element.css({position: "absolute", top: (item.vgap || 0) + (item.tgap || 0) + o.vgap + o.tgap + "px", bottom: (item.bgap || 0) + (item.vgap || 0) + o.vgap + o.bgap + "px"}); }); @@ -60,7 +60,7 @@ BI.HTapeLayout = BI.inherit(BI.Layout, { right[items.length - 1] = 0; BI.any(items, function (i, item) { - var w = self.getWidgetByName(self.getName() + i + ""); + var w = self.getWidgetByName(self._getChildName(i)); if (BI.isNull(left[i])) { left[i] = left[i - 1] + items[i - 1].width + (items[i - 1].lgap || 0) + 2 * (items[i - 1].hgap || 0) + o.hgap + o.lgap + o.rgap; } @@ -77,7 +77,7 @@ BI.HTapeLayout = BI.inherit(BI.Layout, { } }); BI.backAny(items, function (i, item) { - var w = self.getWidgetByName(self.getName() + i + ""); + var w = self.getWidgetByName(self._getChildName(i)); if (BI.isNull(right[i])) { right[i] = right[i + 1] + items[i + 1].width + (items[i + 1].rgap || 0) + 2 * (items[i + 1].hgap || 0) + o.hgap + o.lgap + o.rgap; } @@ -159,11 +159,11 @@ BI.VTapeLayout = BI.inherit(BI.Layout, { var self = this, o = this.options; items = BI.compact(items); BI.each(items, function (i, item) { - if (!self.hasWidget(self.getName() + i + "")) { + if (!self.hasWidget(self._getChildName(i))) { var w = BI._lazyCreateWidget(item); - self.addWidget(self.getName() + i + "", w); + self.addWidget(self._getChildName(i), w); } else { - w = self.getWidgetByName(self.getName() + i + ""); + w = self.getWidgetByName(self._getChildName(i)); } w.element.css({position: "absolute", left: (item.lgap || 0) + (item.hgap || 0) + o.hgap + o.lgap + "px", right: + (item.hgap || 0) + (item.rgap || 0) + o.hgap + o.rgap + "px"}); }); @@ -173,7 +173,7 @@ BI.VTapeLayout = BI.inherit(BI.Layout, { bottom[items.length - 1] = 0; BI.any(items, function (i, item) { - var w = self.getWidgetByName(self.getName() + i + ""); + var w = self.getWidgetByName(self._getChildName(i)); if (BI.isNull(top[i])) { top[i] = top[i - 1] + items[i - 1].height + (items[i - 1].tgap || 0) + 2 * (items[i - 1].vgap || 0) + o.vgap + o.tgap + o.bgap; } @@ -190,7 +190,7 @@ BI.VTapeLayout = BI.inherit(BI.Layout, { } }); BI.backAny(items, function (i, item) { - var w = self.getWidgetByName(self.getName() + i + ""); + var w = self.getWidgetByName(self._getChildName(i)); if (BI.isNull(bottom[i])) { bottom[i] = bottom[i + 1] + items[i + 1].height + (items[i + 1].bgap || 0) + 2 * (items[i + 1].vgap || 0) + o.vgap + o.tgap + o.bgap; } diff --git a/src/core/wrapper/layout/layout.td.js b/src/core/wrapper/layout/layout.td.js index 24add74d90..ccc2feb25e 100644 --- a/src/core/wrapper/layout/layout.td.js +++ b/src/core/wrapper/layout/layout.td.js @@ -115,7 +115,7 @@ BI.TdLayout = BI.inherit(BI.Layout, { }); tr.addItem(td); } - this.addWidget(this.getName() + idx, tr); + this.addWidget(this._getChildName(idx), tr); return tr; }, diff --git a/src/core/wrapper/layout/layout.window.js b/src/core/wrapper/layout/layout.window.js index 75f9069eda..1a5ddd144a 100644 --- a/src/core/wrapper/layout/layout.window.js +++ b/src/core/wrapper/layout/layout.window.js @@ -52,6 +52,7 @@ BI.WindowLayout = BI.inherit(BI.Layout, { if (BI.isNumber(o.columnSize)) { o.columnSize = BI.makeArray(o.items[0].length, 1 / o.items[0].length); } + function firstElement (item, row, col) { if (row === 0) { item.addClass("first-row"); @@ -94,10 +95,10 @@ BI.WindowLayout = BI.inherit(BI.Layout, { if (!o.items[i][j]) { throw new Error("item be required"); } - if (!this.hasWidget(this.getName() + i + "_" + j)) { + if (!this.hasWidget(this._getChildName(i + "_" + j))) { var w = BI._lazyCreateWidget(o.items[i][j]); w.element.css({position: "absolute"}); - this.addWidget(this.getName() + i + "_" + j, w); + this.addWidget(this._getChildName(i + "_" + j), w); } } } @@ -109,7 +110,7 @@ BI.WindowLayout = BI.inherit(BI.Layout, { // 从上到下 for (var i = 0; i < o.rows; i++) { for (var j = 0; j < o.columns; j++) { - var wi = this.getWidgetByName(this.getName() + i + "_" + j); + var wi = this.getWidgetByName(this._getChildName(i + "_" + j)); if (BI.isNull(top[i])) { top[i] = top[i - 1] + (o.rowSize[i - 1] < 1 ? o.rowSize[i - 1] : o.rowSize[i - 1] + o.vgap + o.bgap); } @@ -127,7 +128,7 @@ BI.WindowLayout = BI.inherit(BI.Layout, { // 从下到上 for (var i = o.rows - 1; i >= 0; i--) { for (var j = 0; j < o.columns; j++) { - var wi = this.getWidgetByName(this.getName() + i + "_" + j); + var wi = this.getWidgetByName(this._getChildName(i + "_" + j)); if (BI.isNull(bottom[i])) { bottom[i] = bottom[i + 1] + (o.rowSize[i + 1] < 1 ? o.rowSize[i + 1] : o.rowSize[i + 1] + o.vgap + o.tgap); } @@ -145,7 +146,7 @@ BI.WindowLayout = BI.inherit(BI.Layout, { // 从左到右 for (var j = 0; j < o.columns; j++) { for (var i = 0; i < o.rows; i++) { - var wi = this.getWidgetByName(this.getName() + i + "_" + j); + var wi = this.getWidgetByName(this._getChildName(i + "_" + j)); if (BI.isNull(left[j])) { left[j] = left[j - 1] + (o.columnSize[j - 1] < 1 ? o.columnSize[j - 1] : o.columnSize[j - 1] + o.hgap + o.rgap); } @@ -163,7 +164,7 @@ BI.WindowLayout = BI.inherit(BI.Layout, { // 从右到左 for (var j = o.columns - 1; j >= 0; j--) { for (var i = 0; i < o.rows; i++) { - var wi = this.getWidgetByName(this.getName() + i + "_" + j); + var wi = this.getWidgetByName(this._getChildName(i + "_" + j)); if (BI.isNull(right[j])) { right[j] = right[j + 1] + (o.columnSize[j + 1] < 1 ? o.columnSize[j + 1] : o.columnSize[j + 1] + o.hgap + o.lgap); }