From 7e1b8c15143b5fa34d379e6357f51baa82369234 Mon Sep 17 00:00:00 2001 From: guy Date: Sat, 1 Apr 2017 21:22:06 +0800 Subject: [PATCH] =?UTF-8?q?tab=E5=92=8Cnavigation=E5=8A=A0=E5=85=A5single?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bi/base.js | 44 +++++++++++++++++++++++--- bi/core.js | 2 +- dist/base.js | 44 +++++++++++++++++++++++--- dist/core.js | 2 +- src/base/combination/navigation.js | 29 ++++++++++++++--- src/base/combination/tab.js | 15 +++++++++ src/core/wrapper/layout/layout.card.js | 2 +- 7 files changed, 123 insertions(+), 15 deletions(-) diff --git a/bi/base.js b/bi/base.js index 41d9f2b6f..d8284b6a6 100644 --- a/bi/base.js +++ b/bi/base.js @@ -3920,6 +3920,7 @@ BI.Navigation = BI.inherit(BI.Widget, { logic: { dynamic: false }, + single: false, defaultShowIndex: 0, tab: { type: "bi.button_group", @@ -3973,6 +3974,18 @@ BI.Navigation = BI.inherit(BI.Widget, { } }, + _deleteOtherCards: function (currCardName) { + var self = this, o = this.options; + if (o.single === true) { + BI.each(this.cardMap, function (name, card) { + if (name !== (currCardName + "")) { + self.layout.deleteCardByName(name); + delete self.cardMap[name]; + } + }); + } + }, + afterCardCreated: function (v) { var self = this; this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { @@ -3980,12 +3993,13 @@ BI.Navigation = BI.inherit(BI.Widget, { if (type === BI.Events.CLICK) { self.fireEvent(BI.Navigation.EVENT_CHANGE, obj); } - }) + }); this.options.afterCardCreated.apply(this, arguments); }, afterCardShow: function (v) { this.showIndex = v; + this._deleteOtherCards(v); this.options.afterCardShow.apply(this, arguments); }, @@ -3996,16 +4010,23 @@ BI.Navigation = BI.inherit(BI.Widget, { } }, - setSelect: function (v) { - this.showIndex = v; + _assertCard: function () { if (!this.layout.isCardExisted(v)) { var card = this.options.cardCreator(v); this.cardMap[v] = card; this.layout.addCardByName(v, card); this.afterCardCreated(v); } + }, + + setSelect: function (v) { + this._assertCard(); this.layout.showCardByName(v); - BI.nextTick(BI.bind(this.afterCardShow, this, v)); + this._deleteOtherCards(v); + if (this.showIndex !== v) { + this.showIndex = v; + BI.nextTick(BI.bind(this.afterCardShow, this, v)); + } }, getSelect: function () { @@ -4636,6 +4657,7 @@ BI.Tab = BI.inherit(BI.Widget, { return BI.extend(BI.Tab.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-tab", direction: "top",//top, bottom, left, right, custom + single: false, //是不是单页面 logic: { dynamic: false }, @@ -4675,6 +4697,7 @@ BI.Tab = BI.inherit(BI.Widget, { return card; }, afterCardShow: function (v) { + self._deleteOtherCards(v); self.curr = v; } }); @@ -4683,6 +4706,18 @@ BI.Tab = BI.inherit(BI.Widget, { }); }, + _deleteOtherCards: function (currCardName) { + var self = this, o = this.options; + if (o.single === true) { + BI.each(this.cardMap, function (name, card) { + if (name !== (currCardName + "")) { + self.layout.deleteCardByName(name); + delete self.cardMap[name]; + } + }); + } + }, + _assertCard: function (v) { if (!this.layout.isCardExisted(v)) { var card = this.options.cardCreator(v); @@ -4702,6 +4737,7 @@ BI.Tab = BI.inherit(BI.Widget, { this.tab && this.tab.setValue(v); this._assertCard(v); this.layout.showCardByName(v); + this._deleteOtherCards(v); if (this.curr !== v) { this.curr = v; } diff --git a/bi/core.js b/bi/core.js index af139ef2a..b0b8f41bd 100644 --- a/bi/core.js +++ b/bi/core.js @@ -13289,7 +13289,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { isCardExisted: function (cardName) { return BI.some(this.options.items, function (i, item) { - return item.cardName === cardName && item.el; + return item.cardName == cardName && item.el; }); }, diff --git a/dist/base.js b/dist/base.js index 41d9f2b6f..d8284b6a6 100644 --- a/dist/base.js +++ b/dist/base.js @@ -3920,6 +3920,7 @@ BI.Navigation = BI.inherit(BI.Widget, { logic: { dynamic: false }, + single: false, defaultShowIndex: 0, tab: { type: "bi.button_group", @@ -3973,6 +3974,18 @@ BI.Navigation = BI.inherit(BI.Widget, { } }, + _deleteOtherCards: function (currCardName) { + var self = this, o = this.options; + if (o.single === true) { + BI.each(this.cardMap, function (name, card) { + if (name !== (currCardName + "")) { + self.layout.deleteCardByName(name); + delete self.cardMap[name]; + } + }); + } + }, + afterCardCreated: function (v) { var self = this; this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { @@ -3980,12 +3993,13 @@ BI.Navigation = BI.inherit(BI.Widget, { if (type === BI.Events.CLICK) { self.fireEvent(BI.Navigation.EVENT_CHANGE, obj); } - }) + }); this.options.afterCardCreated.apply(this, arguments); }, afterCardShow: function (v) { this.showIndex = v; + this._deleteOtherCards(v); this.options.afterCardShow.apply(this, arguments); }, @@ -3996,16 +4010,23 @@ BI.Navigation = BI.inherit(BI.Widget, { } }, - setSelect: function (v) { - this.showIndex = v; + _assertCard: function () { if (!this.layout.isCardExisted(v)) { var card = this.options.cardCreator(v); this.cardMap[v] = card; this.layout.addCardByName(v, card); this.afterCardCreated(v); } + }, + + setSelect: function (v) { + this._assertCard(); this.layout.showCardByName(v); - BI.nextTick(BI.bind(this.afterCardShow, this, v)); + this._deleteOtherCards(v); + if (this.showIndex !== v) { + this.showIndex = v; + BI.nextTick(BI.bind(this.afterCardShow, this, v)); + } }, getSelect: function () { @@ -4636,6 +4657,7 @@ BI.Tab = BI.inherit(BI.Widget, { return BI.extend(BI.Tab.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-tab", direction: "top",//top, bottom, left, right, custom + single: false, //是不是单页面 logic: { dynamic: false }, @@ -4675,6 +4697,7 @@ BI.Tab = BI.inherit(BI.Widget, { return card; }, afterCardShow: function (v) { + self._deleteOtherCards(v); self.curr = v; } }); @@ -4683,6 +4706,18 @@ BI.Tab = BI.inherit(BI.Widget, { }); }, + _deleteOtherCards: function (currCardName) { + var self = this, o = this.options; + if (o.single === true) { + BI.each(this.cardMap, function (name, card) { + if (name !== (currCardName + "")) { + self.layout.deleteCardByName(name); + delete self.cardMap[name]; + } + }); + } + }, + _assertCard: function (v) { if (!this.layout.isCardExisted(v)) { var card = this.options.cardCreator(v); @@ -4702,6 +4737,7 @@ BI.Tab = BI.inherit(BI.Widget, { this.tab && this.tab.setValue(v); this._assertCard(v); this.layout.showCardByName(v); + this._deleteOtherCards(v); if (this.curr !== v) { this.curr = v; } diff --git a/dist/core.js b/dist/core.js index fd8f0ca25..bf97615c7 100644 --- a/dist/core.js +++ b/dist/core.js @@ -26842,7 +26842,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { isCardExisted: function (cardName) { return BI.some(this.options.items, function (i, item) { - return item.cardName === cardName && item.el; + return item.cardName == cardName && item.el; }); }, diff --git a/src/base/combination/navigation.js b/src/base/combination/navigation.js index c119f92bb..3ef882581 100644 --- a/src/base/combination/navigation.js +++ b/src/base/combination/navigation.js @@ -9,6 +9,7 @@ BI.Navigation = BI.inherit(BI.Widget, { logic: { dynamic: false }, + single: false, defaultShowIndex: 0, tab: { type: "bi.button_group", @@ -62,6 +63,18 @@ BI.Navigation = BI.inherit(BI.Widget, { } }, + _deleteOtherCards: function (currCardName) { + var self = this, o = this.options; + if (o.single === true) { + BI.each(this.cardMap, function (name, card) { + if (name !== (currCardName + "")) { + self.layout.deleteCardByName(name); + delete self.cardMap[name]; + } + }); + } + }, + afterCardCreated: function (v) { var self = this; this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { @@ -69,12 +82,13 @@ BI.Navigation = BI.inherit(BI.Widget, { if (type === BI.Events.CLICK) { self.fireEvent(BI.Navigation.EVENT_CHANGE, obj); } - }) + }); this.options.afterCardCreated.apply(this, arguments); }, afterCardShow: function (v) { this.showIndex = v; + this._deleteOtherCards(v); this.options.afterCardShow.apply(this, arguments); }, @@ -85,16 +99,23 @@ BI.Navigation = BI.inherit(BI.Widget, { } }, - setSelect: function (v) { - this.showIndex = v; + _assertCard: function () { if (!this.layout.isCardExisted(v)) { var card = this.options.cardCreator(v); this.cardMap[v] = card; this.layout.addCardByName(v, card); this.afterCardCreated(v); } + }, + + setSelect: function (v) { + this._assertCard(); this.layout.showCardByName(v); - BI.nextTick(BI.bind(this.afterCardShow, this, v)); + this._deleteOtherCards(v); + if (this.showIndex !== v) { + this.showIndex = v; + BI.nextTick(BI.bind(this.afterCardShow, this, v)); + } }, getSelect: function () { diff --git a/src/base/combination/tab.js b/src/base/combination/tab.js index 0c0b5e7fe..f3c1ea203 100644 --- a/src/base/combination/tab.js +++ b/src/base/combination/tab.js @@ -7,6 +7,7 @@ BI.Tab = BI.inherit(BI.Widget, { return BI.extend(BI.Tab.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-tab", direction: "top",//top, bottom, left, right, custom + single: false, //是不是单页面 logic: { dynamic: false }, @@ -46,6 +47,7 @@ BI.Tab = BI.inherit(BI.Widget, { return card; }, afterCardShow: function (v) { + self._deleteOtherCards(v); self.curr = v; } }); @@ -54,6 +56,18 @@ BI.Tab = BI.inherit(BI.Widget, { }); }, + _deleteOtherCards: function (currCardName) { + var self = this, o = this.options; + if (o.single === true) { + BI.each(this.cardMap, function (name, card) { + if (name !== (currCardName + "")) { + self.layout.deleteCardByName(name); + delete self.cardMap[name]; + } + }); + } + }, + _assertCard: function (v) { if (!this.layout.isCardExisted(v)) { var card = this.options.cardCreator(v); @@ -73,6 +87,7 @@ BI.Tab = BI.inherit(BI.Widget, { this.tab && this.tab.setValue(v); this._assertCard(v); this.layout.showCardByName(v); + this._deleteOtherCards(v); if (this.curr !== v) { this.curr = v; } diff --git a/src/core/wrapper/layout/layout.card.js b/src/core/wrapper/layout/layout.card.js index aa0921291..201b3ccbf 100644 --- a/src/core/wrapper/layout/layout.card.js +++ b/src/core/wrapper/layout/layout.card.js @@ -63,7 +63,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { isCardExisted: function (cardName) { return BI.some(this.options.items, function (i, item) { - return item.cardName === cardName && item.el; + return item.cardName == cardName && item.el; }); },