From d728980489d2089cf6ffc6ffa5f70b0f466afcd1 Mon Sep 17 00:00:00 2001 From: chaos0156 <429018715@qq.com> Date: Fri, 12 Aug 2022 14:14:25 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-12408=20chore:=20base/combination?= =?UTF-8?q?=E4=B8=ADeslint=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/collection/collection.js | 12 ++++++------ src/base/combination/bubble.js | 14 +++++++++----- src/base/combination/combo.js | 8 ++++++-- src/base/combination/expander.js | 6 +++++- src/base/combination/group.button.js | 24 ++++++++++++++++++++---- src/base/combination/group.combo.js | 2 +- src/base/combination/group.virtual.js | 7 ++++++- src/base/combination/loader.js | 10 +++++++--- src/base/combination/navigation.js | 5 +++-- src/base/combination/searcher.js | 12 +++++++++--- src/base/combination/switcher.js | 2 ++ src/base/combination/tab.js | 2 +- src/base/combination/tree.button.js | 25 +++++++++++++++++++++++-- 13 files changed, 98 insertions(+), 31 deletions(-) diff --git a/src/base/collection/collection.js b/src/base/collection/collection.js index d28adebf1..92d2b15eb 100644 --- a/src/base/collection/collection.js +++ b/src/base/collection/collection.js @@ -101,10 +101,10 @@ BI.CollectionView = BI.inherit(BI.Widget, { for (var index = 0, len = o.items.length; index < len; index++) { var cellMetadatum = o.cellSizeAndPositionGetter(index); - if (cellMetadatum.height === null || isNaN(cellMetadatum.height) || - cellMetadatum.width === null || isNaN(cellMetadatum.width) || - cellMetadatum.x === null || isNaN(cellMetadatum.x) || - cellMetadatum.y === null || isNaN(cellMetadatum.y)) { + if (BI.isNull(cellMetadatum.height) || isNaN(cellMetadatum.height) || + BI.isNull(cellMetadatum.width) || isNaN(cellMetadatum.width) || + BI.isNull(cellMetadatum.x) || isNaN(cellMetadatum.x) || + BI.isNull(cellMetadatum.y) || isNaN(cellMetadatum.y)) { throw Error(); } @@ -170,12 +170,12 @@ BI.CollectionView = BI.inherit(BI.Widget, { // 存储上下左右四个边界 var leftBorder = {}, rightBorder = {}, topBorder = {}, bottomBorder = {}; function assertMinBorder(border, offset) { - if (border[offset] === null) { + if (BI.isNull(border[offset])) { border[offset] = Number.MAX_VALUE; } } function assertMaxBorder(border, offset) { - if (border[offset] === null) { + if (BI.isNull(border[offset])) { border[offset] = 0; } } diff --git a/src/base/combination/bubble.js b/src/base/combination/bubble.js index f698b4a1a..288612a0c 100644 --- a/src/base/combination/bubble.js +++ b/src/base/combination/bubble.js @@ -6,6 +6,7 @@ BI.Bubble = BI.inherit(BI.Widget, { _defaultConfig: function () { var conf = BI.Bubble.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { baseCls: (conf.baseCls || "") + " bi-popper", attributes: { @@ -36,7 +37,7 @@ el: {}, popup: {}, comboClass: "bi-combo-popup", - hoverClass: "bi-combo-hover", + hoverClass: "bi-combo-hover" }); }, @@ -104,14 +105,14 @@ _initPullDownAction: function () { var self = this, o = this.options; var evs = (this.options.trigger || "").split(","); - var st = function (e) { + function st (e) { if (o.stopEvent) { e.stopEvent(); } if (o.stopPropagation) { e.stopPropagation(); } - }; + } var enterPopup = false; @@ -217,6 +218,8 @@ } }); break; + default: + break; } }); }, @@ -229,7 +232,7 @@ _assertPopupView: function () { var self = this, o = this.options; - if (this.popupView == null) { + if (BI.isNull(this.popupView)) { this.popupView = BI.createWidget(BI.isFunction(this.options.popup) ? this.options.popup() : this.options.popup, { type: "bi.bubble_popup_view", showArrow: o.showArrow, @@ -286,6 +289,7 @@ return; } this._hideView(e); + return true; }, @@ -319,7 +323,7 @@ }, _popupView: function (e) { - var self = this, o = this.options; + var o = this.options; this._assertPopupViewRender(); this.fireEvent(BI.Bubble.EVENT_BEFORE_POPUPVIEW); // popupVisible是为了获取其宽高, 放到可视范围之外以防止在IE下闪一下 diff --git a/src/base/combination/combo.js b/src/base/combination/combo.js index 27d00fc6a..c44338429 100644 --- a/src/base/combination/combo.js +++ b/src/base/combination/combo.js @@ -1,6 +1,7 @@ !(function () { var needHideWhenAnotherComboOpen = {}; var currentOpenedCombos = {}; + /** * @class BI.Combo * @extends BI.Widget @@ -11,6 +12,7 @@ }, _defaultConfig: function () { var conf = BI.Combo.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { baseCls: (conf.baseCls || "") + " bi-combo" + (BI.isIE() ? " hack" : ""), attributes: { @@ -107,7 +109,7 @@ _assertPopupView: function () { var self = this, o = this.options; - if (this.popupView == null) { + if (BI.isNull(this.popupView)) { this.popupView = BI.createWidget(BI.isFunction(this.options.popup) ? this.options.popup() : this.options.popup, { type: "bi.popup_view", showArrow: o.showArrow, @@ -280,10 +282,12 @@ delete p.adaptHeight; p.dir = "right"; break; + default: + break; } if ("adaptHeight" in p) { - this.resetListHeight(p["adaptHeight"]); + this.resetListHeight(p.adaptHeight); } var width = this.combo.element.outerWidth(); var height = this.combo.element.outerHeight(); diff --git a/src/base/combination/expander.js b/src/base/combination/expander.js index 407413c40..f3d87109b 100644 --- a/src/base/combination/expander.js +++ b/src/base/combination/expander.js @@ -126,6 +126,8 @@ BI.Expander = BI.inherit(BI.Widget, { })); } break; + default: + break; } }); }, @@ -136,7 +138,7 @@ BI.Expander = BI.inherit(BI.Widget, { _assertPopupView: function () { var self = this, o = this.options; - if (this.popupView == null) { + if (BI.isNull(this.popupView)) { this.popupView = BI.createWidget(this.options.popup, { type: "bi.button_group", cls: "expander-popup", @@ -255,6 +257,7 @@ BI.Expander = BI.inherit(BI.Widget, { if (this.expander.options.id === id) { return this.expander; } + return this.popupView && this.popupView.getNodeById(id); }, @@ -262,6 +265,7 @@ BI.Expander = BI.inherit(BI.Widget, { if (this.expander.getValue() === value) { return this.expander; } + return this.popupView && this.popupView.getNodeByValue(value); }, diff --git a/src/base/combination/group.button.js b/src/base/combination/group.button.js index b9e8f7127..a79c3cc4c 100644 --- a/src/base/combination/group.button.js +++ b/src/base/combination/group.button.js @@ -42,7 +42,6 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { }, _createBtns: function (items) { - var o = this.options; return BI.createWidgets(BI.createItems(items, { type: "bi.text_button" }), this); @@ -66,6 +65,8 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { case BI.ButtonGroup.CHOOSE_TYPE_NONE: self.setValue([]); break; + default: + break; } self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.ButtonGroup.EVENT_CHANGE, value, obj); @@ -84,7 +85,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { _packageBtns: function (btns) { var o = this.options; var layouts = BI.isArray(o.layouts) ? o.layouts : [o.layouts]; - for (var i = layouts.length - 1; i > 0; i--) { + for (let i = layouts.length - 1; i > 0; i--) { btns = BI.map(btns, function (k, it) { return BI.extend({}, layouts[i], { items: [ @@ -95,15 +96,18 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { }); }); } + return btns; }, _packageSimpleItems: function (btns) { var o = this.options; + return BI.map(o.items, function (i, item) { if (BI.stripEL(item) === item) { return btns[i]; } + return BI.extend({}, item, { el: btns[i] }); @@ -122,12 +126,14 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { lay = BI.formatEL(lay.items[0]).el; } lay.items = items; + return layout; }, // 如果是一个简单的layout _isSimpleLayout: function () { var o = this.options; + return BI.isArray(o.layouts) ? (o.layouts.length === 1 && !BI.isArray(o.items[0])) : true; }, @@ -140,12 +146,12 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { }, prependItems: function (items) { - var o = this.options; var btns = this._btnsCreator.apply(this, arguments); this.buttons = BI.concat(btns, this.buttons); if (this._isSimpleLayout() && this.layouts && this.layouts.prependItems) { this.layouts.prependItems(btns); + return; } @@ -154,13 +160,13 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { }, addItems: function (items) { - var o = this.options; var btns = this._btnsCreator.apply(this, arguments); this.buttons = BI.concat(this.buttons, btns); // 如果是一个简单的layout if (this._isSimpleLayout() && this.layouts && this.layouts.addItems) { this.layouts.addItems(btns); + return; } @@ -257,6 +263,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { v.push(item.getValue()); } }); + return v; }, @@ -267,6 +274,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { v.push(item.getValue()); } }); + return v; }, @@ -285,6 +293,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { btns.push(item); } }); + return btns; }, @@ -295,6 +304,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { btns.push(item); } }); + return btns; }, @@ -303,9 +313,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { BI.any(this.buttons, function (i, item) { if (item.isEnabled() && item.getValue() === value) { index = i; + return true; } }); + return index; }, @@ -314,9 +326,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { BI.any(this.buttons, function (i, item) { if (item.isEnabled() && item.options.id === id) { node = item; + return true; } }); + return node; }, @@ -325,9 +339,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { BI.any(this.buttons, function (i, item) { if (item.isEnabled() && item.getValue() === value) { node = item; + return true; } }); + return node; }, diff --git a/src/base/combination/group.combo.js b/src/base/combination/group.combo.js index 7c07445ee..9e4d56749 100644 --- a/src/base/combination/group.combo.js +++ b/src/base/combination/group.combo.js @@ -15,7 +15,7 @@ BI.ComboGroup = BI.inherit(BI.Widget, { isNeedAdjustHeight: false, isNeedAdjustWidth: false, - el: {type: "bi.text_button", text: "", value: ""}, + el: { type: "bi.text_button", text: "", value: "" }, items: [], popup: { diff --git a/src/base/combination/group.virtual.js b/src/base/combination/group.virtual.js index d42c7a5b7..7efe85716 100644 --- a/src/base/combination/group.virtual.js +++ b/src/base/combination/group.virtual.js @@ -29,9 +29,10 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { var o = this.options; var map = this.buttonMap = {}; var layouts = BI.isArray(o.layouts) ? o.layouts : [o.layouts]; - for (var i = layouts.length - 1; i > 0; i--) { + for (let i = layouts.length - 1; i > 0; i--) { items = BI.map(items, function (k, it) { var el = BI.stripEL(it); + return BI.extend({}, layouts[i], { items: [ BI.extend({}, layouts[i].el, { @@ -47,6 +48,7 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { }); }); } + return items; }, @@ -60,6 +62,7 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { lay = BI.formatEL(lay.items[0]).el; } lay.items = items; + return layout; }, @@ -93,6 +96,7 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { } } }); + return v; }, @@ -119,6 +123,7 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { } } }); + return v; }, diff --git a/src/base/combination/loader.js b/src/base/combination/loader.js index a56e72708..b873d09c0 100644 --- a/src/base/combination/loader.js +++ b/src/base/combination/loader.js @@ -38,7 +38,7 @@ BI.Loader = BI.inherit(BI.Widget, { _prevLoad: function () { var self = this, o = this.options; this.prev.setLoading(); - o.itemsCreator.apply(this, [{times: --this.times}, function () { + o.itemsCreator.apply(this, [{ times: --this.times }, function () { self.prev.setLoaded(); self.prependItems.apply(self, arguments); }]); @@ -47,7 +47,7 @@ BI.Loader = BI.inherit(BI.Widget, { _nextLoad: function () { var self = this, o = this.options; this.next.setLoading(); - o.itemsCreator.apply(this, [{times: ++this.times}, function () { + o.itemsCreator.apply(this, [{ times: ++this.times }, function () { self.next.setLoaded(); self.addItems.apply(self, arguments); }]); @@ -122,6 +122,7 @@ BI.Loader = BI.inherit(BI.Widget, { if (BI.isNumber(o.count)) { return this.count < o.count; } + return !!o.hasPrev.apply(this, [{ times: this.times, count: this.count @@ -133,6 +134,7 @@ BI.Loader = BI.inherit(BI.Widget, { if (BI.isNumber(o.count)) { return this.count < o.count; } + return !!o.hasNext.apply(this, [{ times: this.times, count: this.count @@ -168,13 +170,14 @@ BI.Loader = BI.inherit(BI.Widget, { _populate: function (items) { var self = this, o = this.options; if (arguments.length === 0 && (BI.isFunction(o.itemsCreator))) { - o.itemsCreator.apply(this, [{times: 1}, function () { + o.itemsCreator.apply(this, [{ times: 1 }, function () { if (arguments.length === 0) { throw new Error("参数不能为空"); } self.populate.apply(self, arguments); o.onLoaded(); }]); + return false; } this.options.items = items; @@ -195,6 +198,7 @@ BI.Loader = BI.inherit(BI.Widget, { this.prev.invisible(); } } + return true; }, diff --git a/src/base/combination/navigation.js b/src/base/combination/navigation.js index b2d5ae867..7223a1c5f 100644 --- a/src/base/combination/navigation.js +++ b/src/base/combination/navigation.js @@ -23,7 +23,7 @@ BI.Navigation = BI.inherit(BI.Widget, { render: function () { var self = this, o = this.options; - this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"}); + this.tab = BI.createWidget(this.options.tab, { type: "bi.button_group" }); this.cardMap = {}; this.showIndex = 0; this.layout = BI.createWidget({ @@ -45,6 +45,7 @@ BI.Navigation = BI.inherit(BI.Widget, { cardCreator: function (v) { var card = o.cardCreator(v); self.cardMap[v] = card; + return card; }, afterCardCreated: BI.bind(this.afterCardCreated, this), @@ -54,7 +55,7 @@ BI.Navigation = BI.inherit(BI.Widget, { if (BI.isFunction(o.showIndex)) { this.__watch(o.showIndex, function (context, newValue) { self.setSelect(newValue); - }) + }); } }, diff --git a/src/base/combination/searcher.js b/src/base/combination/searcher.js index 0989b4c8a..14efe2e77 100644 --- a/src/base/combination/searcher.js +++ b/src/base/combination/searcher.js @@ -82,6 +82,8 @@ BI.Searcher = BI.inherit(BI.Widget, { self._pauseSearch(); } break; + default: + break; } }); }, @@ -109,6 +111,8 @@ BI.Searcher = BI.inherit(BI.Widget, { values.push(obj.getValue()); o.adapter && o.adapter.setValue(values); break; + default: + break; } } self.fireEvent(BI.Searcher.EVENT_CHANGE, value, obj); @@ -140,7 +144,6 @@ BI.Searcher = BI.inherit(BI.Widget, { }, _pauseSearch: function () { - var o = this.options, name = this.getName(); this._stop = true; BI.nextTick(function (name) { BI.Maskers.hide(name); @@ -153,7 +156,7 @@ BI.Searcher = BI.inherit(BI.Widget, { }, _stopSearch: function () { - var o = this.options, name = this.getName(); + var name = this.getName(); this._stop = true; BI.Maskers.hide(name); if (this._isSearching === true) { @@ -175,6 +178,7 @@ BI.Searcher = BI.inherit(BI.Widget, { this.popupView.populate(find, match, keyword); o.isAutoSync && o.adapter && o.adapter.getValue && this.popupView.setValue(o.adapter.getValue()); self.fireEvent(BI.Searcher.EVENT_SEARCHING); + return; } this.popupView.loading && this.popupView.loading(); @@ -203,6 +207,7 @@ BI.Searcher = BI.inherit(BI.Widget, { if (BI.isEmptyString(res[res.length - 1])) { res = res.slice(0, res.length - 1); } + return BI.isNull(res) ? "" : res[res.length - 1]; } }, @@ -246,6 +251,7 @@ BI.Searcher = BI.inherit(BI.Widget, { hasMatched: function () { this._assertPopupView(); + return this.popupView.hasMatched(); }, @@ -288,8 +294,8 @@ BI.Searcher = BI.inherit(BI.Widget, { if (BI.isNull(this.popupView)) { return o.popup.value; } - return this.popupView.getValue(); + return this.popupView.getValue(); }, populate: function (result, searchResult, keyword) { diff --git a/src/base/combination/switcher.js b/src/base/combination/switcher.js index 1a929f704..ce0a623e2 100644 --- a/src/base/combination/switcher.js +++ b/src/base/combination/switcher.js @@ -265,6 +265,7 @@ BI.Switcher = BI.inherit(BI.Widget, { if (this.switcher.attr("id") === id) { return this.switcher; } + return this.popupView && this.popupView.getNodeById(id); }, @@ -272,6 +273,7 @@ BI.Switcher = BI.inherit(BI.Widget, { if (this.switcher.getValue() === value) { return this.switcher; } + return this.popupView && this.popupView.getNodeByValue(value); }, diff --git a/src/base/combination/tab.js b/src/base/combination/tab.js index 90a788a17..3020859f5 100644 --- a/src/base/combination/tab.js +++ b/src/base/combination/tab.js @@ -112,7 +112,7 @@ BI.Tab = BI.inherit(BI.Widget, { }, removeTab: function (cardname) { - var self = this, o = this.options; + var self = this; BI.any(this.cardMap, function (name, card) { if (BI.isEqual(name, (cardname + ""))) { self.layout.deleteCardByName(name); diff --git a/src/base/combination/tree.button.js b/src/base/combination/tree.button.js index 45b436b8a..457c5afd5 100644 --- a/src/base/combination/tree.button.js +++ b/src/base/combination/tree.button.js @@ -16,6 +16,7 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (!BI.isFunction(item.setSelected)) { item.setNotSelectedValue(v); + return; } if (BI.deepContains(v, item.getValue())) { @@ -31,6 +32,7 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (BI.isFunction(item.setEnabledValue)) { item.setEnabledValue(v); + return; } if (BI.deepContains(v, item.getValue())) { @@ -46,6 +48,7 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (!BI.isFunction(item.setSelected)) { item.setValue(v); + return; } if (BI.deepContains(v, item.getValue())) { @@ -61,12 +64,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { v = BI.concat(v, item.getNotSelectedValue()); + return; } if (item.isEnabled() && item.isSelected && !item.isSelected()) { v.push(item.getValue()); } }); + return v; }, @@ -75,12 +80,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { v = BI.concat(v, item.getValue()); + return; } if (item.isEnabled() && item.isSelected && item.isSelected()) { v.push(item.getValue()); } }); + return v; }, @@ -89,12 +96,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { btns = btns.concat(item.getSelectedButtons()); + return; } if (item.isSelected && item.isSelected()) { btns.push(item); } }); + return btns; }, @@ -103,12 +112,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { btns = btns.concat(item.getNotSelectedButtons()); + return; } if (item.isSelected && !item.isSelected()) { btns.push(item); } }); + return btns; }, @@ -118,12 +129,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.each(this.buttons, function (i, item) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) { leaves = leaves.concat(item.getAllLeaves()); + return; } if (item.isEnabled()) { leaves.push(item); } }); + return leaves; }, @@ -133,9 +146,11 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { var vs = item.getValue(); if (item.isEnabled() && (vs === value || BI.contains(vs, value))) { index = i; + return true; } }); + return index; }, @@ -145,14 +160,17 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { if (item.isEnabled()) { if (item.attr("id") === id) { node = item; + return true; } else if (BI.isFunction(item.getNodeById)) { - if (node = item.getNodeById(id)) { + node = item.getNodeById(id); + if (node) { return true; } } } }); + return node; }, @@ -161,15 +179,18 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.any(this.buttons, function (i, item) { if (item.isEnabled()) { if (BI.isFunction(item.getNodeByValue)) { - if (node = item.getNodeByValue(value)) { + node = item.getNodeByValue(value); + if (node) { return true; } } else if (item.attr("value") === value) { node = item; + return true; } } }); + return node; } });