From e06221784778fceebbd8b6275e5b02350e3b5c41 Mon Sep 17 00:00:00 2001 From: impact Date: Tue, 3 Jan 2023 16:53:20 +0800 Subject: [PATCH 1/7] =?UTF-8?q?KERNEL-13948=20docs:=20=E4=BF=AE=E5=A4=8Dco?= =?UTF-8?q?mbo=5Fgroup=20demo=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/js/core/abstract/combination/demo.combo.js | 4 ++-- demo/js/core/abstract/combination/demo.combo_group.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/demo/js/core/abstract/combination/demo.combo.js b/demo/js/core/abstract/combination/demo.combo.js index 2ec3619b1..fd7765b85 100644 --- a/demo/js/core/abstract/combination/demo.combo.js +++ b/demo/js/core/abstract/combination/demo.combo.js @@ -29,7 +29,7 @@ Demo.Func = BI.inherit(BI.Widget, { iconCls1: "close-ha-font", iconCls2: "close-ha-font" }, - children: [{ + items: [{ type: "bi.single_select_item", height: 25, text: "一月", @@ -385,7 +385,7 @@ Demo.Func = BI.inherit(BI.Widget, { }, width: 200 }); - childCombo.setValue(BI.deepClone(this.child)[0].children[0].value); + childCombo.setValue(BI.deepClone(this.child)[0].items[0].value); var monthCombo = BI.createWidget({ type: "bi.combo", diff --git a/demo/js/core/abstract/combination/demo.combo_group.js b/demo/js/core/abstract/combination/demo.combo_group.js index aeb9a1936..2cd391b7d 100644 --- a/demo/js/core/abstract/combination/demo.combo_group.js +++ b/demo/js/core/abstract/combination/demo.combo_group.js @@ -12,7 +12,7 @@ Demo.Func = BI.inherit(BI.Widget, { height: 25, iconCls: "close-ha-font" }, - children: [{ + items: [{ type: "bi.single_select_item", height: 25, text: "一月", @@ -63,7 +63,7 @@ Demo.Func = BI.inherit(BI.Widget, { }, width: 200 }); - childCombo.setValue(BI.deepClone(this.child)[0].children[0].value); + childCombo.setValue(BI.deepClone(this.child)[0].items[0].value); return BI.createWidget({ type: "bi.left", From 4edb0d9b23139d38d3913765396c6c49d69d61b3 Mon Sep 17 00:00:00 2001 From: impact Date: Tue, 3 Jan 2023 17:09:42 +0800 Subject: [PATCH 2/7] =?UTF-8?q?KERNEL-13948=20refactor:=20base/combination?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9ES6=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/0.base.js | 5 +- src/base/combination/bubble.js | 972 +++++++++++++------------- src/base/combination/combo.js | 682 +++++++++--------- src/base/combination/expander.js | 245 +++---- src/base/combination/group.button.js | 326 ++++----- src/base/combination/group.combo.js | 98 +-- src/base/combination/group.virtual.js | 130 ++-- src/base/combination/loader.js | 221 +++--- src/base/combination/navigation.js | 162 ++--- src/base/combination/searcher.js | 306 ++++---- src/base/combination/switcher.js | 278 ++++---- src/base/combination/tab.js | 177 ++--- src/base/combination/tree.button.js | 142 ++-- src/base/index.js | 40 +- src/core/index.js | 3 + src/core/listener/listener.show.js | 52 +- 16 files changed, 1965 insertions(+), 1874 deletions(-) diff --git a/src/base/0.base.js b/src/base/0.base.js index 3d342a8d3..2b4960808 100644 --- a/src/base/0.base.js +++ b/src/base/0.base.js @@ -7,7 +7,8 @@ import { PopoverController, ResizeController, TooltipsController, - StyleLoaderManager + StyleLoaderManager, + extend } from "../core"; const Resizers = new ResizeController(); @@ -20,7 +21,7 @@ const Drawers = new DrawerController(); const Broadcasts = new BroadcastController(); const StyleLoaders = new StyleLoaderManager(); -BI.extend(BI, { +extend(BI, { Resizers, Layers, Maskers, diff --git a/src/base/combination/bubble.js b/src/base/combination/bubble.js index 7b5f57736..5d9e9e86a 100644 --- a/src/base/combination/bubble.js +++ b/src/base/combination/bubble.js @@ -1,513 +1,515 @@ -!(function () { - /** - * @class BI.Bubble - * @extends BI.Widget - */ - 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: { - tabIndex: -1, - }, - trigger: "click", // click || hover || click-hover || "hover-click" || "" - toggle: true, - direction: "", - placement: "bottom-start", // top-start/top/top-end/bottom-start/bottom/bottom-end/left-start/left/left-end/right-start/right/right-end - logic: { - dynamic: true, - }, - container: null, // popupview放置的容器,默认为this.element - isDefaultInit: false, - destroyWhenHide: false, - hideWhenClickOutside: true, - showArrow: true, - hideWhenBlur: false, - isNeedAdjustHeight: true, // 是否需要高度调整 - isNeedAdjustWidth: true, - stopEvent: false, - stopPropagation: false, - adjustLength: 0, // 调整的距离 - adjustXOffset: 0, - adjustYOffset: 0, - hideChecker: BI.emptyFn, - offsetStyle: "left", // left,right,center - el: {}, - popup: {}, - comboClass: "bi-combo-popup", - hoverClass: "bi-combo-hover", - }); - }, - - render: function () { - var self = this, o = this.options; - this._initCombo(); - // 延迟绑定事件,这样可以将自己绑定的事情优先执行 - BI.nextTick(() => { - !this.isDestroyed() && this._initPullDownAction(); - }); - this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - if (self.isEnabled() && self.isValid()) { - if (type === BI.Events.EXPAND) { - self._popupView(); - } - if (type === BI.Events.COLLAPSE) { - self._hideView(); - } - if (type === BI.Events.EXPAND) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - self.fireEvent(BI.Bubble.EVENT_EXPAND); - } - if (type === BI.Events.COLLAPSE) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - self.isViewVisible() && self.fireEvent(BI.Bubble.EVENT_COLLAPSE); - } - if (type === BI.Events.CLICK) { - self.fireEvent(BI.Bubble.EVENT_TRIGGER_CHANGE, obj); - } +/** + * @class BI.Bubble + * @extends BI.Widget + */ +import { shortcut, Widget, Controller, extend, nextTick, createWidget, each, defer, debounce, delay, isNull, isFunction, contains, bind } from "../../core"; + +@shortcut() +export default class Bubble extends Widget { + static xtype = "bi.bubble"; + + static EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; + static EVENT_CHANGE = "EVENT_CHANGE"; + static EVENT_EXPAND = "EVENT_EXPAND"; + static EVENT_COLLAPSE = "EVENT_COLLAPSE"; + static EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; + + static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; + static EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; + static EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; + static EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; + + _defaultConfig() { + const conf = super._defaultConfig(arguments); + + return extend(conf, { + baseCls: (conf.baseCls || "") + " bi-popper", + attributes: { + tabIndex: -1, + }, + trigger: "click", // click || hover || click-hover || "hover-click" || "" + toggle: true, + direction: "", + placement: "bottom-start", // top-start/top/top-end/bottom-start/bottom/bottom-end/left-start/left/left-end/right-start/right/right-end + logic: { + dynamic: true, + }, + container: null, // popupview放置的容器,默认为this.element + isDefaultInit: false, + destroyWhenHide: false, + hideWhenClickOutside: true, + showArrow: true, + hideWhenBlur: false, + isNeedAdjustHeight: true, // 是否需要高度调整 + isNeedAdjustWidth: true, + stopEvent: false, + stopPropagation: false, + adjustLength: 0, // 调整的距离 + adjustXOffset: 0, + adjustYOffset: 0, + hideChecker: BI.emptyFn, + offsetStyle: "left", // left,right,center + el: {}, + popup: {}, + comboClass: "bi-combo-popup", + hoverClass: "bi-combo-hover", + }); + } + + render() { + const { hoverClass, logic, isDefaultInit } = this.options; + this._initCombo(); + // 延迟绑定事件,这样可以将自己绑定的事情优先执行 + nextTick(() => { + !this.isDestroyed() && this._initPullDownAction(); + }); + this.combo.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => { + if (this.isEnabled() && this.isValid()) { + if (type === BI.Events.EXPAND) { + this._popupView(); } - }); - - self.element.on("mouseenter." + self.getName(), function (e) { - if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) { - self.element.addClass(o.hoverClass); + if (type === BI.Events.COLLAPSE) { + this._hideView(); } - }); - self.element.on("mouseleave." + self.getName(), function (e) { - if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) { - self.element.removeClass(o.hoverClass); + if (type === BI.Events.EXPAND) { + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); + this.fireEvent(Bubble.EVENT_EXPAND); } - }); - - BI.createWidget(BI.extend({ - element: this, - scrolly: false, - }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { - items: [ - { el: this.combo } - ], - })))); - o.isDefaultInit && (this._assertPopupView()); - }, - - _toggle: function (e) { - this._assertPopupViewRender(); - if (this.popupView.isVisible()) { - this._hideView(e); - } else { - if (this.isEnabled()) { - this._popupView(e); + if (type === BI.Events.COLLAPSE) { + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); + this.isViewVisible() && this.fireEvent(Bubble.EVENT_COLLAPSE); + } + if (type === BI.Events.CLICK) { + this.fireEvent(Bubble.EVENT_TRIGGER_CHANGE, obj); } } - }, + }); - _initPullDownAction: function () { - var self = this, o = this.options; - var evs = (this.options.trigger || "").split(","); - - function st(e) { - if (o.stopEvent) { - e.stopEvent(); - } - if (o.stopPropagation) { - e.stopPropagation(); - } + this.element.on("mouseenter." + this.getName(), (e) => { + if (this.isEnabled() && this.isValid() && this.combo.isEnabled() && this.combo.isValid()) { + this.element.addClass(hoverClass); + } + }); + this.element.on("mouseleave." + this.getName(), (e) => { + if (this.isEnabled() && this.isValid() && this.combo.isEnabled() && this.combo.isValid()) { + this.element.removeClass(hoverClass); + } + }); + + createWidget(extend({ + element: this, + scrolly: false, + }, BI.LogicFactory.createLogic("vertical", extend(logic, { + items: [ + { el: this.combo } + ], + })))); + isDefaultInit && (this._assertPopupView()); + } + + _toggle(e) { + this._assertPopupViewRender(); + if (this.popupView.isVisible()) { + this._hideView(e); + } else { + if (this.isEnabled()) { + this._popupView(e); } + } + } - var enterPopup = false; + _initPullDownAction() { + const { stopEvent, stopPropagation, toggle } = this.options; + const evs = (this.options.trigger || "").split(","); - function hide(e) { - if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid() && o.toggle === true) { - self._hideView(e); - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.combo); - self.fireEvent(BI.Bubble.EVENT_COLLAPSE); - } - self.popupView && self.popupView.element.off("mouseenter." + self.getName()).off("mouseleave." + self.getName()); - enterPopup = false; + const st = (e) => { + if (stopEvent) { + e.stopEvent(); } + if (stopPropagation) { + e.stopPropagation(); + } + } - BI.each(evs, function (i, ev) { - switch (ev) { - case "hover": - self.element.on("mouseenter." + self.getName(), function (e) { - if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) { - self._popupView(e); - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo); - self.fireEvent(BI.Bubble.EVENT_EXPAND); - } - }); - self.element.on("mouseleave." + self.getName(), function (e) { - if (self.popupView) { - self.popupView.element.on("mouseenter." + self.getName(), function (e) { - enterPopup = true; - self.popupView.element.on("mouseleave." + self.getName(), function (e) { - hide(e); - }); - self.popupView.element.off("mouseenter." + self.getName()); + let enterPopup = false; + + const hide = (e) => { + if (this.isEnabled() && this.isValid() && this.combo.isEnabled() && this.combo.isValid() && toggle === true) { + this._hideView(e); + this.fireEvent(Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", this.combo); + this.fireEvent(Bubble.EVENT_COLLAPSE); + } + this.popupView && this.popupView.element.off("mouseenter." + this.getName()).off("mouseleave." + this.getName()); + enterPopup = false; + } + + each(evs, (i, ev) => { + let debounced; + switch (ev) { + case "hover": + this.element.on("mouseenter." + this.getName(), (e) => { + if (this.isEnabled() && this.isValid() && this.combo.isEnabled() && this.combo.isValid()) { + this._popupView(e); + this.fireEvent(Controller.EVENT_CHANGE, BI.Events.EXPAND, "", this.combo); + this.fireEvent(Bubble.EVENT_EXPAND); + } + }); + this.element.on("mouseleave." + this.getName(), (e) => { + if (this.popupView) { + this.popupView.element.on("mouseenter." + this.getName(), (e) => { + enterPopup = true; + this.popupView.element.on("mouseleave." + this.getName(), (e) => { + hide(e); }); - BI.defer(function () { - if (!enterPopup) { - hide(e); - } - }, 50); - } - }); - break; - case "click": - var debounce = BI.debounce(function (e) { - if (self.combo.element.__isMouseInBounds__(e)) { - if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) { - // if (!o.toggle && self.isViewVisible()) { - // return; - // } - o.toggle ? self._toggle(e) : self._popupView(e); - if (self.isViewVisible()) { - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo); - self.fireEvent(BI.Bubble.EVENT_EXPAND); - } else { - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.combo); - self.fireEvent(BI.Bubble.EVENT_COLLAPSE); - } + this.popupView.element.off("mouseenter." + this.getName()); + }); + defer(() => { + if (!enterPopup) { + hide(e); + } + }, 50); + } + }); + break; + case "click": + debounced = debounce((e) => { + if (this.combo.element.__isMouseInBounds__(e)) { + if (this.isEnabled() && this.isValid() && this.combo.isEnabled() && this.combo.isValid()) { + // if (!o.toggle && this.isViewVisible()) { + // return; + // } + toggle ? this._toggle(e) : this._popupView(e); + if (this.isViewVisible()) { + this.fireEvent(Controller.EVENT_CHANGE, BI.Events.EXPAND, "", this.combo); + this.fireEvent(Bubble.EVENT_EXPAND); + } else { + this.fireEvent(Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", this.combo); + this.fireEvent(Bubble.EVENT_COLLAPSE); } } - }, BI.EVENT_RESPONSE_TIME, { - "leading": true, - "trailing": false, - }); - self.element.off(ev + "." + self.getName()).on(ev + "." + self.getName(), function (e) { - debounce(e); - st(e); - }); - break; - case "click-hover": - var debounce = BI.debounce(function (e) { - if (self.combo.element.__isMouseInBounds__(e)) { - if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) { - // if (self.isViewVisible()) { - // return; - // } - self._popupView(e); - if (self.isViewVisible()) { - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo); - self.fireEvent(BI.Bubble.EVENT_EXPAND); - } + } + }, BI.EVENT_RESPONSE_TIME, { + "leading": true, + "trailing": false, + }); + this.element.off(ev + "." + this.getName()).on(ev + "." + this.getName(), (e) => { + debounced(e); + st(e); + }); + break; + case "click-hover": + debounced = debounce((e) => { + if (this.combo.element.__isMouseInBounds__(e)) { + if (this.isEnabled() && this.isValid() && this.combo.isEnabled() && this.combo.isValid()) { + // if (this.isViewVisible()) { + // return; + // } + this._popupView(e); + if (this.isViewVisible()) { + this.fireEvent(Controller.EVENT_CHANGE, BI.Events.EXPAND, "", this.combo); + this.fireEvent(Bubble.EVENT_EXPAND); } } - }, BI.EVENT_RESPONSE_TIME, { - "leading": true, - "trailing": false, - }); - self.element.off("click." + self.getName()).on("click." + self.getName(), function (e) { - debounce(e); - st(e); - }); - self.element.on("mouseleave." + self.getName(), function (e) { - if (self.popupView) { - self.popupView.element.on("mouseenter." + self.getName(), function (e) { - enterPopup = true; - self.popupView.element.on("mouseleave." + self.getName(), function (e) { - hide(e); - }); - self.popupView.element.off("mouseenter." + self.getName()); + } + }, BI.EVENT_RESPONSE_TIME, { + "leading": true, + "trailing": false, + }); + this.element.off("click." + this.getName()).on("click." + this.getName(), (e) => { + debounced(e); + st(e); + }); + this.element.on("mouseleave." + this.getName(), (e) => { + if (this.popupView) { + this.popupView.element.on("mouseenter." + this.getName(), (e) => { + enterPopup = true; + this.popupView.element.on("mouseleave." + this.getName(), (e) => { + hide(e); }); - BI.delay(function () { - if (!enterPopup) { - hide(e); - } - }, 50); - } - }); - break; - case "hover-click": - self.element.on("mouseenter." + self.getName(), function (e) { - if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) { - self._popupView(e); - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo); - self.fireEvent(BI.Bubble.EVENT_EXPAND); - } - }); - break; - default: - break; + this.popupView.element.off("mouseenter." + this.getName()); + }); + delay(() => { + if (!enterPopup) { + hide(e); + } + }, 50); + } + }); + break; + case "hover-click": + this.element.on("mouseenter." + this.getName(), (e) => { + if (this.isEnabled() && this.isValid() && this.combo.isEnabled() && this.combo.isValid()) { + this._popupView(e); + this.fireEvent(Controller.EVENT_CHANGE, BI.Events.EXPAND, "", this.combo); + this.fireEvent(Bubble.EVENT_EXPAND); + } + }); + break; + default: + break; + } + }); + } + + _initCombo() { + this.combo = createWidget(this.options.el, { + value: this.options.value, + }); + } + + _assertPopupView() { + const { showArrow, value } = this.options; + if (isNull(this.popupView)) { + this.popupView = createWidget(isFunction(this.options.popup) ? this.options.popup() : this.options.popup, { + type: "bi.bubble_popup_view", + showArrow, + value, + }, this); + this.popupView.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => { + if (type === BI.Events.CLICK) { + this.combo.setValue(this.getValue()); + this.fireEvent(Bubble.EVENT_CHANGE, value, obj); } + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); }); - }, - - _initCombo: function () { - this.combo = BI.createWidget(this.options.el, { - value: this.options.value, + this.popupView.setVisible(false); + nextTick(() => { + this.fireEvent(Bubble.EVENT_AFTER_INIT); }); - }, - - _assertPopupView: function () { - var self = this, o = this.options; - 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, - value: o.value, - }, this); - this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - if (type === BI.Events.CLICK) { - self.combo.setValue(self.getValue()); - self.fireEvent(BI.Bubble.EVENT_CHANGE, value, obj); - } - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - this.popupView.setVisible(false); - BI.nextTick(function () { - self.fireEvent(BI.Bubble.EVENT_AFTER_INIT); - }); - } - }, - - _assertPopupViewRender: function () { - this._assertPopupView(); - if (!this._rendered) { - BI.createWidget({ - type: "bi.vertical", - scrolly: false, - element: BI.isFunction(this.options.container) ? this.options.container() : (this.options.container || this), - items: [ - { el: this.popupView } - ], - }); - this._rendered = true; - } - }, - - _hideIf: function (e, skipTriggerChecker) { - // if (this.element.__isMouseInBounds__(e) || (this.popupView && this.popupView.element.__isMouseInBounds__(e))) { - // return; - // } - // BI-10290 公式combo双击公式内容会收起 - if (e && ((skipTriggerChecker !== true && this.element.find(e.target).length > 0) - || (this.popupView && this.popupView.element.find(e.target).length > 0) - || e.target.className === "CodeMirror-cursor" || BI.Widget._renderEngine.createElement(e.target).closest(".CodeMirror-hints").length > 0)) {// BI-9887 CodeMirror的公式弹框需要特殊处理下 - var directions = this.options.direction.split(","); - if (BI.contains(directions, "innerLeft") || BI.contains(directions, "innerRight")) { - // popup可以出现在trigger内部的combo,滚动时不需要消失,而是调整位置 - this.adjustWidth(); - this.adjustHeight(); - } - - return; - } - var isHide = this.options.hideChecker.apply(this, [e]); - if (isHide === false) { - return; - } - this._hideView(e); - - return true; - }, - - _hideView: function (e) { - var o = this.options; - this.fireEvent(BI.Bubble.EVENT_BEFORE_HIDEVIEW); - if (this.options.destroyWhenHide === true) { - this.popupView && this.popupView.destroy(); - this.popupView = null; - this._rendered = false; - } else { - this.popupView && this.popupView.invisible(); - } - - if (!e || !this.combo.element.__isMouseInBounds__(e)) { - this.element.removeClass(this.options.hoverClass); - // 应对bi-focus-shadow在收起时不失焦 - this.element.blur(); - } - - if (this.popper) { - this.popper.destroy(); - this.popper = null; + } + } + + _assertPopupViewRender() { + this._assertPopupView(); + if (!this._rendered) { + createWidget({ + type: "bi.vertical", + scrolly: false, + element: isFunction(this.options.container) ? this.options.container() : (this.options.container || this), + items: [ + { el: this.popupView } + ], + }); + this._rendered = true; + } + } + + _hideIf(e, skipTriggerChecker) { + // if (this.element.__isMouseInBounds__(e) || (this.popupView && this.popupView.element.__isMouseInBounds__(e))) { + // return; + // } + // BI-10290 公式combo双击公式内容会收起 + if (e && ((skipTriggerChecker !== true && this.element.find(e.target).length > 0) + || (this.popupView && this.popupView.element.find(e.target).length > 0) + || e.target.className === "CodeMirror-cursor" || Widget._renderEngine.createElement(e.target).closest(".CodeMirror-hints").length > 0)) {// BI-9887 CodeMirror的公式弹框需要特殊处理下 + const directions = this.options.direction.split(","); + if (contains(directions, "innerLeft") || contains(directions, "innerRight")) { + // popup可以出现在trigger内部的combo,滚动时不需要消失,而是调整位置 + this.adjustWidth(); + this.adjustHeight(); } - this.element.removeClass(this.options.comboClass); - - BI.Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()).unbind("mousewheel." + this.getName()); - BI.EVENT_BLUR && o.hideWhenBlur && BI.Widget._renderEngine.createElement(window).unbind("blur." + this.getName()); - this.fireEvent(BI.Bubble.EVENT_AFTER_HIDEVIEW); - }, - - _popupView: function (e) { - var o = this.options; - this._assertPopupViewRender(); - this.fireEvent(BI.Bubble.EVENT_BEFORE_POPUPVIEW); - // popupVisible是为了获取其宽高, 放到可视范围之外以防止在IE下闪一下 - // this.popupView.css({left: -999999999, top: -99999999}); - this.popupView.visible(); - this.adjustWidth(e); - - if (this.popper) { - this.popper.destroy(); - } - var modifiers = [ - { - name: "offset", - options: { - offset: function () { - return [o.adjustXOffset, (o.showArrow ? 12 : 0) + (o.adjustYOffset + o.adjustLength)]; - }, - }, - } - ]; - if (this.options.showArrow) { - modifiers.push({ - name: "arrow", - options: { - padding: 4, - element: this.popupView.arrow.element[0], + return; + } + const isHide = this.options.hideChecker.apply(this, [e]); + if (isHide === false) { + return; + } + this._hideView(e); + + return true; + } + + _hideView(e) { + const { hideWhenBlur } = this.options; + this.fireEvent(Bubble.EVENT_BEFORE_HIDEVIEW); + if (this.options.destroyWhenHide === true) { + this.popupView && this.popupView.destroy(); + this.popupView = null; + this._rendered = false; + } else { + this.popupView && this.popupView.invisible(); + } + + if (!e || !this.combo.element.__isMouseInBounds__(e)) { + this.element.removeClass(this.options.hoverClass); + // 应对bi-focus-shadow在收起时不失焦 + this.element.blur(); + } + + if (this.popper) { + this.popper.destroy(); + this.popper = null; + } + + this.element.removeClass(this.options.comboClass); + + Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()).unbind("mousewheel." + this.getName()); + BI.EVENT_BLUR && hideWhenBlur && Widget._renderEngine.createElement(window).unbind("blur." + this.getName()); + this.fireEvent(Bubble.EVENT_AFTER_HIDEVIEW); + } + + _popupView(e) { + const { adjustXOffset, showArrow, adjustYOffset, adjustLength, placement, hideWhenClickOutside, hideWhenBlur } = this.options; + this._assertPopupViewRender(); + this.fireEvent(Bubble.EVENT_BEFORE_POPUPVIEW); + // popupVisible是为了获取其宽高, 放到可视范围之外以防止在IE下闪一下 + // this.popupView.css({left: -999999999, top: -99999999}); + this.popupView.visible(); + this.adjustWidth(e); + + if (this.popper) { + this.popper.destroy(); + } + const modifiers = [ + { + name: "offset", + options: { + offset: () => { + return [adjustXOffset, (showArrow ? 12 : 0) + (adjustYOffset + adjustLength)]; }, - }); + }, } - this.popper = BI.Popper.createPopper(this.combo.element[0], this.popupView.element[0], { - placement: o.placement, - strategy: "fixed", - modifiers: modifiers, + ]; + if (this.options.showArrow) { + modifiers.push({ + name: "arrow", + options: { + padding: 4, + element: this.popupView.arrow.element[0], + }, }); - - // this.adjustHeight(e); - - this.element.addClass(this.options.comboClass); - o.hideWhenClickOutside && BI.Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()); - BI.EVENT_BLUR && o.hideWhenBlur && BI.Widget._renderEngine.createElement(window).unbind("blur." + this.getName()); - - o.hideWhenClickOutside && BI.Widget._renderEngine.createElement(document).bind("mousedown." + this.getName(), BI.bind(this._hideIf, this)); - BI.EVENT_BLUR && o.hideWhenBlur && BI.Widget._renderEngine.createElement(window).bind("blur." + this.getName(), BI.bind(this._hideIf, this)); - this.fireEvent(BI.Bubble.EVENT_AFTER_POPUPVIEW); - }, - - adjustWidth: function (e) { - var o = this.options; - if (!this.popupView) { - return; - } - if (o.isNeedAdjustWidth === true) { - this.resetListWidth(""); - var width = this.popupView.element.outerWidth(); - var maxW = this.element.outerWidth() || o.width; - // BI-93885 最大列宽算法调整 - if (maxW < 500) { - if (width >= 500) { - maxW = 500; - } else if (width > maxW) { - // 防止小数导致差那么一点 - maxW = width + 1; - } + } + this.popper = BI.Popper.createPopper(this.combo.element[0], this.popupView.element[0], { + placement, + strategy: "fixed", + modifiers, + }); + + // this.adjustHeight(e); + + this.element.addClass(this.options.comboClass); + hideWhenClickOutside && Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()); + BI.EVENT_BLUR && hideWhenBlur && Widget._renderEngine.createElement(window).unbind("blur." + this.getName()); + + hideWhenClickOutside && Widget._renderEngine.createElement(document).bind("mousedown." + this.getName(), bind(this._hideIf, this)); + BI.EVENT_BLUR && hideWhenBlur && Widget._renderEngine.createElement(window).bind("blur." + this.getName(), bind(this._hideIf, this)); + this.fireEvent(Bubble.EVENT_AFTER_POPUPVIEW); + } + + adjustWidth(e) { + const { isNeedAdjustWidth } = this.options; + if (!this.popupView) { + return; + } + if (isNeedAdjustWidth === true) { + this.resetListWidth(""); + const width = this.popupView.element.outerWidth(); + let maxW = this.element.outerWidth() || this.options.width; + // BI-93885 最大列宽算法调整 + if (maxW < 500) { + if (width >= 500) { + maxW = 500; + } else if (width > maxW) { + // 防止小数导致差那么一点 + maxW = width + 1; } - - // if (width > maxW + 80) { - // maxW = maxW + 80; - // } else if (width > maxW) { - // maxW = width; - // } - this.resetListWidth(maxW < 100 ? 100 : maxW); - } - }, - - adjustHeight: function () { - - }, - - resetListHeight: function (h) { - this._assertPopupView(); - this.popupView.resetHeight && this.popupView.resetHeight(h); - }, - - resetListWidth: function (w) { - this._assertPopupView(); - this.popupView.resetWidth && this.popupView.resetWidth(w); - }, - - populate: function (items) { - this._assertPopupView(); - this.popupView.populate.apply(this.popupView, arguments); - this.combo.populate && this.combo.populate.apply(this.combo, arguments); - }, - - _setEnable: function (arg) { - BI.Bubble.superclass._setEnable.apply(this, arguments); - if (arg === true) { - this.element.removeClass("base-disabled disabled"); - } else if (arg === false) { - this.element.addClass("base-disabled disabled"); - } - !arg && this.element.removeClass(this.options.hoverClass); - !arg && this.isViewVisible() && this._hideView(); - }, - - setValue: function (v) { - this.combo.setValue(v); - if (BI.isNull(this.popupView)) { - this.options.popup.value = v; - } else { - this.popupView.setValue(v); } - }, - getValue: function () { - if (BI.isNull(this.popupView)) { - return this.options.popup.value; - } else { - return this.popupView.getValue(); - } - }, - - isViewVisible: function () { - return this.isEnabled() && this.combo.isEnabled() && !!this.popupView && this.popupView.isVisible(); - }, - - showView: function (e) { - // 减少popup 调整宽高的次数 - if (this.isEnabled() && this.combo.isEnabled() && !this.isViewVisible()) { - this._popupView(e); - } - }, - - hideView: function (e) { - this._hideView(e); - }, - - getView: function () { - return this.popupView; - }, - - getPopupPosition: function () { - return this.position; - }, - - toggle: function () { - this._toggle(); - }, - - destroyed: function () { - BI.Widget._renderEngine.createElement(document) - .unbind("click." + this.getName()) - .unbind("mousedown." + this.getName()) - .unbind("mouseenter." + this.getName()) - .unbind("mouseleave." + this.getName()); - BI.Widget._renderEngine.createElement(window) - .unbind("blur." + this.getName()); - this.popper && this.popper.destroy(); - this.popper = null; - this.popupView && this.popupView._destroy(); - }, - }); - BI.Bubble.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; - BI.Bubble.EVENT_CHANGE = "EVENT_CHANGE"; - BI.Bubble.EVENT_EXPAND = "EVENT_EXPAND"; - BI.Bubble.EVENT_COLLAPSE = "EVENT_COLLAPSE"; - BI.Bubble.EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; - - - BI.Bubble.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; - BI.Bubble.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; - BI.Bubble.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; - BI.Bubble.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; - - BI.shortcut("bi.bubble", BI.Bubble); -}()); + // if (width > maxW + 80) { + // maxW = maxW + 80; + // } else if (width > maxW) { + // maxW = width; + // } + this.resetListWidth(maxW < 100 ? 100 : maxW); + } + } + + adjustHeight() { + + } + + resetListHeight(h) { + this._assertPopupView(); + this.popupView.resetHeight && this.popupView.resetHeight(h); + } + + resetListWidth(w) { + this._assertPopupView(); + this.popupView.resetWidth && this.popupView.resetWidth(w); + } + + populate(items) { + this._assertPopupView(); + this.popupView.populate.apply(this.popupView, arguments); + this.combo.populate && this.combo.populate.apply(this.combo, arguments); + } + + _setEnable(arg) { + super._setEnable(arguments); + if (arg === true) { + this.element.removeClass("base-disabled disabled"); + } else if (arg === false) { + this.element.addClass("base-disabled disabled"); + } + !arg && this.element.removeClass(this.options.hoverClass); + !arg && this.isViewVisible() && this._hideView(); + } + + setValue(v) { + this.combo.setValue(v); + if (isNull(this.popupView)) { + this.options.popup.value = v; + } else { + this.popupView.setValue(v); + } + } + + getValue() { + if (isNull(this.popupView)) { + return this.options.popup.value; + } else { + return this.popupView.getValue(); + } + } + + isViewVisible() { + return this.isEnabled() && this.combo.isEnabled() && !!this.popupView && this.popupView.isVisible(); + } + + showView(e) { + // 减少popup 调整宽高的次数 + if (this.isEnabled() && this.combo.isEnabled() && !this.isViewVisible()) { + this._popupView(e); + } + } + + hideView(e) { + this._hideView(e); + } + + getView() { + return this.popupView; + } + + getPopupPosition() { + return this.position; + } + + toggle() { + this._toggle(); + } + + destroyed() { + Widget._renderEngine.createElement(document) + .unbind("click." + this.getName()) + .unbind("mousedown." + this.getName()) + .unbind("mouseenter." + this.getName()) + .unbind("mouseleave." + this.getName()); + Widget._renderEngine.createElement(window) + .unbind("blur." + this.getName()); + this.popper && this.popper.destroy(); + this.popper = null; + this.popupView && this.popupView._destroy(); + } +} diff --git a/src/base/combination/combo.js b/src/base/combination/combo.js index 75c45a4fe..277e9e224 100644 --- a/src/base/combination/combo.js +++ b/src/base/combination/combo.js @@ -1,374 +1,374 @@ -!(function () { - var needHideWhenAnotherComboOpen = {}; - var currentOpenedCombos = {}; +/** + * @class BI.Combo + * @extends BI.Widget + */ - /** - * @class BI.Combo - * @extends BI.Widget - */ - BI.Combo = BI.inherit(BI.Bubble, { - _const: { - TRIANGLE_LENGTH: 12, - }, - _defaultConfig: function () { - var conf = BI.Combo.superclass._defaultConfig.apply(this, arguments); +import { shortcut, Widget, Controller, extend, createWidget, nextTick, bind, isNotNull, isNull, isFunction, each } from "../../core"; +import Bubble from "./bubble"; +import { Resizers } from "../0.base"; - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-combo" + (BI.isIE() ? " hack" : ""), - attributes: { - tabIndex: -1, - }, - trigger: "click", // click || hover || click-hover || "" - toggle: true, - direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right||right,innerRight||right,innerLeft||innerRight||innerLeft - logic: { - dynamic: true, - }, - container: null, // popupview放置的容器,默认为this.element - isDefaultInit: false, - destroyWhenHide: false, - hideWhenBlur: true, - hideWhenAnotherComboOpen: false, - hideWhenClickOutside: true, - showArrow: false, - isNeedAdjustHeight: true, // 是否需要高度调整 - isNeedAdjustWidth: true, - stopEvent: false, - stopPropagation: false, - adjustLength: 0, // 调整的距离 - adjustXOffset: 0, - adjustYOffset: 0, - supportCSSTransform: true, - hideChecker: BI.emptyFn, - offsetStyle: "", // "",center,middle - el: {}, - popup: {}, - comboClass: "bi-combo-popup", - hoverClass: "bi-combo-hover", - belowMouse: false, - }); - }, +let needHideWhenAnotherComboOpen = {}; +let currentOpenedCombos = {}; - render: function () { - var self = this, o = this.options; - this._initCombo(); - // 延迟绑定事件,这样可以将自己绑定的事情优先执行 - BI.nextTick(() => { - !this.isDestroyed() && this._initPullDownAction(); - }); - this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - if (self.isEnabled() && self.isValid()) { - if (type === BI.Events.TOGGLE) { - self._toggle(); - } - if (type === BI.Events.EXPAND) { - self._popupView(); - } - if (type === BI.Events.COLLAPSE) { - self._hideView(); - } - if (type === BI.Events.EXPAND) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - self.fireEvent(BI.Combo.EVENT_EXPAND); - } - if (type === BI.Events.COLLAPSE) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - self.isViewVisible() && self.fireEvent(BI.Combo.EVENT_COLLAPSE); - } - if (type === BI.Events.CLICK) { - self.fireEvent(BI.Combo.EVENT_TRIGGER_CHANGE, obj); - } - } - }); +@shortcut() +export default class Combo extends Bubble { + static xtype = "bi.combo"; - self.element.on("mouseenter." + self.getName(), function (e) { - if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) { - self.element.addClass(o.hoverClass); + static EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; + static EVENT_CHANGE = "EVENT_CHANGE"; + static EVENT_EXPAND = "EVENT_EXPAND"; + static EVENT_COLLAPSE = "EVENT_COLLAPSE"; + static EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; + + static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; + static EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; + static EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; + static EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; + + _defaultConfig() { + const conf = super._defaultConfig(arguments); + + return extend(conf, { + baseCls: (conf.baseCls || "") + " bi-combo" + (BI.isIE() ? " hack" : ""), + attributes: { + tabIndex: -1, + }, + trigger: "click", // click || hover || click-hover || "" + toggle: true, + direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right||right,innerRight||right,innerLeft||innerRight||innerLeft + logic: { + dynamic: true, + }, + container: null, // popupview放置的容器,默认为this.element + isDefaultInit: false, + destroyWhenHide: false, + hideWhenBlur: true, + hideWhenAnotherComboOpen: false, + hideWhenClickOutside: true, + showArrow: false, + isNeedAdjustHeight: true, // 是否需要高度调整 + isNeedAdjustWidth: true, + stopEvent: false, + stopPropagation: false, + adjustLength: 0, // 调整的距离 + adjustXOffset: 0, + adjustYOffset: 0, + supportCSSTransform: true, + hideChecker: BI.emptyFn, + offsetStyle: "", // "",center,middle + el: {}, + popup: {}, + comboClass: "bi-combo-popup", + hoverClass: "bi-combo-hover", + belowMouse: false, + }); + } + + render() { + const { hoverClass, logic, isDefaultInit } = this.options; + this._initCombo(); + // 延迟绑定事件,这样可以将自己绑定的事情优先执行 + nextTick(() => { + !this.isDestroyed() && this._initPullDownAction(); + }); + this.combo.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => { + if (this.isEnabled() && this.isValid()) { + if (type === BI.Events.TOGGLE) { + this._toggle(); } - }); - self.element.on("mouseleave." + self.getName(), function (e) { - if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) { - self.element.removeClass(o.hoverClass); + if (type === BI.Events.EXPAND) { + this._popupView(); } - }); - - BI.createWidget(BI.extend({ - element: this, - scrolly: false, - }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { - items: [ - { el: this.combo } - ], - })))); - o.isDefaultInit && (this._assertPopupView()); - BI.Resizers.add(this.getName(), BI.bind(function (e) { - // 如果resize对象是combo的子元素,则不应该收起,或交由hideChecker去处理 - if (this.isViewVisible()) { - BI.isNotNull(e) ? this._hideIf(e) : this._hideView(); + if (type === BI.Events.COLLAPSE) { + this._hideView(); + } + if (type === BI.Events.EXPAND) { + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); + this.fireEvent(Combo.EVENT_EXPAND); + } + if (type === BI.Events.COLLAPSE) { + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); + this.isViewVisible() && this.fireEvent(Combo.EVENT_COLLAPSE); + } + if (type === BI.Events.CLICK) { + this.fireEvent(Combo.EVENT_TRIGGER_CHANGE, obj); } - }, this)); - }, - - _assertPopupView: function () { - var self = this, o = this.options; - 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, - value: o.value, - }, this); - this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - if (type === BI.Events.CLICK) { - self.combo.setValue(self.getValue()); - self.fireEvent(BI.Bubble.EVENT_CHANGE, value, obj); - } - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - this.popupView.setVisible(false); - BI.nextTick(function () { - self.fireEvent(BI.Bubble.EVENT_AFTER_INIT); - }); } - }, + }); - _hideView: function (e) { - var o = this.options; - this.fireEvent(BI.Combo.EVENT_BEFORE_HIDEVIEW); - if (this.options.destroyWhenHide === true) { - this.popupView && this.popupView.destroy(); - this.popupView = null; - this._rendered = false; - } else { - this.popupView && this.popupView.invisible(); + this.element.on("mouseenter." + this.getName(), (e) => { + if (this.isEnabled() && this.isValid() && this.combo.isEnabled() && this.combo.isValid()) { + this.element.addClass(hoverClass); } - - if (!e || !this.combo.element.__isMouseInBounds__(e)) { - this.element.removeClass(this.options.hoverClass); - // 应对bi-focus-shadow在收起时不失焦 - this.element.blur(); + }); + this.element.on("mouseleave." + this.getName(), (e) => { + if (this.isEnabled() && this.isValid() && this.combo.isEnabled() && this.combo.isValid()) { + this.element.removeClass(hoverClass); } + }); - this.element.removeClass(this.options.comboClass); - delete needHideWhenAnotherComboOpen[this.getName()]; - delete currentOpenedCombos[this.getName()]; - - o.hideWhenClickOutside && BI.Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()).unbind("mousewheel." + this.getName()); - BI.EVENT_BLUR && o.hideWhenBlur && BI.Widget._renderEngine.createElement(window).unbind("blur." + this.getName()); - this.fireEvent(BI.Combo.EVENT_AFTER_HIDEVIEW, e); - }, + createWidget(extend({ + element: this, + scrolly: false, + }, BI.LogicFactory.createLogic("vertical", extend(logic, { + items: [ + { el: this.combo } + ], + })))); + isDefaultInit && (this._assertPopupView()); + Resizers.add(this.getName(), bind((e) => { + // 如果resize对象是combo的子元素,则不应该收起,或交由hideChecker去处理 + if (this.isViewVisible()) { + isNotNull(e) ? this._hideIf(e) : this._hideView(); + } + }, this)); + } - _popupView: function (e) { - var self = this, o = this.options; - this._assertPopupViewRender(); - this.fireEvent(BI.Combo.EVENT_BEFORE_POPUPVIEW); - // popupVisible是为了获取其宽高, 放到可视范围之外以防止在IE下闪一下 - this.popupView.css({ left: -99999, top: -99999 }); - this.popupView.visible(); - BI.each(needHideWhenAnotherComboOpen, function (i, combo) { - if (i !== self.getName()) { - if (combo && combo._hideIf(e, true) === true) { - delete needHideWhenAnotherComboOpen[i]; - } + _assertPopupView() { + const { showArrow, value, hideWhenClickOutside, hideWhenBlur } = this.options; + if (isNull(this.popupView)) { + this.popupView = createWidget(isFunction(this.options.popup) ? this.options.popup() : this.options.popup, { + type: "bi.popup_view", + showArrow, + value, + }, this); + this.popupView.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => { + if (type === BI.Events.CLICK) { + this.combo.setValue(this.getValue()); + this.fireEvent(Bubble.EVENT_CHANGE, value, obj); } + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); + }); + this.popupView.setVisible(false); + nextTick(() => { + this.fireEvent(Bubble.EVENT_AFTER_INIT); }); - currentOpenedCombos[this.getName()] = this; - this.options.hideWhenAnotherComboOpen && (needHideWhenAnotherComboOpen[this.getName()] = this); - this.adjustWidth(e); - this.adjustHeight(e); + } + } - this.element.addClass(this.options.comboClass); - o.hideWhenClickOutside && BI.Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()).unbind("mousewheel." + this.getName()); - o.hideWhenClickOutside && BI.Widget._renderEngine.createElement(document).unbind("mousewheel." + this.getName()); - BI.EVENT_BLUR && o.hideWhenBlur && BI.Widget._renderEngine.createElement(window).unbind("blur." + this.getName()); + _hideView(e) { + const { hideWhenClickOutside, hideWhenBlur } = this.options; + this.fireEvent(Combo.EVENT_BEFORE_HIDEVIEW); + if (this.options.destroyWhenHide === true) { + this.popupView && this.popupView.destroy(); + this.popupView = null; + this._rendered = false; + } else { + this.popupView && this.popupView.invisible(); + } - o.hideWhenClickOutside && BI.Widget._renderEngine.createElement(document).bind("mousedown." + this.getName(), BI.bind(this._hideIf, this)).bind("mousewheel." + this.getName(), BI.bind(this._hideIf, this)); - o.hideWhenClickOutside && BI.Widget._renderEngine.createElement(document).bind("mousewheel." + this.getName(), BI.bind(this._hideIf, this)); - BI.EVENT_BLUR && o.hideWhenBlur && BI.Widget._renderEngine.createElement(window).bind("blur." + this.getName(), BI.bind(this._hideIf, this)); - this.fireEvent(BI.Combo.EVENT_AFTER_POPUPVIEW); - }, + if (!e || !this.combo.element.__isMouseInBounds__(e)) { + this.element.removeClass(this.options.hoverClass); + // 应对bi-focus-shadow在收起时不失焦 + this.element.blur(); + } - adjustHeight: function (e) { - var o = this.options, p = {}; - if (!this.popupView) { - return; - } - var isVisible = this.popupView.isVisible(); - this.popupView.visible(); - var combo = (o.belowMouse && BI.isNotNull(e)) ? { - element: { - 0: BI.extend({}, e.target, { - getBoundingClientRect: function () { - return { - left: e.pageX, - top: e.pageY, - width: 0, - height: 0, - }; - } - }), - offset: function () { - return { - left: e.pageX, - top: e.pageY, - }; - }, - }, - } : this.combo; + this.element.removeClass(this.options.comboClass); + delete needHideWhenAnotherComboOpen[this.getName()]; + delete currentOpenedCombos[this.getName()]; - var positionRelativeElement = BI.DOM.getPositionRelativeContainingBlock( - BI.isNull(o.container) - ? this.element[0] - : BI.isWidget(o.container) - ? o.container.element[0] - : BI.Widget._renderEngine.createElement(BI.isFunction(o.container) ? o.container() : o.container)[0] - ); + hideWhenClickOutside && Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()).unbind("mousewheel." + this.getName()); + BI.EVENT_BLUR && hideWhenBlur && Widget._renderEngine.createElement(window).unbind("blur." + this.getName()); + this.fireEvent(Combo.EVENT_AFTER_HIDEVIEW, e); + } - switch (o.direction) { - case "bottom": - case "bottom,right": - p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset, (o.adjustYOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0), o.isNeedAdjustHeight, ["bottom", "top", "right", "left"], o.offsetStyle, positionRelativeElement); - break; - case "top": - case "top,right": - p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset, (o.adjustYOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0), o.isNeedAdjustHeight, ["top", "bottom", "right", "left"], o.offsetStyle, positionRelativeElement); - break; - case "left": - case "left,bottom": - p = BI.DOM.getComboPosition(combo, this.popupView, (o.adjustXOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0), o.adjustYOffset, o.isNeedAdjustHeight, ["left", "right", "bottom", "top"], o.offsetStyle, positionRelativeElement); - break; - case "right": - case "right,bottom": - p = BI.DOM.getComboPosition(combo, this.popupView, (o.adjustXOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0), o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "bottom", "top"], o.offsetStyle, positionRelativeElement); - break; - case "top,left": - p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset, (o.adjustYOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0), o.isNeedAdjustHeight, ["top", "bottom", "left", "right"], o.offsetStyle, positionRelativeElement); - break; - case "bottom,left": - p = BI.DOM.getComboPosition(combo, this.popupView, o.adjustXOffset, (o.adjustYOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0), o.isNeedAdjustHeight, ["bottom", "top", "left", "right"], o.offsetStyle, positionRelativeElement); - break; - case "left,top": - p = BI.DOM.getComboPosition(combo, this.popupView, (o.adjustXOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0), o.adjustYOffset, o.isNeedAdjustHeight, ["left", "right", "top", "bottom"], o.offsetStyle, positionRelativeElement); - break; - case "right,top": - p = BI.DOM.getComboPosition(combo, this.popupView, (o.adjustXOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0), o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "top", "bottom"], o.offsetStyle, positionRelativeElement); - break; - case "right,innerRight": - p = BI.DOM.getComboPosition(combo, this.popupView, (o.adjustXOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0), o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "innerRight", "innerLeft", "bottom", "top"], o.offsetStyle, positionRelativeElement); - break; - case "right,innerLeft": - p = BI.DOM.getComboPosition(combo, this.popupView, (o.adjustXOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0), o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "innerLeft", "innerRight", "bottom", "top"], o.offsetStyle, positionRelativeElement); - break; - case "innerRight": - p = BI.DOM.getComboPosition(combo, this.popupView, (o.adjustXOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0), o.adjustYOffset, o.isNeedAdjustHeight, ["innerRight", "innerLeft", "right", "left", "bottom", "top"], o.offsetStyle, positionRelativeElement); - break; - case "innerLeft": - p = BI.DOM.getComboPosition(combo, this.popupView, (o.adjustXOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0), o.adjustYOffset, o.isNeedAdjustHeight, ["innerLeft", "innerRight", "left", "right", "bottom", "top"], o.offsetStyle, positionRelativeElement); - break; - case "top,custom": - case "custom,top": - p = BI.DOM.getTopAdaptPosition(combo, this.popupView, (o.adjustYOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0), o.isNeedAdjustHeight); - p.dir = "top"; - break; - case "custom,bottom": - case "bottom,custom": - p = BI.DOM.getBottomAdaptPosition(combo, this.popupView, (o.adjustYOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0), o.isNeedAdjustHeight); - p.dir = "bottom"; - break; - case "left,custom": - case "custom,left": - p = BI.DOM.getLeftAdaptPosition(combo, this.popupView, (o.adjustXOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0)); - delete p.top; - delete p.adaptHeight; - p.dir = "left"; - break; - case "custom,right": - case "right,custom": - p = BI.DOM.getRightAdaptPosition(combo, this.popupView, (o.adjustXOffset + o.adjustLength) + (o.showArrow ? this._const.TRIANGLE_LENGTH : 0)); - delete p.top; - delete p.adaptHeight; - p.dir = "right"; - break; - default: - break; + _popupView(e) { + const { hideWhenClickOutside, hideWhenBlur } = this.options; + this._assertPopupViewRender(); + this.fireEvent(Combo.EVENT_BEFORE_POPUPVIEW); + // popupVisible是为了获取其宽高, 放到可视范围之外以防止在IE下闪一下 + this.popupView.css({ left: -99999, top: -99999 }); + this.popupView.visible(); + each(needHideWhenAnotherComboOpen, (i, combo) => { + if (i !== this.getName()) { + if (combo && combo._hideIf(e, true) === true) { + delete needHideWhenAnotherComboOpen[i]; + } } + }); + currentOpenedCombos[this.getName()] = this; + this.options.hideWhenAnotherComboOpen && (needHideWhenAnotherComboOpen[this.getName()] = this); + this.adjustWidth(e); + this.adjustHeight(e); - var width = this.combo.element.outerWidth(); - var height = this.combo.element.outerHeight(); - this.popupView.setDirection && this.popupView.setDirection(p.dir, { - width: width, - height: height, - offsetStyle: o.offsetStyle, - adjustXOffset: o.adjustXOffset, - adjustYOffset: o.adjustYOffset, - offset: this.combo.element.offset(), - }); + this.element.addClass(this.options.comboClass); + hideWhenClickOutside && Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()).unbind("mousewheel." + this.getName()); + hideWhenClickOutside && Widget._renderEngine.createElement(document).unbind("mousewheel." + this.getName()); + BI.EVENT_BLUR && hideWhenBlur && Widget._renderEngine.createElement(window).unbind("blur." + this.getName()); - if (o.supportCSSTransform) { + hideWhenClickOutside && Widget._renderEngine.createElement(document).bind("mousewheel." + this.getName(), bind(this._hideIf, this)); + hideWhenClickOutside && Widget._renderEngine.createElement(document).bind("mousedown." + this.getName(), bind(this._hideIf, this)).bind("mousewheel." + this.getName(), bind(this._hideIf, this)); + BI.EVENT_BLUR && hideWhenBlur && Widget._renderEngine.createElement(window).bind("blur." + this.getName(), bind(this._hideIf, this)); + this.fireEvent(Combo.EVENT_AFTER_POPUPVIEW); + } - var positonedRect = positionRelativeElement.getBoundingClientRect(); + adjustHeight(e) { + const { belowMouse, supportCSSTransform, container, direction, adjustXOffset, adjustYOffset, adjustLength, showArrow, isNeedAdjustHeight, offsetStyle } = this.options; + let p = {}; + if (!this.popupView) { + return; + } + const isVisible = this.popupView.isVisible(); + this.popupView.visible(); + const combo = (belowMouse && isNotNull(e)) ? { + element: { + 0: e.target, + offset: () => { + return { + left: e.pageX, + top: e.pageY, + }; + }, + bounds: () => { + // offset为其相对于父定位元素的偏移 + return { + x: e.offsetX, + y: e.offsetY, + width: 0, + height: 24, + }; + }, + outerWidth: () => { + return 0; + }, + outerHeight: () => { + return 24; + }, + }, + } : this.combo; + const positionRelativeElement = supportCSSTransform ? BI.DOM.getPositionRelativeContainingBlock(isNull(container) ? this.element[0] : Widget._renderEngine.createElement(isFunction(container) ? container() : container)[0]) : null; + const TRIANGLE_LENGTH = 12; + switch (direction) { + case "bottom": + case "bottom,right": + p = BI.DOM.getComboPosition(combo, this.popupView, adjustXOffset, (adjustYOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0), isNeedAdjustHeight, ["bottom", "top", "right", "left"], offsetStyle, positionRelativeElement); + break; + case "top": + case "top,right": + p = BI.DOM.getComboPosition(combo, this.popupView, adjustXOffset, (adjustYOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0), isNeedAdjustHeight, ["top", "bottom", "right", "left"], offsetStyle, positionRelativeElement); + break; + case "left": + case "left,bottom": + p = BI.DOM.getComboPosition(combo, this.popupView, (adjustXOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0), adjustYOffset, isNeedAdjustHeight, ["left", "right", "bottom", "top"], offsetStyle, positionRelativeElement); + break; + case "right": + case "right,bottom": + p = BI.DOM.getComboPosition(combo, this.popupView, (adjustXOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0), adjustYOffset, isNeedAdjustHeight, ["right", "left", "bottom", "top"], offsetStyle, positionRelativeElement); + break; + case "top,left": + p = BI.DOM.getComboPosition(combo, this.popupView, adjustXOffset, (adjustYOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0), isNeedAdjustHeight, ["top", "bottom", "left", "right"], offsetStyle, positionRelativeElement); + break; + case "bottom,left": + p = BI.DOM.getComboPosition(combo, this.popupView, adjustXOffset, (adjustYOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0), isNeedAdjustHeight, ["bottom", "top", "left", "right"], offsetStyle, positionRelativeElement); + break; + case "left,top": + p = BI.DOM.getComboPosition(combo, this.popupView, (adjustXOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0), adjustYOffset, isNeedAdjustHeight, ["left", "right", "top", "bottom"], offsetStyle, positionRelativeElement); + break; + case "right,top": + p = BI.DOM.getComboPosition(combo, this.popupView, (adjustXOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0), adjustYOffset, isNeedAdjustHeight, ["right", "left", "top", "bottom"], offsetStyle, positionRelativeElement); + break; + case "right,innerRight": + p = BI.DOM.getComboPosition(combo, this.popupView, (adjustXOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0), adjustYOffset, isNeedAdjustHeight, ["right", "left", "innerRight", "innerLeft", "bottom", "top"], offsetStyle, positionRelativeElement); + break; + case "right,innerLeft": + p = BI.DOM.getComboPosition(combo, this.popupView, (adjustXOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0), adjustYOffset, isNeedAdjustHeight, ["right", "left", "innerLeft", "innerRight", "bottom", "top"], offsetStyle, positionRelativeElement); + break; + case "innerRight": + p = BI.DOM.getComboPosition(combo, this.popupView, (adjustXOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0), adjustYOffset, isNeedAdjustHeight, ["innerRight", "innerLeft", "right", "left", "bottom", "top"], offsetStyle, positionRelativeElement); + break; + case "innerLeft": + p = BI.DOM.getComboPosition(combo, this.popupView, (adjustXOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0), adjustYOffset, isNeedAdjustHeight, ["innerLeft", "innerRight", "left", "right", "bottom", "top"], offsetStyle, positionRelativeElement); + break; + case "top,custom": + case "custom,top": + p = BI.DOM.getTopAdaptPosition(combo, this.popupView, (adjustYOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0), isNeedAdjustHeight); + p.dir = "top"; + break; + case "custom,bottom": + case "bottom,custom": + p = BI.DOM.getBottomAdaptPosition(combo, this.popupView, (adjustYOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0), isNeedAdjustHeight); + p.dir = "bottom"; + break; + case "left,custom": + case "custom,left": + p = BI.DOM.getLeftAdaptPosition(combo, this.popupView, (adjustXOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0)); + delete p.top; + delete p.adaptHeight; + p.dir = "left"; + break; + case "custom,right": + case "right,custom": + p = BI.DOM.getRightAdaptPosition(combo, this.popupView, (adjustXOffset + adjustLength) + (showArrow ? TRIANGLE_LENGTH : 0)); + delete p.top; + delete p.adaptHeight; + p.dir = "right"; + break; + default: + break; + } - var scaleX = positonedRect.width / positionRelativeElement.offsetWidth; - var scaleY = positonedRect.height / positionRelativeElement.offsetHeight; + if ("adaptHeight" in p) { + this.resetListHeight(p.adaptHeight); + } - p.top && (p.top = Math.round(p.top / scaleY + positionRelativeElement.scrollTop)); - p.left && (p.left = Math.round(p.left / scaleX + positionRelativeElement.scrollLeft)); + const width = this.combo.element.outerWidth(); + const height = this.combo.element.outerHeight(); + this.popupView.setDirection && this.popupView.setDirection(p.dir, { + width, + height, + offsetStyle, + adjustXOffset, + adjustYOffset, + offset: this.combo.element.offset(), + }); - p.adaptHeight && (p.adaptHeight = Math.round(p.adaptHeight / scaleY)); - } + if (supportCSSTransform) { - if ("adaptHeight" in p) { - this.resetListHeight(p.adaptHeight); - } + const positonedRect = positionRelativeElement.getBoundingClientRect(); - if ("left" in p) { - this.popupView.element.css({ - left: p.left, - }); - } - if ("top" in p) { - this.popupView.element.css({ - top: p.top, - }); - } - this.position = p; - this.popupView.setVisible(isVisible); - }, + const scaleX = positonedRect.width / positionRelativeElement.offsetWidth; + const scaleY = positonedRect.height / positionRelativeElement.offsetHeight; - destroyed: function () { - BI.Widget._renderEngine.createElement(document) - .unbind("click." + this.getName()) - .unbind("mousedown." + this.getName()) - .unbind("mousewheel." + this.getName()) - .unbind("mouseenter." + this.getName()) - .unbind("mouseleave." + this.getName()); - BI.Widget._renderEngine.createElement(window) - .unbind("blur." + this.getName()); - BI.Resizers.remove(this.getName()); - this.popupView && this.popupView._destroy(); - delete needHideWhenAnotherComboOpen[this.getName()]; - delete currentOpenedCombos[this.getName()]; - }, - }); - BI.Combo.closeAll = function () { - BI.each(currentOpenedCombos, function (i, combo) { - if (combo) { - combo.hideView(); - } - }); - currentOpenedCombos = {}; - needHideWhenAnotherComboOpen = {}; - }; - BI.Combo.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; - BI.Combo.EVENT_CHANGE = "EVENT_CHANGE"; - BI.Combo.EVENT_EXPAND = "EVENT_EXPAND"; - BI.Combo.EVENT_COLLAPSE = "EVENT_COLLAPSE"; - BI.Combo.EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; + p.top && (p.top = p.top / scaleY); + p.left && (p.left = p.left / scaleX); + } + if ("left" in p) { + this.popupView.element.css({ + left: p.left, + }); + } + if ("top" in p) { + this.popupView.element.css({ + top: p.top, + }); + } + this.position = p; + this.popupView.setVisible(isVisible); + } - BI.Combo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; - BI.Combo.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; - BI.Combo.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; - BI.Combo.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; + destroyed() { + Widget._renderEngine.createElement(document) + .unbind("click." + this.getName()) + .unbind("mousedown." + this.getName()) + .unbind("mousewheel." + this.getName()) + .unbind("mouseenter." + this.getName()) + .unbind("mouseleave." + this.getName()); + Widget._renderEngine.createElement(window) + .unbind("blur." + this.getName()); + Resizers.remove(this.getName()); + this.popupView && this.popupView._destroy(); + delete needHideWhenAnotherComboOpen[this.getName()]; + delete currentOpenedCombos[this.getName()]; + } +} - BI.shortcut("bi.combo", BI.Combo); -}()); +Combo.closeAll = () => { + each(currentOpenedCombos, (i, combo) => { + if (combo) { + combo.hideView(); + } + }); + currentOpenedCombos = {}; + needHideWhenAnotherComboOpen = {}; +}; diff --git a/src/base/combination/expander.js b/src/base/combination/expander.js index 60b3dd471..3c7e9f8cb 100644 --- a/src/base/combination/expander.js +++ b/src/base/combination/expander.js @@ -6,9 +6,25 @@ * @class BI.Expander * @extends BI.Widget */ -BI.Expander = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.Expander.superclass._defaultConfig.apply(this, arguments), { +import { shortcut, Widget, Controller, extend, nextTick, each, debounce, isNull, createWidget } from "../../core"; + +@shortcut() +export default class Expander extends Widget { + static xtype = "bi.expander"; + + static EVENT_EXPAND = "EVENT_EXPAND"; + static EVENT_COLLAPSE = "EVENT_COLLAPSE"; + static EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; + static EVENT_CHANGE = "EVENT_CHANGE"; + static EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; + + static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; + static EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; + static EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; + static EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; + + _defaultConfig() { + return extend(super._defaultConfig(arguments), { baseCls: "bi-expander", trigger: "click", toggle: true, @@ -19,48 +35,48 @@ BI.Expander = BI.inherit(BI.Widget, { expanderClass: "bi-expander-popup", hoverClass: "bi-expander-hover", }); - }, + } - render: function () { - var self = this, o = this.options; - this._expanded = !!o.el.open; + render() { + const { el, hoverClass, isDefaultInit } = this.options; + this._expanded = !!el.open; this._initExpander(); // 延迟绑定事件,这样可以将自己绑定的事情优先执行 - BI.nextTick(() => { + nextTick(() => { !this.isDestroyed() && this._initPullDownAction(); }); - this.expander.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - if (self.isEnabled() && self.isValid()) { + this.expander.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => { + if (this.isEnabled() && this.isValid()) { if (type === BI.Events.EXPAND) { - self._popupView(); + this._popupView(); } if (type === BI.Events.COLLAPSE) { - self._hideView(); + this._hideView(); } if (type === BI.Events.EXPAND) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - self.fireEvent(BI.Expander.EVENT_EXPAND); + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); + this.fireEvent(Expander.EVENT_EXPAND); } if (type === BI.Events.COLLAPSE) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - self.isViewVisible() && self.fireEvent(BI.Expander.EVENT_COLLAPSE); + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); + this.isViewVisible() && this.fireEvent(Expander.EVENT_COLLAPSE); } if (type === BI.Events.CLICK) { - self.fireEvent(BI.Expander.EVENT_TRIGGER_CHANGE, value, obj); + this.fireEvent(Expander.EVENT_TRIGGER_CHANGE, value, obj); } } }); - this.element.hover(function () { - if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) { - self.element.addClass(o.hoverClass); + this.element.hover(() => { + if (this.isEnabled() && this.isValid() && this.expander.isEnabled() && this.expander.isValid()) { + this.element.addClass(hoverClass); } - }, function () { - if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) { - self.element.removeClass(o.hoverClass); + }, () => { + if (this.isEnabled() && this.isValid() && this.expander.isEnabled() && this.expander.isValid()) { + this.element.removeClass(hoverClass); } }); - BI.createWidget({ + createWidget({ type: "bi.vertical", scrolly: false, element: this, @@ -68,13 +84,13 @@ BI.Expander = BI.inherit(BI.Widget, { { el: this.expander } ], }); - o.isDefaultInit && this._assertPopupView(); + isDefaultInit && this._assertPopupView(); if (this.expander.isOpened() === true) { this._popupView(); } - }, + } - _toggle: function () { + _toggle() { this._assertPopupViewRender(); if (this.popupView.isVisible()) { this._hideView(); @@ -83,40 +99,40 @@ BI.Expander = BI.inherit(BI.Widget, { this._popupView(); } } - }, + } - _initPullDownAction: function () { - var self = this, o = this.options; - var evs = this.options.trigger.split(","); - BI.each(evs, function (i, e) { + _initPullDownAction() { + const { toggle } = this.options; + const evs = this.options.trigger.split(","); + each(evs, (i, e) => { switch (e) { case "hover": - self.element[e](function (e) { - if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) { - self._popupView(); - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.expander); - self.fireEvent(BI.Expander.EVENT_EXPAND); + this.element[e]((e) => { + if (this.isEnabled() && this.isValid() && this.expander.isEnabled() && this.expander.isValid()) { + this._popupView(); + this.fireEvent(Controller.EVENT_CHANGE, BI.Events.EXPAND, "", this.expander); + this.fireEvent(Expander.EVENT_EXPAND); } - }, function () { - if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid() && o.toggle) { - self._hideView(); - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.expander); - self.fireEvent(BI.Expander.EVENT_COLLAPSE); + }, () => { + if (this.isEnabled() && this.isValid() && this.expander.isEnabled() && this.expander.isValid() && toggle) { + this._hideView(); + this.fireEvent(Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", this.expander); + this.fireEvent(Expander.EVENT_COLLAPSE); } }); break; case "click": if (e) { - self.element.off(e + "." + self.getName()).on(e + "." + self.getName(), BI.debounce(function (e) { - if (self.expander.element.__isMouseInBounds__(e)) { - if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) { - o.toggle ? self._toggle() : self._popupView(); - if (self.isExpanded()) { - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.expander); - self.fireEvent(BI.Expander.EVENT_EXPAND); + this.element.off(e + "." + this.getName()).on(e + "." + this.getName(), debounce((e) => { + if (this.expander.element.__isMouseInBounds__(e)) { + if (this.isEnabled() && this.isValid() && this.expander.isEnabled() && this.expander.isValid()) { + toggle ? this._toggle() : this._popupView(); + if (this.isExpanded()) { + this.fireEvent(Controller.EVENT_CHANGE, BI.Events.EXPAND, "", this.expander); + this.fireEvent(Expander.EVENT_EXPAND); } else { - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.expander); - self.fireEvent(BI.Expander.EVENT_COLLAPSE); + this.fireEvent(Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", this.expander); + this.fireEvent(Expander.EVENT_COLLAPSE); } } } @@ -130,16 +146,16 @@ BI.Expander = BI.inherit(BI.Widget, { break; } }); - }, + } - _initExpander: function () { - this.expander = BI.createWidget(this.options.el); - }, + _initExpander() { + this.expander = createWidget(this.options.el); + } - _assertPopupView: function () { - var self = this, o = this.options; - if (BI.isNull(this.popupView)) { - this.popupView = BI.createWidget(this.options.popup, { + _assertPopupView() { + const { value } = this.options; + if (isNull(this.popupView)) { + this.popupView = createWidget(this.options.popup, { type: "bi.button_group", cls: "expander-popup", layouts: [{ @@ -147,26 +163,26 @@ BI.Expander = BI.inherit(BI.Widget, { hgap: 0, vgap: 0, }], - value: o.value, + value, }, this); - this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.popupView.on(Controller.EVENT_CHANGE, (type, value, obj, ...args)=> { + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); if (type === BI.Events.CLICK) { // self.setValue(self.getValue()); - self.fireEvent(BI.Expander.EVENT_CHANGE, value, obj); + this.fireEvent(Expander.EVENT_CHANGE, value, obj); } }); this.popupView.setVisible(this.isExpanded()); - BI.nextTick(function () { - self.fireEvent(BI.Expander.EVENT_AFTER_INIT); + nextTick(() => { + this.fireEvent(Expander.EVENT_AFTER_INIT); }); } - }, + } - _assertPopupViewRender: function () { + _assertPopupViewRender() { this._assertPopupView(); if (!this._rendered) { - BI.createWidget({ + createWidget({ type: "bi.vertical", scrolly: false, element: this, @@ -176,113 +192,100 @@ BI.Expander = BI.inherit(BI.Widget, { }); this._rendered = true; } - }, + } - _hideView: function () { - this.fireEvent(BI.Expander.EVENT_BEFORE_HIDEVIEW); + _hideView() { + this.fireEvent(Expander.EVENT_BEFORE_HIDEVIEW); this._expanded = false; this.expander.setOpened(false); this.popupView && this.popupView.invisible(); this.element.removeClass(this.options.expanderClass); - this.fireEvent(BI.Expander.EVENT_AFTER_HIDEVIEW); - }, + this.fireEvent(Expander.EVENT_AFTER_HIDEVIEW); + } - _popupView: function () { + _popupView() { this._assertPopupViewRender(); - this.fireEvent(BI.Expander.EVENT_BEFORE_POPUPVIEW); + this.fireEvent(Expander.EVENT_BEFORE_POPUPVIEW); this._expanded = true; this.expander.setOpened(true); this.popupView.visible(); this.element.addClass(this.options.expanderClass); - this.fireEvent(BI.Expander.EVENT_AFTER_POPUPVIEW); - }, + this.fireEvent(Expander.EVENT_AFTER_POPUPVIEW); + } - populate: function (items) { + populate(items) { // this._assertPopupView(); this.popupView && this.popupView.populate.apply(this.popupView, arguments); this.expander.populate && this.expander.populate.apply(this.expander, arguments); - }, + } - _setEnable: function (arg) { - BI.Expander.superclass._setEnable.apply(this, arguments); + _setEnable(arg) { + super._setEnable(arguments); !arg && this.element.removeClass(this.options.hoverClass); !arg && this.isViewVisible() && this._hideView(); - }, + } - setValue: function (v) { + setValue(v) { this.expander.setValue(v); - if (BI.isNull(this.popupView)) { + if (isNull(this.popupView)) { this.options.popup.value = v; } else { this.popupView.setValue(v); } - }, + } - getValue: function () { - if (BI.isNull(this.popupView)) { + getValue() { + if (isNull(this.popupView)) { return this.options.popup.value; } else { return this.popupView.getValue(); } - }, + } - isViewVisible: function () { + isViewVisible() { return this.isEnabled() && this.expander.isEnabled() && !!this.popupView && this.popupView.isVisible(); - }, + } - isExpanded: function () { + isExpanded() { return this._expanded; - }, + } - showView: function () { + showView() { if (this.isEnabled() && this.expander.isEnabled()) { this._popupView(); } - }, + } - hideView: function () { + hideView() { this._hideView(); - }, + } - getView: function () { + getView() { return this.popupView; - }, + } - getAllLeaves: function () { + getAllLeaves() { return this.popupView && this.popupView.getAllLeaves(); - }, + } - getNodeById: function (id) { + getNodeById(id) { if (this.expander.options.id === id) { return this.expander; } return this.popupView && this.popupView.getNodeById(id); - }, + } - getNodeByValue: function (value) { + getNodeByValue(value) { if (this.expander.getValue() === value) { return this.expander; } return this.popupView && this.popupView.getNodeByValue(value); - }, - - destroy: function () { - BI.Expander.superclass.destroy.apply(this, arguments); - }, -}); -BI.Expander.EVENT_EXPAND = "EVENT_EXPAND"; -BI.Expander.EVENT_COLLAPSE = "EVENT_COLLAPSE"; -BI.Expander.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; -BI.Expander.EVENT_CHANGE = "EVENT_CHANGE"; -BI.Expander.EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; - - -BI.Expander.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.Expander.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; -BI.Expander.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; -BI.Expander.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; + } -BI.shortcut("bi.expander", BI.Expander); + destroy() { + super.destroy(arguments); + } +} diff --git a/src/base/combination/group.button.js b/src/base/combination/group.button.js index 02b044b17..22c110720 100644 --- a/src/base/combination/group.button.js +++ b/src/base/combination/group.button.js @@ -3,10 +3,16 @@ * @class BI.ButtonGroup * @extends BI.Widget */ +import { shortcut, Widget, Controller, extend, createWidget, createWidgets, each, isFunction, isKey, isNotEmptyArray, createItems, isArray, remove, map, stripEL, makeArrayByArray, clone, deepClone, formatEL, isEmpty, concat, removeAt, deepContains, has, any } from "../../core"; -BI.ButtonGroup = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.ButtonGroup.superclass._defaultConfig.apply(this, arguments), { +@shortcut() +export default class ButtonGroup extends Widget { + static xtype = "bi.button_group"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig() { + return extend(super._defaultConfig(arguments), { baseCls: "bi-button-group", behaviors: {}, items: [], @@ -18,83 +24,84 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { vgap: 0, }], }); - }, + } - render: function () { - var self = this, o = this.options; - var behaviors = {}; - BI.each(o.behaviors, function (key, rule) { + render() { + const { behaviors: optionsBehaviors, items: optionsItems, value } = this.options; + const behaviors = {}; + each(optionsBehaviors, (key, rule) => { behaviors[key] = BI.BehaviorFactory.createBehavior(key, { rule: rule, }); }); this.behaviors = behaviors; - var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { - self.populate(newValue); - }) : o.items; + const items = isFunction(optionsItems) ? this.__watch(optionsItems, (context, newValue) => { + this.populate(newValue); + }) : optionsItems; this.populate(items); - o.value = BI.isFunction(o.value) ? this.__watch(o.value, function (context, newValue) { - self.setValue(newValue); - }) : o.value; - if (BI.isKey(o.value) || BI.isNotEmptyArray(o.value)) { - this.setValue(o.value); + this.options.value = isFunction(value) ? this.__watch(value, (context, newValue) => { + this.setValue(newValue); + }) : value; + if (isKey(value) || isNotEmptyArray(value)) { + this.setValue(value); } - }, + } - _createBtns: function (items) { - var btns; - BI.Widget.execWithContext(this, function () { - btns = BI.createWidgets(BI.createItems(items, { + _createBtns(items) { + let btns; + Widget.execWithContext(this, () => { + btns = createWidgets(createItems(items, { type: "bi.text_button", })); }); return btns; - }, + } - _btnsCreator: function (items) { - var self = this, args = Array.prototype.slice.call(arguments), o = this.options; - var buttons = this._createBtns(items); + _btnsCreator(items) { + const args = Array.prototype.slice.call(arguments); + const { chooseType } = this.options; + const buttons = this._createBtns(items); args[0] = buttons; - BI.each(this.behaviors, function (i, behavior) { + each(this.behaviors, (i, behavior) => { behavior.doBehavior.apply(behavior, args); }); - BI.each(buttons, function (i, btn) { - btn.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { + each(buttons, (i, btn) => { + btn.on(Controller.EVENT_CHANGE, (type, value, obj, ...arg) => { if (type === BI.Events.CLICK) { - switch (o.chooseType) { - case BI.ButtonGroup.CHOOSE_TYPE_SINGLE: - self.setValue(btn.getValue()); + switch (chooseType) { + case ButtonGroup.CHOOSE_TYPE_SINGLE: + this.setValue(btn.getValue()); break; - case BI.ButtonGroup.CHOOSE_TYPE_NONE: - self.setValue([]); + case ButtonGroup.CHOOSE_TYPE_NONE: + this.setValue([]); break; default: break; } - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - self.fireEvent(BI.ButtonGroup.EVENT_CHANGE, value, obj); + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...arg); + this.fireEvent(ButtonGroup.EVENT_CHANGE, value, obj); } else { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...arg); } }); - btn.on(BI.Events.DESTROY, function () { - BI.remove(self.buttons, btn); + btn.on(BI.Events.DESTROY, () => { + remove(this.buttons, btn); }); }); return buttons; - }, - - _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--) { - btns = BI.map(btns, function (k, it) { - return BI.extend({}, layouts[i], { + } + + _packageBtns(btns) { + const { layouts: optionsLayouts } = this.options; + const layouts = isArray(optionsLayouts) ? optionsLayouts : [optionsLayouts]; + for (let i = layouts.length - 1; i > 0; i--) { + btns = map(btns, (k, it) => { + return extend({}, layouts[i], { items: [ - BI.extend({}, layouts[i].el, { + extend({}, layouts[i].el, { el: it, }) ], @@ -103,56 +110,57 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { } return btns; - }, + } - _packageSimpleItems: function (btns) { - var o = this.options; + _packageSimpleItems(btns) { + const { items } = this.options; - return BI.map(o.items, function (i, item) { - if (BI.stripEL(item) === item) { + return map(items, (i, item) => { + if (stripEL(item) === item) { return btns[i]; } - return BI.extend({}, item, { + return extend({}, item, { el: btns[i], }); }); - }, + } - _packageItems: function (items, packBtns) { - return BI.createItems(BI.makeArrayByArray(items, {}), BI.clone(packBtns)); - }, + _packageItems(items, packBtns) { + return createItems(makeArrayByArray(items, {}), clone(packBtns)); + } - _packageLayout: function (items) { - var o = this.options, layout = BI.deepClone(BI.isArray(o.layouts) ? o.layouts[0] : o.layouts); + _packageLayout(items) { + const { layouts } = this.options; + const layout = deepClone(isArray(layouts) ? layouts[0] : layouts); - var lay = BI.formatEL(layout).el; - while (lay && lay.items && !BI.isEmpty(lay.items)) { - lay = BI.formatEL(lay.items[0]).el; + let lay = formatEL(layout).el; + while (lay && lay.items && !isEmpty(lay.items)) { + lay = formatEL(lay.items[0]).el; } lay.items = items; return layout; - }, + } // 如果是一个简单的layout - _isSimpleLayout: function () { - var o = this.options; + _isSimpleLayout() { + const { layouts, items } = this.options; - return BI.isArray(o.layouts) ? (o.layouts.length === 1 && !BI.isArray(o.items[0])) : true; - }, + return isArray(layouts) ? (layouts.length === 1 && !isArray(items[0])) : true; + } - doBehavior: function () { - var args = Array.prototype.slice.call(arguments); + doBehavior() { + const args = Array.prototype.slice.call(arguments); args.unshift(this.buttons); - BI.each(this.behaviors, function (i, behavior) { + each(this.behaviors, (i, behavior) => { behavior.doBehavior.apply(behavior, args); }); - }, + } - prependItems: function (items) { - var btns = this._btnsCreator.apply(this, arguments); - this.buttons = BI.concat(btns, this.buttons); + prependItems(items) { + const btns = this._btnsCreator.apply(this, arguments); + this.buttons = concat(btns, this.buttons); if (this._isSimpleLayout() && this.layouts && this.layouts.prependItems) { this.layouts.prependItems(btns); @@ -162,11 +170,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { items = this._packageItems(items, this._packageBtns(btns)); this.layouts.prependItems(this._packageLayout(items).items); - }, + } - addItems: function (items) { - var btns = this._btnsCreator.apply(this, arguments); - this.buttons = BI.concat(this.buttons, btns); + addItems(items) { + const btns = this._btnsCreator.apply(this, arguments); + this.buttons = concat(this.buttons, btns); // 如果是一个简单的layout if (this._isSimpleLayout() && this.layouts && this.layouts.addItems) { @@ -177,26 +185,26 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { items = this._packageItems(items, this._packageBtns(btns)); this.layouts.addItems(this._packageLayout(items).items); - }, + } - removeItemAt: function (indexes) { - BI.removeAt(this.buttons, indexes); + removeItemAt(indexes) { + removeAt(this.buttons, indexes); this.layouts.removeItemAt(indexes); - }, + } - removeItems: function (values) { - values = BI.isArray(values) ? values : [values]; - var deleted = []; - BI.each(this.buttons, function (i, button) { - if (BI.deepContains(values, button.getValue())) { + removeItems(values) { + values = isArray(values) ? values : [values]; + const deleted = []; + each(this.buttons, (i, button) => { + if (deepContains(values, button.getValue())) { deleted.push(i); } }); - BI.removeAt(this.buttons, deleted); + removeAt(this.buttons, deleted); this.layouts.removeItemAt(deleted); - }, + } - populate: function (items) { + populate(items) { items = items || []; this.empty(); this.options.items = items; @@ -208,114 +216,114 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { items = this._packageItems(items, this._packageBtns(this.buttons)); } - this.layouts = BI.createWidget(BI.extend({ element: this }, this._packageLayout(items))); - }, + this.layouts = createWidget(extend({ element: this }, this._packageLayout(items))); + } - setNotSelectedValue: function (v) { - v = BI.isArray(v) ? v : [v]; - BI.each(this.buttons, function (i, item) { - if (BI.deepContains(v, item.getValue())) { + setNotSelectedValue(v) { + v = isArray(v) ? v : [v]; + each(this.buttons, (i, item) => { + if (deepContains(v, item.getValue())) { item.setSelected && item.setSelected(false); } else { item.setSelected && item.setSelected(true); } }); - }, + } - setEnabledValue: function (v) { - v = BI.isArray(v) ? v : [v]; - BI.each(this.buttons, function (i, item) { - if (BI.deepContains(v, item.getValue())) { + setEnabledValue(v) { + v = isArray(v) ? v : [v]; + each(this.buttons, (i, item) => { + if (deepContains(v, item.getValue())) { item.setEnable(true); } else { item.setEnable(false); } }); - }, + } - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - BI.each(this.buttons, function (i, item) { - if (BI.deepContains(v, item.getValue())) { + setValue(v) { + v = isArray(v) ? v : [v]; + each(this.buttons, (i, item) => { + if (deepContains(v, item.getValue())) { item.setSelected && item.setSelected(true); } else { item.setSelected && item.setSelected(false); } }); - }, + } - setValueMap: function (map) { + setValueMap(map) { map = map || {}; - BI.each(this.buttons, function (i, item) { - if (BI.has(map, item.getValue())) { + each(this.buttons, (i, item) => { + if (has(map, item.getValue())) { item.setSelected && item.setSelected(true); } else { item.setSelected && item.setSelected(false); } }); - }, + } - setAllSelected: function (v) { - BI.each(this.getAllButtons(), function (i, btn) { + setAllSelected(v) { + each(this.getAllButtons(), (i, btn) => { (btn.setSelected || btn.setAllSelected).apply(btn, [v]); }); - }, + } - getNotSelectedValue: function () { - var v = []; - BI.each(this.buttons, function (i, item) { + getNotSelectedValue() { + const v = []; + each(this.buttons, (i, item) => { if (item.isEnabled() && !(item.isSelected && item.isSelected())) { v.push(item.getValue()); } }); return v; - }, + } - getValue: function () { - var v = []; - BI.each(this.buttons, function (i, item) { + getValue() { + const v = []; + each(this.buttons, (i, item) => { if (item.isEnabled() && item.isSelected && item.isSelected()) { v.push(item.getValue()); } }); return v; - }, + } - getAllButtons: function () { + getAllButtons() { return this.buttons; - }, + } - getAllLeaves: function () { + getAllLeaves() { return this.buttons; - }, + } - getSelectedButtons: function () { - var btns = []; - BI.each(this.buttons, function (i, item) { + getSelectedButtons() { + const btns = []; + each(this.buttons, (i, item) => { if (item.isSelected && item.isSelected()) { btns.push(item); } }); return btns; - }, + } - getNotSelectedButtons: function () { - var btns = []; - BI.each(this.buttons, function (i, item) { + getNotSelectedButtons() { + const btns = []; + each(this.buttons, (i, item) => { if (item.isSelected && !item.isSelected()) { btns.push(item); } }); return btns; - }, + } - getIndexByValue: function (value) { - var index = -1; - BI.any(this.buttons, function (i, item) { + getIndexByValue(value) { + let index = -1; + any(this.buttons, (i, item) => { if (item.isEnabled() && item.getValue() === value) { index = i; @@ -324,11 +332,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { }); return index; - }, + } - getNodeById: function (id) { - var node; - BI.any(this.buttons, function (i, item) { + getNodeById(id) { + let node; + any(this.buttons, (i, item) => { if (item.isEnabled() && item.options.id === id) { node = item; @@ -337,11 +345,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { }); return node; - }, + } - getNodeByValue: function (value) { - var node; - BI.any(this.buttons, function (i, item) { + getNodeByValue(value) { + let node; + any(this.buttons, (i, item) => { if (item.isEnabled() && item.getValue() === value) { node = item; @@ -350,35 +358,33 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { }); return node; - }, + } /** * 滚动到指定的节点 */ - scrollToValue: function (value, scrollIntoViewOptions) { - var node = this.getNodeByValue(value); + scrollToValue(value, scrollIntoViewOptions) { + const node = this.getNodeByValue(value); if (node) { node.element[0].scrollIntoView(scrollIntoViewOptions); } - }, + } - empty: function () { - BI.ButtonGroup.superclass.empty.apply(this, arguments); + empty() { + super.empty(arguments); this.options.items = []; - }, + } - destroy: function () { - BI.ButtonGroup.superclass.destroy.apply(this, arguments); + destroy() { + super.destroy(arguments); this.options.items = []; - }, -}); -BI.extend(BI.ButtonGroup, { + } +} + +extend(ButtonGroup, { CHOOSE_TYPE_SINGLE: BI.Selection.Single, CHOOSE_TYPE_MULTI: BI.Selection.Multi, CHOOSE_TYPE_ALL: BI.Selection.All, CHOOSE_TYPE_NONE: BI.Selection.None, CHOOSE_TYPE_DEFAULT: BI.Selection.Default, }); -BI.ButtonGroup.EVENT_CHANGE = "EVENT_CHANGE"; - -BI.shortcut("bi.button_group", BI.ButtonGroup); diff --git a/src/base/combination/group.combo.js b/src/base/combination/group.combo.js index 2f8b0c72e..97882f40f 100644 --- a/src/base/combination/group.combo.js +++ b/src/base/combination/group.combo.js @@ -2,9 +2,16 @@ * Created by GUY on 2015/8/10. */ -BI.ComboGroup = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.ComboGroup.superclass._defaultConfig.apply(this, arguments), { +import { shortcut, Widget, Controller, extend, isEmpty, each, formatEL, clone, createWidget } from "../../core"; + +@shortcut() +export default class ComboGroup extends Widget { + static xtype = "bi.combo_group"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig() { + return extend(super._defaultConfig(arguments), { baseCls: "bi-combo-group bi-list-item", // 以下这些属性对每一个combo都是公用的 @@ -28,69 +35,66 @@ BI.ComboGroup = BI.inherit(BI.Widget, { }, }, }); - }, + } - render: function () { + render() { this._populate(this.options.el); - }, + } - _populate: function (item) { - var self = this, o = this.options; - var children = o.items; - if (BI.isEmpty(children)) { + _populate(item) { + const { items, action, height, direction, isDefaultInit, isNeedAdjustHeight, isNeedAdjustWidth, adjustLength, popup, container, trigger } = this.options; + const children = items; + if (isEmpty(children)) { throw new Error("ComboGroup构造错误"); } - BI.each(children, function (i, ch) { - var son = BI.formatEL(ch).el.children; - ch = BI.formatEL(ch).el; - if (!BI.isEmpty(son)) { - ch.el = BI.clone(ch); + each(children, (i, ch) => { + const son = formatEL(ch).el.children; + ch = formatEL(ch).el; + if (!isEmpty(son)) { + ch.el = clone(ch); ch.items = son; ch.type = "bi.combo_group"; - ch.action = o.action; - ch.height = o.height; - ch.direction = o.direction; - ch.isDefaultInit = o.isDefaultInit; - ch.isNeedAdjustHeight = o.isNeedAdjustHeight; - ch.isNeedAdjustWidth = o.isNeedAdjustWidth; - ch.adjustLength = o.adjustLength; - ch.popup = o.popup; + ch.action = action; + ch.height = height; + ch.direction = direction; + ch.isDefaultInit = isDefaultInit; + ch.isNeedAdjustHeight = isNeedAdjustHeight; + ch.isNeedAdjustWidth = isNeedAdjustWidth; + ch.adjustLength = adjustLength; + ch.popup = popup; } }); - this.combo = BI.createWidget({ + this.combo = createWidget({ type: "bi.combo", element: this, - container: o.container, - height: o.height, - trigger: o.trigger, - direction: o.direction, - isDefaultInit: o.isDefaultInit, - isNeedAdjustWidth: o.isNeedAdjustWidth, - isNeedAdjustHeight: o.isNeedAdjustHeight, - adjustLength: o.adjustLength, + container, + height, + trigger, + direction, + isDefaultInit, + isNeedAdjustWidth, + isNeedAdjustHeight, + adjustLength, el: item, - popup: BI.extend({}, o.popup, { - el: BI.extend({ + popup: extend({}, popup, { + el: extend({ items: children, - }, o.popup.el), + }, popup.el), }), }); - this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.combo.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => { + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); if (type === BI.Events.CLICK) { - self.fireEvent(BI.ComboGroup.EVENT_CHANGE, obj); + this.fireEvent(ComboGroup.EVENT_CHANGE, obj); } }); - }, + } - getValue: function () { + getValue() { return this.combo.getValue(); - }, + } - setValue: function (v) { + setValue(v) { this.combo.setValue(v); - }, -}); -BI.ComboGroup.EVENT_CHANGE = "EVENT_CHANGE"; - -BI.shortcut("bi.combo_group", BI.ComboGroup); + } +} diff --git a/src/base/combination/group.virtual.js b/src/base/combination/group.virtual.js index 40e7c09f4..f757c4b4e 100644 --- a/src/base/combination/group.virtual.js +++ b/src/base/combination/group.virtual.js @@ -1,6 +1,13 @@ -BI.VirtualGroup = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.VirtualGroup.superclass._defaultConfig.apply(this, arguments), { +import { shortcut, Widget, Controller, extend, isFunction, isKey, isArray, map, stripEL, deepClone, formatEL, isEmpty, each, createWidget } from "../../core"; + +@shortcut() +export default class VirtualGroup extends Widget { + static xtype = "bi.virtual_group"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig() { + return extend(super._defaultConfig(arguments), { baseCls: "bi-virtual-group", items: [], layouts: [{ @@ -9,36 +16,36 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { vgap: 0, }], }); - }, + } - render: function () { - var self = this, o = this.options; - var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { - self.populate(newValue); - }) : o.items; + render() { + const { items: optionsItems, value } = this.options; + const items = isFunction(optionsItems) ? this.__watch(optionsItems, (context, newValue) => { + this.populate(newValue); + }) : optionsItems; this.populate(items); - o.value = BI.isFunction(o.value) ? this.__watch(o.value, function (context, newValue) { - self.setValue(newValue); - }) : o.value; - if (BI.isKey(o.value)) { - this.setValue(o.value); + this.options.value = isFunction(value) ? this.__watch(value, (context, newValue) => { + this.setValue(newValue); + }) : value; + if (isKey(value)) { + this.setValue(value); } - }, + } - _packageBtns: function (items) { - var o = this.options; - var map = this.buttonMap = {}; - var layouts = BI.isArray(o.layouts) ? o.layouts : [o.layouts]; + _packageBtns(items) { + const o = this.options; + const map = this.buttonMap = {}; + const layouts = isArray(o.layouts) ? o.layouts : [o.layouts]; for (let i = layouts.length - 1; i > 0; i--) { - items = BI.map(items, function (k, it) { - var el = BI.stripEL(it); + items = map(items, (k, it) => { + const el = stripEL(it); - return BI.extend({}, layouts[i], { + return extend({}, layouts[i], { items: [ - BI.extend({}, layouts[i].el, { - el: BI.extend({ - ref: function (_ref) { - if (BI.isKey(map[el.value])) { + extend({}, layouts[i].el, { + el: extend({ + ref: (_ref) => { + if (isKey(map[el.value])) { map[el.value] = _ref; } }, @@ -50,33 +57,33 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { } return items; - }, + } - _packageLayout: function (items) { - var o = this.options; - var layouts = BI.isArray(o.layouts) ? o.layouts : [o.layouts]; - var layout = BI.deepClone(layouts[0]); + _packageLayout(items) { + const o = this.options; + const layouts = isArray(o.layouts) ? o.layouts : [o.layouts]; + const layout = deepClone(layouts[0]); - var lay = BI.formatEL(layout).el; - while (lay && lay.items && !BI.isEmpty(lay.items)) { - lay = BI.formatEL(lay.items[0]).el; + let lay = formatEL(layout).el; + while (lay && lay.items && !isEmpty(lay.items)) { + lay = formatEL(lay.items[0]).el; } lay.items = items; return layout; - }, + } - addItems: function (items) { + addItems(items) { this.layouts.addItems(items, this); - }, + } - prependItems: function (items) { + prependItems(items) { this.layouts.prependItems(items, this); - }, + } - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - BI.each(this.buttonMap, function (key, item) { + setValue(v) { + v = isArray(v) ? v : [v]; + each(this.buttonMap, (key, item) => { if (item) { if (v.deepContains(key)) { item.setSelected && item.setSelected(true); @@ -85,11 +92,11 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { } } }); - }, + } - getNotSelectedValue: function () { - var v = []; - BI.each(this.buttonMap, function (i, item) { + getNotSelectedValue() { + const v = []; + each(this.buttonMap, (i, item) => { if (item) { if (item.isEnabled() && !(item.isSelected && item.isSelected())) { v.push(item.getValue()); @@ -98,25 +105,25 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { }); return v; - }, + } - getNodeByValue: function (value) { + getNodeByValue(value) { return this.buttonMap[value]; - }, + } /** * 滚动到指定的节点 */ - scrollToValue: function (value, scrollIntoViewOptions) { - var node = this.getNodeByValue(value); + scrollToValue(value, scrollIntoViewOptions) { + const node = this.getNodeByValue(value); if (node) { node.element[0].scrollIntoView(scrollIntoViewOptions); } - }, + } - getValue: function () { - var v = []; - BI.each(this.buttonMap, function (i, item) { + getValue() { + const v = []; + each(this.buttonMap, (i, item) => { if (item) { if (item.isEnabled() && item.isSelected && item.isSelected()) { v.push(item.getValue()); @@ -125,21 +132,18 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { }); return v; - }, + } - populate: function (items) { + populate(items) { items = items || []; this.options.items = items; items = this._packageBtns(items); if (!this.layouts) { - this.layouts = BI.createWidget(BI.extend({ element: this }, this._packageLayout(items))); + this.layouts = createWidget(extend({ element: this }, this._packageLayout(items))); } else { this.layouts.populate(items, { context: this, }); } - }, -}); -BI.VirtualGroup.EVENT_CHANGE = "EVENT_CHANGE"; - -BI.shortcut("bi.virtual_group", BI.VirtualGroup); + } +} diff --git a/src/base/combination/loader.js b/src/base/combination/loader.js index cf548b024..0ebf26770 100644 --- a/src/base/combination/loader.js +++ b/src/base/combination/loader.js @@ -5,9 +5,16 @@ * @class BI.Loader * @extends BI.Widget */ -BI.Loader = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.Loader.superclass._defaultConfig.apply(this, arguments), { +import { shortcut, Widget, Controller, extend, createWidget, isEmpty, nextTick, bind, isFunction, isNotEmptyArray, isNumber, isObject, each } from "../../core"; + +@shortcut() +export default class Loader extends Widget { + static xtype = "bi.loader"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig() { + return extend(super._defaultConfig(arguments), { baseCls: "bi-loader", direction: "top", @@ -33,115 +40,115 @@ BI.Loader = BI.inherit(BI.Widget, { hasPrev: BI.emptyFn, hasNext: BI.emptyFn, }); - }, + } - _prevLoad: function () { - var self = this, o = this.options; + _prevLoad() { + const o = this.options; this.prev.setLoading(); - o.itemsCreator.apply(this, [{ times: --this.times }, function () { - self.prev.setLoaded(); - self.prependItems.apply(self, arguments); + o.itemsCreator.apply(this, [{ times: --this.times }, (...args) => { + this.prev.setLoaded(); + this.prependItems.apply(this, args); }]); - }, + } - _nextLoad: function () { - var self = this, o = this.options; + _nextLoad() { + const o = this.options; this.next.setLoading(); - o.itemsCreator.apply(this, [{ times: ++this.times }, function () { - self.next.setLoaded(); - self.addItems.apply(self, arguments); + o.itemsCreator.apply(this, [{ times: ++this.times }, (...args) => { + this.next.setLoaded(); + this.addItems.apply(this, args); }]); - }, + } - render: function () { - var self = this, o = this.options; - if (o.itemsCreator === false) { - o.prev = false; - o.next = false; + render() { + const { itemsCreator, prev, next, el, items: optionsItems, value, direction, logic, isDefaultInit } = this.options; + if (itemsCreator === false) { + prev = false; + next = false; } - if (o.prev !== false) { - this.prev = BI.createWidget(BI.extend({ + if (prev !== false) { + this.prev = createWidget(extend({ type: "bi.loading_bar", - }, o.prev)); - this.prev.on(BI.Controller.EVENT_CHANGE, function (type) { + }, prev)); + this.prev.on(Controller.EVENT_CHANGE, (type) => { if (type === BI.Events.CLICK) { - self._prevLoad(); + this._prevLoad(); } }); } - this.button_group = BI.createWidget(o.el, { + this.button_group = createWidget(el, { type: "bi.button_group", chooseType: 0, - items: o.items, + items: optionsItems, behaviors: {}, layouts: [{ type: "bi.vertical", }], - value: o.value, + value, }); - this.button_group.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.button_group.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => { + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); if (type === BI.Events.CLICK) { - self.fireEvent(BI.Loader.EVENT_CHANGE, obj); + this.fireEvent(Loader.EVENT_CHANGE, obj); } }); - if (o.next !== false) { - this.next = BI.createWidget(BI.extend({ + if (next !== false) { + this.next = createWidget(extend({ type: "bi.loading_bar", - }, o.next)); - this.next.on(BI.Controller.EVENT_CHANGE, function (type) { + }, next)); + this.next.on(Controller.EVENT_CHANGE, (type) => { if (type === BI.Events.CLICK) { - self._nextLoad(); + this._nextLoad(); } }); } - BI.createWidget(BI.extend({ + createWidget(extend({ element: this, - }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({ + }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(direction), extend({ scrolly: true, - }, o.logic, { - items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.prev, this.button_group, this.next), + }, logic, { + items: BI.LogicFactory.createLogicItemsByDirection(direction, this.prev, this.button_group, this.next), })))); - o.isDefaultInit && BI.isEmpty(o.items) && BI.nextTick(BI.bind(function () { - o.isDefaultInit && BI.isEmpty(o.items) && this._populate(); + isDefaultInit && isEmpty(optionsItems) && nextTick(bind(() => { + isDefaultInit && isEmpty(optionsItems) && this._populate(); }, this)); - var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { - self.populate(newValue); - }) : o.items; - if (BI.isNotEmptyArray(items)) { + const items = isFunction(optionsItems) ? this.__watch(optionsItems, (context, newValue) => { + this.populate(newValue); + }) : optionsItems; + if (isNotEmptyArray(items)) { this._populate(items); } - }, + } - hasPrev: function () { - var o = this.options; - if (BI.isNumber(o.count)) { - return this.count < o.count; + hasPrev() { + const { count, hasPrev } = this.options; + if (isNumber(count)) { + return this.count < count; } - return !!o.hasPrev.apply(this, [{ + return !!hasPrev.apply(this, [{ times: this.times, count: this.count, }]); - }, + } - hasNext: function () { - var o = this.options; - if (BI.isNumber(o.count)) { - return this.count < o.count; + hasNext() { + const { count, hasNext } = this.options; + if (isNumber(count)) { + return this.count < count; } - return !!o.hasNext.apply(this, [{ + return !!hasNext.apply(this, [{ times: this.times, count: this.count, }]); - }, + } - prependItems: function (items) { + prependItems(items) { this.count += items.length; if (this.next !== false) { if (this.hasPrev()) { @@ -152,11 +159,11 @@ BI.Loader = BI.inherit(BI.Widget, { } } this.button_group.prependItems.apply(this.button_group, arguments); - }, + } - addItems: function (items) { + addItems(items) { this.count += items.length; - if (BI.isObject(this.next)) { + if (isObject(this.next)) { if (this.hasNext()) { this.options.items = this.options.items.concat(items); this.next.setLoaded(); @@ -165,16 +172,16 @@ BI.Loader = BI.inherit(BI.Widget, { } } this.button_group.addItems.apply(this.button_group, arguments); - }, + } - _populate: function (items) { - var self = this, o = this.options; - if (arguments.length === 0 && (BI.isFunction(o.itemsCreator))) { - o.itemsCreator.apply(this, [{ times: 1 }, function () { - if (arguments.length === 0) { + _populate(items) { + const o = this.options; + if (arguments.length === 0 && (isFunction(o.itemsCreator))) { + o.itemsCreator.apply(this, [{ times: 1 }, (...args) => { + if (args.length === 0) { throw new Error("参数不能为空"); } - self.populate.apply(self, arguments); + this.populate.apply(this, args); o.onLoaded(); }]); @@ -184,14 +191,14 @@ BI.Loader = BI.inherit(BI.Widget, { this.times = 1; this.count = 0; this.count += items.length; - if (BI.isObject(this.next)) { + if (isObject(this.next)) { if (this.hasNext()) { this.next.setLoaded(); } else { this.next.invisible(); } } - if (BI.isObject(this.prev)) { + if (isObject(this.prev)) { if (this.hasPrev()) { this.prev.setLoaded(); } else { @@ -200,66 +207,64 @@ BI.Loader = BI.inherit(BI.Widget, { } return true; - }, + } - populate: function () { + populate() { this._populate.apply(this, arguments) && this.button_group.populate.apply(this.button_group, arguments); - }, + } - setNotSelectedValue: function () { + setNotSelectedValue() { this.button_group.setNotSelectedValue.apply(this.button_group, arguments); - }, + } - getNotSelectedValue: function () { + getNotSelectedValue() { return this.button_group.getNotSelectedValue(); - }, + } - setValue: function () { + setValue() { this.button_group.setValue.apply(this.button_group, arguments); - }, + } - getValue: function () { + getValue() { return this.button_group.getValue.apply(this.button_group, arguments); - }, + } - getAllButtons: function () { + getAllButtons() { return this.button_group.getAllButtons(); - }, + } - getAllLeaves: function () { + getAllLeaves() { return this.button_group.getAllLeaves(); - }, + } - getSelectedButtons: function () { + getSelectedButtons() { return this.button_group.getSelectedButtons(); - }, + } - getNotSelectedButtons: function () { + getNotSelectedButtons() { return this.button_group.getNotSelectedButtons(); - }, + } - getIndexByValue: function (value) { + getIndexByValue(value) { return this.button_group.getIndexByValue(value); - }, + } - getNodeById: function (id) { + getNodeById(id) { return this.button_group.getNodeById(id); - }, + } - getNodeByValue: function (value) { + getNodeByValue(value) { return this.button_group.getNodeByValue(value); - }, + } - empty: function () { + empty() { this.button_group.empty(); - BI.each([this.prev, this.next], function (i, ob) { + each([this.prev, this.next], (i, ob) => { ob && ob.setVisible(false); }); - }, - - destroy: function () { - BI.Loader.superclass.destroy.apply(this, arguments); - }, -}); -BI.Loader.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.loader", BI.Loader); + } + + destroy() { + super.destroy(arguments); + } +} diff --git a/src/base/combination/navigation.js b/src/base/combination/navigation.js index 1b347298e..febb44958 100644 --- a/src/base/combination/navigation.js +++ b/src/base/combination/navigation.js @@ -1,10 +1,16 @@ /** * Created by GUY on 2015/6/26. */ +import { shortcut, Widget, Controller, extend, createWidget, bind, ShowListener, isFunction, each, nextTick, isKey, values } from "../../core"; -BI.Navigation = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this, arguments), { +@shortcut() +export default class Navigation extends Widget { + static xtype = "bi.navigation"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig() { + return extend(super._defaultConfig(arguments), { direction: "bottom", // top, bottom, left, right, custom logic: { dynamic: false, @@ -12,160 +18,158 @@ BI.Navigation = BI.inherit(BI.Widget, { single: false, showIndex: false, tab: false, - cardCreator: function (v) { - return BI.createWidget(); + cardCreator: (v) => { + return createWidget(); }, afterCardCreated: BI.emptyFn, afterCardShow: BI.emptyFn, }); - }, + } - render: function () { - var self = this, o = this.options; - this.tab = BI.createWidget(this.options.tab, { type: "bi.button_group" }); + render() { + const { direction, logic, cardCreator, showIndex } = this.options; + this.tab = createWidget(this.options.tab, { type: "bi.button_group" }); this.cardMap = {}; this.showIndex = 0; - this.layout = BI.createWidget({ + this.layout = createWidget({ type: "bi.card", }); - BI.createWidget(BI.extend({ + createWidget(extend({ element: this, - }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, { - items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout), + }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(direction), extend({}, logic, { + items: BI.LogicFactory.createLogicItemsByDirection(direction, this.tab, this.layout), })))); - new BI.ShowListener({ + new ShowListener({ eventObj: this.tab, cardLayout: this.layout, - cardNameCreator: function (v) { - return self.showIndex + v; + cardNameCreator: (v) => { + return this.showIndex + v; }, - cardCreator: function (v) { - BI.Widget.execWithContext(self, function () { - self.cardMap[v] = o.cardCreator(v); + cardCreator: (v) => { + Widget.execWithContext(this, () => { + this.cardMap[v] = cardCreator(v); }); - return self.cardMap[v]; + return this.cardMap[v]; }, - afterCardCreated: BI.bind(this.afterCardCreated, this), - afterCardShow: BI.bind(this.afterCardShow, this), + afterCardCreated: bind(this.afterCardCreated, this), + afterCardShow: bind(this.afterCardShow, this), }); - if (BI.isFunction(o.showIndex)) { - this.__watch(o.showIndex, function (context, newValue) { - self.setSelect(newValue); + if (isFunction(showIndex)) { + this.__watch(showIndex, (context, newValue) => { + this.setSelect(newValue); }); } - }, + } - created: function () { - var o = this.options; - if (o.showIndex !== false) { - this.setSelect(o.showIndex); + created() { + const { showIndex } = this.options; + if (showIndex !== false) { + this.setSelect(showIndex); } - }, + } - _deleteOtherCards: function (currCardName) { - var self = this, o = this.options; - if (o.single === true) { - BI.each(this.cardMap, function (name, card) { + _deleteOtherCards(currCardName) { + const { single } = this.options; + if (single === true) { + each(this.cardMap, (name, card) => { if (name !== (currCardName + "")) { - self.layout.deleteCardByName(name); - delete self.cardMap[name]; + this.layout.deleteCardByName(name); + delete this.cardMap[name]; } }); } - }, + } - afterCardCreated: function (v) { - var self = this; - this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + afterCardCreated(v) { + this.cardMap[v].on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => { + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); if (type === BI.Events.CLICK) { - self.fireEvent(BI.Navigation.EVENT_CHANGE, obj); + this.fireEvent(Navigation.EVENT_CHANGE, obj); } }); this.options.afterCardCreated.apply(this, arguments); - }, + } - afterCardShow: function (v) { + afterCardShow(v) { this.showIndex = v; this._deleteOtherCards(v); this.options.afterCardShow.apply(this, arguments); - }, + } - populate: function () { - var card = this.layout.getShowingCard(); + populate() { + const card = this.layout.getShowingCard(); if (card) { return card.populate.apply(card, arguments); } - }, + } - _assertCard: function (v) { - var self = this, o = this.options; + _assertCard(v) { + const { cardCreator } = this.options; if (!this.layout.isCardExisted(v)) { - BI.Widget.execWithContext(self, function () { - self.cardMap[v] = o.cardCreator(v); + Widget.execWithContext(this, () => { + this.cardMap[v] = cardCreator(v); }); this.layout.addCardByName(v, this.cardMap[v]); this.afterCardCreated(v); } - }, + } - setSelect: function (v) { + setSelect(v) { this._assertCard(v); this.layout.showCardByName(v); this._deleteOtherCards(v); if (this.showIndex !== v) { this.showIndex = v; - BI.nextTick(BI.bind(this.afterCardShow, this, v)); + nextTick(bind(this.afterCardShow, this, v)); } - }, + } - getSelect: function () { + getSelect() { return this.showIndex; - }, + } - getSelectedCard: function () { - if (BI.isKey(this.showIndex)) { + getSelectedCard() { + if (isKey(this.showIndex)) { return this.cardMap[this.showIndex]; } - }, + } - getAllCard: function() { - return BI.values(this.cardMap); - }, + getAllCard() { + return values(this.cardMap); + } /** * @override */ - setValue: function (v) { - var card = this.layout.getShowingCard(); + setValue(v) { + const card = this.layout.getShowingCard(); if (card) { card.setValue(v); } - }, + } /** * @override */ - getValue: function () { - var card = this.layout.getShowingCard(); + getValue() { + const card = this.layout.getShowingCard(); if (card) { return card.getValue(); } - }, + } - empty: function () { + empty() { this.layout.deleteAllCard(); this.cardMap = {}; - }, + } + + destroy() { + super.destroy(arguments); + } - destroy: function () { - BI.Navigation.superclass.destroy.apply(this, arguments); - }, -}); -BI.Navigation.EVENT_CHANGE = "EVENT_CHANGE"; +} -BI.shortcut("bi.navigation", BI.Navigation); diff --git a/src/base/combination/searcher.js b/src/base/combination/searcher.js index 2098f4ce0..56b03f720 100644 --- a/src/base/combination/searcher.js +++ b/src/base/combination/searcher.js @@ -5,10 +5,23 @@ * @class BI.Searcher * @extends BI.Widget */ - -BI.Searcher = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.Searcher.superclass._defaultConfig.apply(this, arguments), { +import { shortcut, Widget, Controller, extend, createWidget, debounce, bind, endWith, deepWithout, nextTick, isEmptyString, isNull } from "../../core"; +import ButtonGroup from "./group.button"; +import { Maskers } from "../0.base"; + +@shortcut() +export default class Searcher extends Widget { + static xtype = "bi.searcher"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + static EVENT_START = "EVENT_START"; + static EVENT_STOP = "EVENT_STOP"; + static EVENT_PAUSE = "EVENT_PAUSE"; + static EVENT_SEARCHING = "EVENT_SEARCHING"; + static EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; + + _defaultConfig() { + return extend(super._defaultConfig(arguments), { baseCls: "bi-searcher", lgap: 0, rgap: 0, @@ -20,10 +33,10 @@ BI.Searcher = BI.inherit(BI.Widget, { isDefaultInit: false, isAutoSearch: true, // 是否自动搜索 isAutoSync: true, // 是否自动同步数据, 即是否保持搜索面板和adapter面板状态值的统一 - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, + chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, // isAutoSearch为false时启用 - onSearch: function (op, callback) { + onSearch: (op, callback) => { callback([]); }, @@ -40,190 +53,191 @@ BI.Searcher = BI.inherit(BI.Widget, { offset: {}, }, }); - }, + } - render: function () { - var self = this, o = this.options; + render() { + const { el, lgap, rgap, tgap, bgap, vgap, hgap, isDefaultInit } = this.options; - this.editor = BI.createWidget(o.el, { + this.editor = createWidget(el, { type: "bi.search_editor", }); - BI.createWidget({ + createWidget({ type: "bi.vertical", element: this, - lgap: o.lgap, - rgap: o.rgap, - tgap: o.tgap, - bgap: o.bgap, - vgap: o.vgap, - hgap: o.hgap, + lgap, + rgap, + tgap, + bgap, + vgap, + hgap, items: [this.editor], }); - o.isDefaultInit && (this._assertPopupView()); + isDefaultInit && (this._assertPopupView()); - var search = BI.debounce(BI.bind(this._search, this), BI.EVENT_RESPONSE_TIME, { + const search = debounce(bind(this._search, this), BI.EVENT_RESPONSE_TIME, { "leading": true, "trailing": false, }); - this.editor.on(BI.Controller.EVENT_CHANGE, function (type) { + this.editor.on(Controller.EVENT_CHANGE, (type) => { switch (type) { case BI.Events.STARTEDIT: - self._startSearch(); + this._startSearch(); break; case BI.Events.EMPTY: - self._stopSearch(); + this._stopSearch(); break; case BI.Events.CHANGE: search(); break; case BI.Events.PAUSE: - if (BI.endWith(this.getValue(), BI.BlankSplitChar)) { - self._pauseSearch(); + if (endWith(this.getValue(), BI.BlankSplitChar)) { + this._pauseSearch(); } break; default: break; } }); - }, + } - _assertPopupView: function () { - var self = this, o = this.options; - if ((o.masker && !BI.Maskers.has(this.getName())) || (o.masker === false && !this.popupView)) { - this.popupView = BI.createWidget(o.popup, { + _assertPopupView() { + const { masker, popup, chooseType, isAutoSync, adapter } = this.options; + if ((masker && !Maskers.has(this.getName())) || (masker === false && !this.popupView)) { + this.popupView = createWidget(popup, { type: "bi.searcher_view", - chooseType: o.chooseType, + chooseType: chooseType, }); - this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.popupView.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => { + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); if (type === BI.Events.CLICK) { - if (o.isAutoSync) { - var values = o.adapter && o.adapter.getValue(); - switch (o.chooseType) { - case BI.ButtonGroup.CHOOSE_TYPE_SINGLE: - o.adapter && o.adapter.setValue([obj.getValue()]); + if (isAutoSync) { + const values = adapter && adapter.getValue(); + switch (chooseType) { + case ButtonGroup.CHOOSE_TYPE_SINGLE: + adapter && adapter.setValue([obj.getValue()]); break; - case BI.ButtonGroup.CHOOSE_TYPE_MULTI: + case ButtonGroup.CHOOSE_TYPE_MULTI: if (!obj.isSelected()) { - o.adapter && o.adapter.setValue(BI.deepWithout(values, obj.getValue())); + adapter && adapter.setValue(deepWithout(values, obj.getValue())); } values.push(obj.getValue()); - o.adapter && o.adapter.setValue(values); + adapter && adapter.setValue(values); break; default: break; } } - self.fireEvent(BI.Searcher.EVENT_CHANGE, value, obj); + this.fireEvent(Searcher.EVENT_CHANGE, value, obj); } }); - BI.nextTick(function () { - self.fireEvent(BI.Searcher.EVENT_AFTER_INIT); + nextTick(() => { + this.fireEvent(Searcher.EVENT_AFTER_INIT); }); } - if (o.masker && !BI.Maskers.has(this.getName())) { - BI.Maskers.create(this.getName(), o.adapter, BI.extend({ + if (masker && !Maskers.has(this.getName())) { + Maskers.create(this.getName(), adapter, extend({ container: this, render: this.popupView, - }, o.masker), this); + }, masker), this); } - }, + } - _startSearch: function () { + _startSearch() { this._assertPopupView(); this._stop = false; this._isSearching = true; - this.fireEvent(BI.Searcher.EVENT_START); + this.fireEvent(Searcher.EVENT_START); this.popupView.startSearch && this.popupView.startSearch(); // 搜索前先清空dom // BI.Maskers.get(this.getName()).empty(); - BI.nextTick(function (name) { - BI.Maskers.show(name); + nextTick((name) => { + Maskers.show(name); }, this.getName()); - }, + } - _pauseSearch: function () { + _pauseSearch() { this._stop = true; - BI.nextTick(function (name) { - BI.Maskers.hide(name); + nextTick((name) => { + Maskers.hide(name); }, this.getName()); if (this._isSearching === true) { this.popupView && this.popupView.pauseSearch && this.popupView.pauseSearch(); - this.fireEvent(BI.Searcher.EVENT_PAUSE); + this.fireEvent(Searcher.EVENT_PAUSE); } this._isSearching = false; - }, + } - _stopSearch: function () { - var name = this.getName(); + _stopSearch() { + const name = this.getName(); this._stop = true; - BI.Maskers.hide(name); + Maskers.hide(name); if (this._isSearching === true) { this.popupView && this.popupView.stopSearch && this.popupView.stopSearch(); - this.fireEvent(BI.Searcher.EVENT_STOP); + this.fireEvent(Searcher.EVENT_STOP); } this._isSearching = false; - }, + } - _search: function () { - var self = this, o = this.options, keyword = this.editor.getValue(); + _search() { + const { isAutoSearch, adapter, isAutoSync, onSearch } = this.options; + const keyword = this.editor.getValue(); if (keyword === "" || this._stop) { return; } - if (o.isAutoSearch) { - var items = (o.adapter && ((o.adapter.getItems && o.adapter.getItems()) || o.adapter.attr("items"))) || []; - var finding = BI.Func.getSearchResult(items, keyword); - var match = finding.match, find = finding.find; + if (isAutoSearch) { + const items = (adapter && ((adapter.getItems && adapter.getItems()) || adapter.attr("items"))) || []; + const finding = BI.Func.getSearchResult(items, keyword); + const match = finding.match, find = finding.find; 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); + isAutoSync && adapter && adapter.getValue && this.popupView.setValue(adapter.getValue()); + this.fireEvent(Searcher.EVENT_SEARCHING); return; } this.popupView.loading && this.popupView.loading(); - o.onSearch({ + onSearch({ times: 1, keyword: keyword, - selectedValues: o.adapter && o.adapter.getValue(), - }, function (searchResult, matchResult) { - if (!self._stop && keyword === self.editor.getValue()) { - var args = [].slice.call(arguments); + selectedValues: adapter && adapter.getValue(), + }, (searchResult, matchResult, ...arg) => { + if (!this._stop && keyword === this.editor.getValue()) { + const args = [searchResult, matchResult, ...arg]; if (args.length > 0) { args.push(keyword); } - BI.Maskers.show(self.getName()); - self.popupView.populate.apply(self.popupView, args); - o.isAutoSync && o.adapter && o.adapter.getValue && self.popupView.setValue(o.adapter.getValue()); - self.popupView.loaded && self.popupView.loaded(); - self.fireEvent(BI.Searcher.EVENT_SEARCHING); + Maskers.show(this.getName()); + this.popupView.populate.apply(this.popupView, args); + isAutoSync && adapter && adapter.getValue && this.popupView.setValue(adapter.getValue()); + this.popupView.loaded && this.popupView.loaded(); + this.fireEvent(Searcher.EVENT_SEARCHING); } }); - }, + } - _getLastSearchKeyword: function () { + _getLastSearchKeyword() { if (this.isValid()) { - var res = this.editor.getValue().split(/\u200b\s\u200b/); - if (BI.isEmptyString(res[res.length - 1])) { + const res = this.editor.getValue().split(/\u200b\s\u200b/); + if (isEmptyString(res[res.length - 1])) { res = res.slice(0, res.length - 1); } - return BI.isNull(res) ? "" : res[res.length - 1]; + return isNull(res) ? "" : res[res.length - 1]; } - }, + } - setAdapter: function (adapter) { + setAdapter(adapter) { this.options.adapter = adapter; - BI.Maskers.remove(this.getName()); - }, + Maskers.remove(this.getName()); + } - doSearch: function () { + doSearch() { if (this.isSearching()) { this._search(); } - }, + } - stopSearch: function () { + stopSearch() { this._stopSearch();// 先停止搜索,然后再去设置editor为空 // important:停止搜索必须退出编辑状态,这里必须加上try(input框不显示时blur会抛异常) try { @@ -235,103 +249,95 @@ BI.Searcher = BI.inherit(BI.Widget, { } finally { this.editor.setValue(""); } - }, + } - isSearching: function () { + isSearching() { return this._isSearching; - }, + } - isViewVisible: function () { - return this.editor.isEnabled() && BI.Maskers.isVisible(this.getName()); - }, + isViewVisible() { + return this.editor.isEnabled() && Maskers.isVisible(this.getName()); + } - getView: function () { + getView() { return this.popupView; - }, + } - hasMatched: function () { + hasMatched() { this._assertPopupView(); return this.popupView.hasMatched(); - }, + } - adjustHeight: function () { - if (BI.Maskers.has(this.getName()) && BI.Maskers.get(this.getName()).isVisible()) { - BI.Maskers.show(this.getName()); + adjustHeight() { + if (Maskers.has(this.getName()) && Maskers.get(this.getName()).isVisible()) { + Maskers.show(this.getName()); } - }, + } - adjustView: function () { - this.isViewVisible() && BI.Maskers.show(this.getName()); - }, + adjustView() { + this.isViewVisible() && Maskers.show(this.getName()); + } - setValue: function (v) { - if (BI.isNull(this.popupView)) { + setValue(v) { + if (isNull(this.popupView)) { this.options.popup.value = v; } else { this.popupView.setValue(v); } - }, + } - getKeyword: function () { + getKeyword() { return this._getLastSearchKeyword(); - }, + } - getKeywords: function () { + getKeywords() { return this.editor.getKeywords(); - }, + } - getValue: function () { - var o = this.options; - if (o.isAutoSync && o.adapter && o.adapter.getValue) { - return o.adapter.getValue(); + getValue() { + const { isAutoSync, adapter, popup } = this.options; + if (isAutoSync && adapter && adapter.getValue) { + return adapter.getValue(); } if (this.isSearching()) { return this.popupView.getValue(); - } else if (o.adapter && o.adapter.getValue) { - return o.adapter.getValue(); + } else if (adapter && adapter.getValue) { + return adapter.getValue(); } - if (BI.isNull(this.popupView)) { - return o.popup.value; + if (isNull(this.popupView)) { + return popup.value; } return this.popupView.getValue(); - }, + } - populate: function (result, searchResult, keyword) { - var o = this.options; + populate(result, searchResult, keyword) { + const { isAutoSync, adapter } = this.options; this._assertPopupView(); this.popupView.populate.apply(this.popupView, arguments); - if (o.isAutoSync && o.adapter && o.adapter.getValue) { - this.popupView.setValue(o.adapter.getValue()); + if (isAutoSync && adapter && adapter.getValue) { + this.popupView.setValue(adapter.getValue()); } - }, + } - empty: function () { + empty() { this.popupView && this.popupView.empty(); - }, + } - destroyed: function () { - BI.Maskers.remove(this.getName()); - }, + destroyed() { + Maskers.remove(this.getName()); + } - focus: function () { + focus() { this.editor.focus(); - }, + } - blur: function () { + blur() { this.editor.blur(); - }, + } - setWaterMark: function (v) { + setWaterMark(v) { this.editor.setWaterMark(v); - }, -}); -BI.Searcher.EVENT_CHANGE = "EVENT_CHANGE"; -BI.Searcher.EVENT_START = "EVENT_START"; -BI.Searcher.EVENT_STOP = "EVENT_STOP"; -BI.Searcher.EVENT_PAUSE = "EVENT_PAUSE"; -BI.Searcher.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.Searcher.EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; - -BI.shortcut("bi.searcher", BI.Searcher); + } +} diff --git a/src/base/combination/switcher.js b/src/base/combination/switcher.js index 419711595..e89b31314 100644 --- a/src/base/combination/switcher.js +++ b/src/base/combination/switcher.js @@ -6,9 +6,26 @@ * @class BI.Switcher * @extends BI.Widget */ -BI.Switcher = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.Switcher.superclass._defaultConfig.apply(this, arguments), { +import { shortcut, Widget, Controller, extend, nextTick, createWidget, each, debounce, isNull } from "../../core"; +import { Maskers } from "../0.base"; + +@shortcut() +export default class Switcher extends Widget { + static xtype = "bi.switcher"; + + static EVENT_EXPAND = "EVENT_EXPAND"; + static EVENT_COLLAPSE = "EVENT_COLLAPSE"; + static EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; + static EVENT_CHANGE = "EVENT_CHANGE"; + static EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; + + static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; + static EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; + static EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; + static EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; + + _defaultConfig() { + return extend(super._defaultConfig(arguments), { baseCls: "bi-switcher", direction: BI.Direction.Top, trigger: "click", @@ -20,47 +37,47 @@ BI.Switcher = BI.inherit(BI.Widget, { switcherClass: "bi-switcher-popup", hoverClass: "bi-switcher-hover", }); - }, + } - render: function () { - var self = this, o = this.options; + render() { + const { hoverClass, isDefaultInit } = this.options; this._initSwitcher(); // 延迟绑定事件,这样可以将自己绑定的事情优先执行 - BI.nextTick(() => { + nextTick(() => { !this.isDestroyed() && this._initPullDownAction(); }); - this.switcher.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - if (self.isEnabled() && self.isValid()) { + this.switcher.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => { + if (this.isEnabled() && this.isValid()) { if (type === BI.Events.EXPAND) { - self._popupView(); + this._popupView(); } if (type === BI.Events.COLLAPSE) { - self._hideView(); + this._hideView(); } if (type === BI.Events.EXPAND) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - self.fireEvent(BI.Switcher.EVENT_EXPAND); + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); + this.fireEvent(Switcher.EVENT_EXPAND); } if (type === BI.Events.COLLAPSE) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - self.isViewVisible() && self.fireEvent(BI.Switcher.EVENT_COLLAPSE); + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); + this.isViewVisible() && this.fireEvent(Switcher.EVENT_COLLAPSE); } if (type === BI.Events.CLICK) { - self.fireEvent(BI.Switcher.EVENT_TRIGGER_CHANGE, value, obj); + this.fireEvent(Switcher.EVENT_TRIGGER_CHANGE, value, obj); } } }); - this.element.hover(function () { - if (self.isEnabled() && self.switcher.isEnabled()) { - self.element.addClass(o.hoverClass); + this.element.hover(() => { + if (this.isEnabled() && this.switcher.isEnabled()) { + this.element.addClass(hoverClass); } - }, function () { - if (self.isEnabled() && self.switcher.isEnabled()) { - self.element.removeClass(o.hoverClass); + }, () => { + if (this.isEnabled() && this.switcher.isEnabled()) { + this.element.removeClass(hoverClass); } }); - BI.createWidget({ + createWidget({ type: "bi.vertical", scrolly: false, element: this, @@ -68,10 +85,10 @@ BI.Switcher = BI.inherit(BI.Widget, { { el: this.switcher } ], }); - o.isDefaultInit && (this._assertPopupView()); - }, + isDefaultInit && (this._assertPopupView()); + } - _toggle: function () { + _toggle() { this._assertPopupView(); if (this.isExpanded()) { this._hideView(); @@ -80,40 +97,40 @@ BI.Switcher = BI.inherit(BI.Widget, { this._popupView(); } } - }, + } - _initPullDownAction: function () { - var self = this, o = this.options; - var evs = this.options.trigger.split(","); - BI.each(evs, function (i, e) { + _initPullDownAction() { + const { toggle } = this.options; + const evs = this.options.trigger.split(","); + each(evs, (i, e) => { switch (e) { case "hover": - self.element[e](function (e) { - if (self.isEnabled() && self.switcher.isEnabled()) { - self._popupView(); - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.switcher); - self.fireEvent(BI.Switcher.EVENT_EXPAND); + this.element[e]((e) => { + if (this.isEnabled() && this.switcher.isEnabled()) { + this._popupView(); + this.fireEvent(Controller.EVENT_CHANGE, BI.Events.EXPAND, "", this.switcher); + this.fireEvent(Switcher.EVENT_EXPAND); } - }, function () { - if (self.isEnabled() && self.switcher.isEnabled() && o.toggle) { - self._hideView(); - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.switcher); - self.fireEvent(BI.Switcher.EVENT_COLLAPSE); + }, () => { + if (this.isEnabled() && this.switcher.isEnabled() && toggle) { + this._hideView(); + this.fireEvent(Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", this.switcher); + this.fireEvent(Switcher.EVENT_COLLAPSE); } }); break; default : if (e) { - self.element.off(e + "." + self.getName()).on(e + "." + self.getName(), BI.debounce(function (e) { - if (self.switcher.element.__isMouseInBounds__(e)) { - if (self.isEnabled() && self.switcher.isEnabled()) { - o.toggle ? self._toggle() : self._popupView(); - if (self.isExpanded()) { - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.switcher); - self.fireEvent(BI.Switcher.EVENT_EXPAND); + this.element.off(e + "." + this.getName()).on(e + "." + this.getName(), debounce((e) => { + if (this.switcher.element.__isMouseInBounds__(e)) { + if (this.isEnabled() && this.switcher.isEnabled()) { + toggle ? this._toggle() : this._popupView(); + if (this.isExpanded()) { + this.fireEvent(Controller.EVENT_CHANGE, BI.Events.EXPAND, "", this.switcher); + this.fireEvent(Switcher.EVENT_EXPAND); } else { - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.switcher); - self.fireEvent(BI.Switcher.EVENT_COLLAPSE); + this.fireEvent(Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", this.switcher); + this.fireEvent(Switcher.EVENT_COLLAPSE); } } } @@ -125,36 +142,36 @@ BI.Switcher = BI.inherit(BI.Widget, { break; } }); - }, + } - _initSwitcher: function () { - this.switcher = BI.createWidget(this.options.el, { + _initSwitcher() { + this.switcher = createWidget(this.options.el, { value: this.options.value, }); - }, + } - _assertPopupView: function () { - var self = this, o = this.options; + _assertPopupView() { + const { popup, adapter, masker, value, direction } = this.options; if (!this._created) { - this.popupView = BI.createWidget(o.popup, { + this.popupView = createWidget(popup, { type: "bi.button_group", - element: o.adapter && BI.Maskers.create(this.getName(), o.adapter, BI.extend({ container: this }, o.masker)), + element: adapter && Maskers.create(this.getName(), adapter, extend({ container: this }, masker)), cls: "switcher-popup", layouts: [{ type: "bi.vertical", hgap: 0, vgap: 0, }], - value: o.value, + value, }, this); - this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.popupView.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => { + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); if (type === BI.Events.CLICK) { - self.fireEvent(BI.Switcher.EVENT_CHANGE, value, obj); + this.fireEvent(Switcher.EVENT_CHANGE, value, obj); } }); - if (o.direction !== BI.Direction.Custom && !o.adapter) { - BI.createWidget({ + if (direction !== BI.Direction.Custom && !adapter) { + createWidget({ type: "bi.vertical", scrolly: false, element: this, @@ -164,133 +181,120 @@ BI.Switcher = BI.inherit(BI.Widget, { }); } this._created = true; - BI.nextTick(function () { - self.fireEvent(BI.Switcher.EVENT_AFTER_INIT); + nextTick(() => { + this.fireEvent(Switcher.EVENT_AFTER_INIT); }); } - }, + } - _hideView: function () { - this.fireEvent(BI.Switcher.EVENT_BEFORE_HIDEVIEW); - var self = this, o = this.options; - o.adapter ? BI.Maskers.hide(self.getName()) : (self.popupView && self.popupView.setVisible(false)); - BI.nextTick(function () { - o.adapter ? BI.Maskers.hide(self.getName()) : (self.popupView && self.popupView.setVisible(false)); - self.element.removeClass(o.switcherClass); - self.fireEvent(BI.Switcher.EVENT_AFTER_HIDEVIEW); + _hideView() { + this.fireEvent(Switcher.EVENT_BEFORE_HIDEVIEW); + const { adapter, switcherClass } = this.options; + adapter ? Maskers.hide(this.getName()) : (this.popupView && this.popupView.setVisible(false)); + nextTick(() => { + adapter ? Maskers.hide(this.getName()) : (this.popupView && this.popupView.setVisible(false)); + this.element.removeClass(switcherClass); + this.fireEvent(Switcher.EVENT_AFTER_HIDEVIEW); }); - }, + } - _popupView: function () { - var self = this, o = this.options; + _popupView() { + const { adapter, switcherClass } = this.options; this._assertPopupView(); - this.fireEvent(BI.Switcher.EVENT_BEFORE_POPUPVIEW); - o.adapter ? BI.Maskers.show(this.getName()) : self.popupView.setVisible(true); - BI.nextTick(function (name) { - o.adapter ? BI.Maskers.show(name) : self.popupView.setVisible(true); - self.element.addClass(o.switcherClass); - self.fireEvent(BI.Switcher.EVENT_AFTER_POPUPVIEW); + this.fireEvent(Switcher.EVENT_BEFORE_POPUPVIEW); + adapter ? Maskers.show(this.getName()) : this.popupView.setVisible(true); + nextTick((name) => { + adapter ? Maskers.show(name) : this.popupView.setVisible(true); + this.element.addClass(switcherClass); + this.fireEvent(Switcher.EVENT_AFTER_POPUPVIEW); }, this.getName()); - }, + } - _populate: function () { + _populate() { this._assertPopupView(); this.popupView.populate.apply(this.popupView, arguments); - }, + } - populate: function (items) { + populate(items) { this._populate.apply(this, arguments); this.switcher.populate && this.switcher.populate.apply(this.switcher, arguments); - }, + } - _setEnable: function (arg) { - BI.Switcher.superclass._setEnable.apply(this, arguments); + _setEnable(arg) { + super._setEnable(arguments); !arg && this.isViewVisible() && this._hideView(); - }, + } - setValue: function (v) { + setValue(v) { this.switcher.setValue(v); - if (BI.isNull(this.popupView)) { + if (isNull(this.popupView)) { this.options.popup.value = v; } else { this.popupView.setValue(v); } - }, + } - getValue: function () { - if (BI.isNull(this.popupView)) { + getValue() { + if (isNull(this.popupView)) { return this.options.popup.value; } else { return this.popupView.getValue(); } - }, + } - setAdapter: function (adapter) { + setAdapter(adapter) { this.options.adapter = adapter; - BI.Maskers.remove(this.getName()); - }, + Maskers.remove(this.getName()); + } - isViewVisible: function () { + isViewVisible() { return this.isEnabled() && this.switcher.isEnabled() && - (this.options.adapter ? BI.Maskers.isVisible(this.getName()) : (this.popupView && this.popupView.isVisible())); - }, + (this.options.adapter ? Maskers.isVisible(this.getName()) : (this.popupView && this.popupView.isVisible())); + } - isExpanded: function () { + isExpanded() { return this.isViewVisible(); - }, + } - showView: function () { + showView() { if (this.isEnabled() && this.switcher.isEnabled()) { this._popupView(); } - }, + } - hideView: function () { + hideView() { this._hideView(); - }, + } - getView: function () { + getView() { return this.popupView; - }, + } - adjustView: function () { - this.isViewVisible() && BI.Maskers.show(this.getName()); - }, + adjustView() { + this.isViewVisible() && Maskers.show(this.getName()); + } - getAllLeaves: function () { + getAllLeaves() { return this.popupView && this.popupView.getAllLeaves(); - }, + } - getNodeById: function (id) { + getNodeById(id) { if (this.switcher.attr("id") === id) { return this.switcher; } return this.popupView && this.popupView.getNodeById(id); - }, + } - getNodeByValue: function (value) { + getNodeByValue(value) { if (this.switcher.getValue() === value) { return this.switcher; } return this.popupView && this.popupView.getNodeByValue(value); - }, + } - empty: function () { + empty() { this.popupView && this.popupView.empty(); - }, -}); -BI.Switcher.EVENT_EXPAND = "EVENT_EXPAND"; -BI.Switcher.EVENT_COLLAPSE = "EVENT_COLLAPSE"; -BI.Switcher.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; -BI.Switcher.EVENT_CHANGE = "EVENT_CHANGE"; -BI.Switcher.EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; - - -BI.Switcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.Switcher.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; -BI.Switcher.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; -BI.Switcher.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; - -BI.shortcut("bi.switcher", BI.Switcher); + } +} diff --git a/src/base/combination/tab.js b/src/base/combination/tab.js index 933496004..7fcce06c4 100644 --- a/src/base/combination/tab.js +++ b/src/base/combination/tab.js @@ -1,10 +1,16 @@ /** * Created by GUY on 2015/6/26. */ +import { shortcut, Widget, Controller, ShowListener, extend, createWidget, isObject, each, isFunction, contains, any, isEqual } from "../../core"; -BI.Tab = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.Tab.superclass._defaultConfig.apply(this, arguments), { +@shortcut() +export default class Tab extends Widget { + static xtype = "bi.tab"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig() { + return extend(super._defaultConfig(arguments), { baseCls: "bi-tab", direction: "top", // top, bottom, left, right, custom single: false, // 是不是单页面 @@ -13,87 +19,87 @@ BI.Tab = BI.inherit(BI.Widget, { }, showIndex: false, tab: false, - cardCreator: function (v) { - return BI.createWidget(); + cardCreator: (v) => { + return createWidget(); }, keepAlives: [], }); - }, - - render: function () { - var self = this, o = this.options; - if (BI.isObject(o.tab)) { - this.tab = BI.createWidget(this.options.tab, { type: "bi.button_group" }); - this.tab.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + } + + render() { + const { tab, direction, logic, cardCreator } = this.options; + if (isObject(tab)) { + this.tab = createWidget(this.options.tab, { type: "bi.button_group" }); + this.tab.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => { + this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args); }); } this.cardMap = {}; - this.layout = BI.createWidget({ + this.layout = createWidget({ type: "bi.card", }); - BI.createWidget(BI.extend({ + createWidget(extend({ element: this, - }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, { - items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout), + }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(direction), extend({}, logic, { + items: BI.LogicFactory.createLogicItemsByDirection(direction, this.tab, this.layout), })))); - var listener = new BI.ShowListener({ + const listener = new ShowListener({ eventObj: this.tab, cardLayout: this.layout, - cardCreator: function (v) { - BI.Widget.execWithContext(self, function () { - self.cardMap[v] = o.cardCreator(v); + cardCreator: (v) => { + Widget.execWithContext(this, () => { + this.cardMap[v] = cardCreator(v); }); - return self.cardMap[v]; + return this.cardMap[v]; }, - afterCardShow: function (v) { - self._deleteOtherCards(v); - self.curr = v; + afterCardShow: (v) => { + this._deleteOtherCards(v); + this.curr = v; }, }); - listener.on(BI.ShowListener.EVENT_CHANGE, function (value) { - self.fireEvent(BI.Tab.EVENT_CHANGE, value, self); + listener.on(ShowListener.EVENT_CHANGE, (value) => { + this.fireEvent(Tab.EVENT_CHANGE, value, this); }); - }, - - _deleteOtherCards: function (currCardName) { - var self = this, o = this.options; - if (o.single === true) { - BI.each(this.cardMap, function (name, card) { - if (name !== (currCardName + "") && self._keepAlive(name) !== true) { - self.layout.deleteCardByName(name); - delete self.cardMap[name]; + } + + _deleteOtherCards(currCardName) { + const { single } = this.options; + if (single === true) { + each(this.cardMap, (name, card) => { + if (name !== (currCardName + "") && this._keepAlive(name) !== true) { + this.layout.deleteCardByName(name); + delete this.cardMap[name]; } }); } - }, + } - _assertCard: function (v) { - var self = this, o = this.options; + _assertCard(v) { + const { cardCreator } = this.options; if (!this.layout.isCardExisted(v)) { - BI.Widget.execWithContext(this, function () { - self.cardMap[v] = o.cardCreator(v); + Widget.execWithContext(this, () => { + this.cardMap[v] = cardCreator(v); }); this.layout.addCardByName(v, this.cardMap[v]); } - }, + } - _keepAlive: function (v) { - var o = this.options; + _keepAlive(v) { + const { keepAlives } = this.options; - return BI.isFunction(o.keepAlives) ? o.keepAlives(v) : BI.contains(o.keepAlives, v); - }, + return isFunction(keepAlives) ? keepAlives(v) : contains(keepAlives, v); + } - created: function () { - var self = this, o = this.options; + created() { + const o = this.options; + let showIndex; - var showIndex; - if (BI.isFunction(o.showIndex)) { - showIndex = this.__watch(o.showIndex, function (context, newValue) { - self.setSelect(newValue); + if (isFunction(o.showIndex)) { + showIndex = this.__watch(o.showIndex, (context, newValue) => { + this.setSelect(newValue); }); } else { showIndex = o.showIndex; @@ -102,9 +108,9 @@ BI.Tab = BI.inherit(BI.Widget, { if (showIndex !== false) { this.setSelect(showIndex); } - }, + } - setSelect: function (v, action, callback) { + setSelect(v, action, callback) { this.tab && this.tab.setValue(v); this._assertCard(v); this.layout.showCardByName(v, action, callback); @@ -112,69 +118,66 @@ BI.Tab = BI.inherit(BI.Widget, { if (this.curr !== v) { this.curr = v; } - }, + } - removeTab: function (cardname) { - var self = this; - BI.any(this.cardMap, function (name, card) { - if (BI.isEqual(name, (cardname + ""))) { - self.layout.deleteCardByName(name); - delete self.cardMap[name]; + removeTab(cardname) { + any(this.cardMap, (name, card) => { + if (isEqual(name, (cardname + ""))) { + this.layout.deleteCardByName(name); + delete this.cardMap[name]; return true; } }); - }, + } - isCardExisted: function (cardName) { + isCardExisted(cardName) { return this.layout.isCardExisted(cardName); - }, + } - getSelect: function () { + getSelect() { return this.curr; - }, + } - getSelectedTab: function () { + getSelectedTab() { return this.layout.getShowingCard(); - }, + } - getTab: function (v) { + getTab(v) { this._assertCard(v); return this.layout.getCardByName(v); - }, + } - setValue: function (v) { - var card = this.layout.getShowingCard(); + setValue(v) { + const card = this.layout.getShowingCard(); if (card) { card.setValue(v); } - }, + } - getValue: function () { - var card = this.layout.getShowingCard(); + getValue() { + const card = this.layout.getShowingCard(); if (card) { return card.getValue(); } - }, + } - populate: function () { - var card = this.layout.getShowingCard(); + populate() { + const card = this.layout.getShowingCard(); if (card) { return card.populate && card.populate.apply(card, arguments); } - }, + } - empty: function () { + empty() { this.layout.deleteAllCard(); this.cardMap = {}; - }, + } - destroy: function () { + destroy() { this.cardMap = {}; - BI.Tab.superclass.destroy.apply(this, arguments); - }, -}); -BI.Tab.EVENT_CHANGE = "EVENT_CHANGE"; + super.destroy(arguments); + } -BI.shortcut("bi.tab", BI.Tab); +} diff --git a/src/base/combination/tree.button.js b/src/base/combination/tree.button.js index cfa9a3c3b..6ed1a1b3f 100644 --- a/src/base/combination/tree.button.js +++ b/src/base/combination/tree.button.js @@ -3,67 +3,74 @@ * @class BI.ButtonTree * @extends BI.ButtonGroup */ +import { shortcut, Widget, extend, isArray, each, isFunction, deepContains, concat, any, contains } from "../../core"; +import ButtonGroup from "./group.button"; -BI.ButtonTree = BI.inherit(BI.ButtonGroup, { - _defaultConfig: function () { - return BI.extend(BI.ButtonTree.superclass._defaultConfig.apply(this, arguments), { +@shortcut() +export default class ButtonTree extends ButtonGroup { + static xtype = "bi.button_tree"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig() { + return extend(super._defaultConfig(arguments), { baseCls: "bi-button-tree", }); - }, + } - setNotSelectedValue: function (v) { - v = BI.isArray(v) ? v : [v]; - BI.each(this.buttons, function (i, item) { - if (!BI.isFunction(item.setSelected)) { + setNotSelectedValue(v) { + v = isArray(v) ? v : [v]; + each(this.buttons, (i, item) => { + if (!isFunction(item.setSelected)) { item.setNotSelectedValue(v); return; } - if (BI.deepContains(v, item.getValue())) { + if (deepContains(v, item.getValue())) { item.setSelected(false); } else { item.setSelected(true); } }); - }, + } - setEnabledValue: function (v) { - v = BI.isArray(v) ? v : [v]; - BI.each(this.buttons, function (i, item) { - if (BI.isFunction(item.setEnabledValue)) { + setEnabledValue(v) { + v = isArray(v) ? v : [v]; + each(this.buttons, (i, item) => { + if (isFunction(item.setEnabledValue)) { item.setEnabledValue(v); return; } - if (BI.deepContains(v, item.getValue())) { + if (deepContains(v, item.getValue())) { item.setEnable(true); } else { item.setEnable(false); } }); - }, + } - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - BI.each(this.buttons, function (i, item) { - if (!BI.isFunction(item.setSelected)) { + setValue(v) { + v = isArray(v) ? v : [v]; + each(this.buttons, (i, item) => { + if (!isFunction(item.setSelected)) { item.setValue(v); return; } - if (BI.deepContains(v, item.getValue())) { + if (deepContains(v, item.getValue())) { item.setSelected(true); } else { item.setSelected(false); } }); - }, + } - getNotSelectedValue: function () { - var v = []; - BI.each(this.buttons, function (i, item) { - if (item.isEnabled() && !BI.isFunction(item.setSelected)) { - v = BI.concat(v, item.getNotSelectedValue()); + getNotSelectedValue() { + let v = []; + each(this.buttons, (i, item) => { + if (item.isEnabled() && !isFunction(item.setSelected)) { + v = concat(v, item.getNotSelectedValue()); return; } @@ -73,13 +80,13 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { }); return v; - }, + } - getValue: function () { - var v = []; - BI.each(this.buttons, function (i, item) { - if (item.isEnabled() && !BI.isFunction(item.setSelected)) { - v = BI.concat(v, item.getValue()); + getValue() { + let v = []; + each(this.buttons, (i, item) => { + if (item.isEnabled() && !isFunction(item.setSelected)) { + v = concat(v, item.getValue()); return; } @@ -89,12 +96,12 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { }); return v; - }, + } - getSelectedButtons: function () { - var btns = []; - BI.each(this.buttons, function (i, item) { - if (item.isEnabled() && !BI.isFunction(item.setSelected)) { + getSelectedButtons() { + let btns = []; + each(this.buttons, (i, item) => { + if (item.isEnabled() && !isFunction(item.setSelected)) { btns = btns.concat(item.getSelectedButtons()); return; @@ -105,12 +112,12 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { }); return btns; - }, + } - getNotSelectedButtons: function () { - var btns = []; - BI.each(this.buttons, function (i, item) { - if (item.isEnabled() && !BI.isFunction(item.setSelected)) { + getNotSelectedButtons() { + let btns = []; + each(this.buttons, (i, item) => { + if (item.isEnabled() && !isFunction(item.setSelected)) { btns = btns.concat(item.getNotSelectedButtons()); return; @@ -121,13 +128,13 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { }); return btns; - }, + } // 获取所有的叶子节点 - getAllLeaves: function () { - var leaves = []; - BI.each(this.buttons, function (i, item) { - if (item.isEnabled() && !BI.isFunction(item.setSelected)) { + getAllLeaves() { + let leaves = []; + each(this.buttons, (i, item) => { + if (item.isEnabled() && !isFunction(item.setSelected)) { leaves = leaves.concat(item.getAllLeaves()); return; @@ -138,13 +145,13 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { }); return leaves; - }, + } - getIndexByValue: function (value) { - var index = -1; - BI.any(this.buttons, function (i, item) { - var vs = item.getValue(); - if (item.isEnabled() && (vs === value || BI.contains(vs, value))) { + getIndexByValue(value) { + let index = -1; + any(this.buttons, (i, item) => { + const vs = item.getValue(); + if (item.isEnabled() && (vs === value || contains(vs, value))) { index = i; return true; @@ -152,17 +159,17 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { }); return index; - }, + } - getNodeById: function (id) { - var node; - BI.any(this.buttons, function (i, item) { + getNodeById(id) { + let node; + any(this.buttons, (i, item) => { if (item.isEnabled()) { if (item.attr("id") === id) { node = item; return true; - } else if (BI.isFunction(item.getNodeById)) { + } else if (isFunction(item.getNodeById)) { node = item.getNodeById(id); if (node) { return true; @@ -172,13 +179,13 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { }); return node; - }, + } - getNodeByValue: function (value) { - var node; - BI.any(this.buttons, function (i, item) { + getNodeByValue(value) { + let node; + any(this.buttons, (i, item) => { if (item.isEnabled()) { - if (BI.isFunction(item.getNodeByValue)) { + if (isFunction(item.getNodeByValue)) { node = item.getNodeByValue(value); if (node) { return true; @@ -192,8 +199,5 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, { }); return node; - }, -}); -BI.ButtonTree.EVENT_CHANGE = "EVENT_CHANGE"; - -BI.shortcut("bi.button_tree", BI.ButtonTree); + } +} diff --git a/src/base/index.js b/src/base/index.js index b5f9c4faa..723070d48 100644 --- a/src/base/index.js +++ b/src/base/index.js @@ -1,3 +1,4 @@ +import { extend } from "../core"; import Pane from "./1.pane"; import Single from "./single/0.single"; import Text from "./single/1.text"; @@ -14,9 +15,20 @@ import VirtualGroupList from "./list/virtualgrouplist"; import VirtualList from "./list/virtuallist"; import GridView from "./grid/grid"; import Pager from "./pager/pager"; +import Bubble from "./combination/bubble"; +import Combo from "./combination/combo"; +import Expander from "./combination/expander"; +import ButtonGroup from "./combination/group.button"; +import ComboGroup from "./combination/group.combo"; +import VirtualGroup from "./combination/group.virtual"; +import Loader from "./combination/loader"; +import Navigation from "./combination/navigation"; +import Searcher from "./combination/searcher"; +import Switcher from "./combination/switcher"; +import Tab from "./combination/tab"; +import ButtonTree from "./combination/tree.button"; - -BI.extend(BI, { +extend(BI, { Pane, Single, Text, @@ -34,6 +46,18 @@ BI.extend(BI, { VirtualList, GridView, Pager, + Bubble, + Combo, + Expander, + ButtonGroup, + ComboGroup, + VirtualGroup, + Loader, + Navigation, + Searcher, + Switcher, + Tab, + ButtonTree, }); export { @@ -54,4 +78,16 @@ export { VirtualList, GridView, Pager, + Bubble, + Combo, + Expander, + ButtonGroup, + ComboGroup, + VirtualGroup, + Loader, + Navigation, + Searcher, + Switcher, + Tab, + ButtonTree, } \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 18b15a0f2..8295b976b 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -16,6 +16,7 @@ import PopoverController from "./controller/controller.popover"; import ResizeController from "./controller/controller.resizer"; import TooltipsController from "./controller/controller.tooltips"; import StyleLoaderManager from "./loader/loader.style"; +import ShowListener from "./listener/listener.show"; BI.extend(BI, { OB, @@ -35,6 +36,7 @@ BI.extend(BI, { ResizeController, TooltipsController, StyleLoaderManager, + ShowListener, }); export * from './2.base'; @@ -60,4 +62,5 @@ export { ResizeController, TooltipsController, StyleLoaderManager, + ShowListener, } \ No newline at end of file diff --git a/src/core/listener/listener.show.js b/src/core/listener/listener.show.js index af2236578..1c9469473 100644 --- a/src/core/listener/listener.show.js +++ b/src/core/listener/listener.show.js @@ -5,44 +5,50 @@ * @class BI.ShowListener * @extends BI.OB */ -BI.ShowListener = BI.inherit(BI.OB, { - props: function () { +import OB from "../3.ob"; +import { isArray, isNull, nextTick, } from "../2.base"; +import { createWidget } from "../5.inject"; +import Controller from "../controller/0.controller"; + +export default class ShowListener extends OB { + static EVENT_CHANGE = "EVENT_CHANGE"; + + props() { return { - eventObj: BI.createWidget(), + eventObj: createWidget(), cardLayout: null, - cardNameCreator: function (v) { + cardNameCreator: (v) => { return v; }, cardCreator: BI.emptyFn, afterCardCreated: BI.emptyFn, afterCardShow: BI.emptyFn }; - }, + } - init: function () { - var self = this, o = this.options; - if (o.eventObj) { - o.eventObj.on(BI.Controller.EVENT_CHANGE, function (type, v, ob) { + init() { + const { eventObj, cardLayout, afterCardCreated, cardNameCreator, cardCreator, afterCardShow } = this.options; + if (eventObj) { + eventObj.on(Controller.EVENT_CHANGE, (type, v, ob) => { if (type === BI.Events.CLICK) { - v = v || o.eventObj.getValue(); - v = BI.isArray(v) ? (v.length > 1 ? v.toString() : v[0]) : v; - if (BI.isNull(v)) { + v = v || eventObj.getValue(); + v = isArray(v) ? (v.length > 1 ? v.toString() : v[0]) : v; + if (isNull(v)) { throw new Error("不能为null"); } - var cardName = o.cardNameCreator(v); - if (!o.cardLayout.isCardExisted(cardName)) { - var card = o.cardCreator(cardName); - o.cardLayout.addCardByName(cardName, card); - o.afterCardCreated(cardName); + var cardName = cardNameCreator(v); + if (!cardLayout.isCardExisted(cardName)) { + const card = cardCreator(cardName); + cardLayout.addCardByName(cardName, card); + afterCardCreated(cardName); } - o.cardLayout.showCardByName(cardName); - BI.nextTick(function () { - o.afterCardShow(cardName); - self.fireEvent(BI.ShowListener.EVENT_CHANGE, cardName); + cardLayout.showCardByName(cardName); + nextTick(() => { + afterCardShow(cardName); + this.fireEvent(ShowListener.EVENT_CHANGE, cardName); }); } }); } } -}); -BI.ShowListener.EVENT_CHANGE = "EVENT_CHANGE"; +} From 15b9445faed5444ba0904058eb53b9a9d6d811aa Mon Sep 17 00:00:00 2001 From: zsmj Date: Tue, 3 Jan 2023 20:19:03 +0800 Subject: [PATCH 3/7] =?UTF-8?q?KERNEL-13991=20feat:=20core/func=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/2.base.js | 30 +- src/core/func/alias.js | 1654 +++++++++--------- src/core/func/array.js | 29 +- src/core/func/date.js | 615 ++++--- src/core/func/function.js | 300 ++-- src/core/func/index.js | 23 + src/core/func/number.js | 274 ++- src/core/func/string.js | 224 ++- src/core/index.js | 8 +- src/core/platform/web/detectElementResize.js | 123 +- src/core/utils/chinesePY.js | 863 ++++----- 11 files changed, 2125 insertions(+), 2018 deletions(-) create mode 100644 src/core/func/index.js diff --git a/src/core/2.base.js b/src/core/2.base.js index 46bf10e92..a4e8df688 100644 --- a/src/core/2.base.js +++ b/src/core/2.base.js @@ -157,8 +157,10 @@ BI._.extend(BI, { BI._.each(["where", "findWhere", "invoke", "pluck", "shuffle", "sample", "toArray", "size"], function (name) { BI[name] = _apply(name); }); -BI._.each(["get", "set", "each", "map", "reduce", "reduceRight", "find", "filter", "reject", "every", "all", "some", "any", "max", "min", - "sortBy", "groupBy", "indexBy", "countBy", "partition", "clamp"], function (name) { +BI._.each([ + "get", "set", "each", "map", "reduce", "reduceRight", "find", "filter", "reject", "every", "all", "some", "any", "max", "min", + "sortBy", "groupBy", "indexBy", "countBy", "partition", "clamp" +], function (name) { if (name === "any") { BI[name] = _applyFunc("some"); } else { @@ -404,8 +406,10 @@ BI._.extend(BI, { }); // 数组相关的方法 -BI._.each(["first", "initial", "last", "rest", "compact", "flatten", "without", "union", "intersection", - "difference", "zip", "unzip", "object", "indexOf", "lastIndexOf", "sortedIndex", "range", "take", "takeRight", "uniqBy"], function (name) { +BI._.each([ + "first", "initial", "last", "rest", "compact", "flatten", "without", "union", "intersection", + "difference", "zip", "unzip", "object", "indexOf", "lastIndexOf", "sortedIndex", "range", "take", "takeRight", "uniqBy" +], function (name) { BI[name] = _apply(name); }); BI._.each(["findIndex", "findLastIndex"], function (name) { @@ -497,10 +501,12 @@ BI._.extend(BI, { }); // 对象相关方法 -BI._.each(["keys", "allKeys", "values", "pairs", "invert", "create", "functions", "extend", "extendOwn", +BI._.each([ + "keys", "allKeys", "values", "pairs", "invert", "create", "functions", "extend", "extendOwn", "defaults", "clone", "property", "propertyOf", "matcher", "isEqual", "isMatch", "isEmpty", "isElement", "isNumber", "isString", "isArray", "isObject", "isPlainObject", "isArguments", "isFunction", "isFinite", - "isBoolean", "isDate", "isRegExp", "isError", "isNaN", "isUndefined", "zipObject", "cloneDeep"], function (name) { + "isBoolean", "isDate", "isRegExp", "isError", "isNaN", "isUndefined", "zipObject", "cloneDeep" +], function (name) { BI[name] = _apply(name); }); export const keys = BI.keys; @@ -666,6 +672,7 @@ BI._.extend(BI, { export const deepClone = BI._.cloneDeep; export const deepExtend = BI._.deepExtend; + export function isDeepMatch(object, attrs) { let attrsKeys = keys(attrs), length = attrsKeys.length; if (object == null) { @@ -886,7 +893,7 @@ export const nextTick = (function () { }; })(); -BI._.extend(BI, { nextTick }); +BI._.extend(BI, { nextTick }); // 数字相关方法 BI._.each(["random"], function (name) { @@ -1351,9 +1358,8 @@ export function parseDateTime(str, fmt) { return today; } -export function getDate() { - const length = arguments.length; - const args = arguments; +export function getDate(...args) { + const length = args.length; let dt; switch (length) { // new Date() @@ -1458,5 +1464,5 @@ BI._.extend(BI, { checkDateLegal, parseDateTime, getDate, - getTime, -}); \ No newline at end of file + getTime, +}); diff --git a/src/core/func/alias.js b/src/core/func/alias.js index 2884e492b..f7ba2f324 100644 --- a/src/core/func/alias.js +++ b/src/core/func/alias.js @@ -1,938 +1,930 @@ -(function () { - var _global; - if (typeof window !== "undefined") { - _global = window; - } else if (typeof global !== "undefined") { - _global = global; - } else if (typeof self !== "undefined") { - _global = self; - } else { - _global = this; - } - if (!_global.BI) { - _global.BI = {}; - } - - function isEmpty (value) { - // 判断是否为空值 - var result = value === "" || value === null || value === undefined; - return result; - } - - // 判断是否是无效的日期 - function isInvalidDate (date) { - return date == "Invalid Date" || date == "NaN"; - } +import {each, isFunction, isNull, isObject, isPlainObject, keys, leftPad, parseDateTime, values} from "../2.base"; +import {replaceAll} from "./string"; +import {getFullDayName, getMonthName, getTimezone} from "./date"; + +var _global; +if (typeof window !== "undefined") { + _global = window; +} else if (typeof global !== "undefined") { + _global = global; +} else if (typeof self !== "undefined") { + _global = self; +} else { + _global = this; +} +if (!_global.BI) { + _global.BI = {}; +} + +function isEmpty(value) { + // 判断是否为空值 + return value === "" || value === null || value === undefined; +} + +// 判断是否是无效的日期 +function isInvalidDate(date) { + return date === "Invalid Date" || date === "NaN"; +} + +/** + * CHART-1400 + * 使用数值计算的方式来获取任意数值的科学技术表示值。 + * 科学计数格式 + */ +function _eFormat(text, fmt) { + text = +text; + + return eFormat(text, fmt); /** - * CHART-1400 - * 使用数值计算的方式来获取任意数值的科学技术表示值。 - * 科学计数格式 + * 科学计数格式具体计算过程 + * @param num + * @param format {String}有两种形式, + * 1、"0.00E00"这样的字符串表示正常的科学计数表示,只不过规定了数值精确到百分位, + * 而数量级的绝对值如果是10以下的时候在前面补零。 + * 2、 "##0.0E0"这样的字符串则规定用科学计数法表示之后的数值的整数部分是三位,精确到十分位, + * 数量级没有规定,因为没见过实数里有用科学计数法表示之后E的后面会小于一位的情况(0无所谓)。 + * @returns {*} */ - function _eFormat (text, fmt) { - text = +text; - - return eFormat(text, fmt); - - /** - * 科学计数格式具体计算过程 - * @param num - * @param format {String}有两种形式, - * 1、"0.00E00"这样的字符串表示正常的科学计数表示,只不过规定了数值精确到百分位, - * 而数量级的绝对值如果是10以下的时候在前面补零。 - * 2、 "##0.0E0"这样的字符串则规定用科学计数法表示之后的数值的整数部分是三位,精确到十分位, - * 数量级没有规定,因为没见过实数里有用科学计数法表示之后E的后面会小于一位的情况(0无所谓)。 - * @returns {*} - */ - function eFormat (num, format) { - var neg = num < 0 ? (num *= -1, "-") : "", - magnitudeNeg = ""; + function eFormat(num, format) { + var neg = num < 0 ? (num *= -1, "-") : "", + magnitudeNeg = ""; - var funcName = num > 0 && num < 1 ? "floor" : "ceil"; // -0.9999->-1 - // 数量级 - var magnitude = Math[funcName](Math.log(num) / Math.log(10)); + var funcName = num > 0 && num < 1 ? "floor" : "ceil"; // -0.9999->-1 + // 数量级 + var magnitude = Math[funcName](Math.log(num) / Math.log(10)); - if (!isFinite(magnitude)) { - return format.replace(/#/ig, "").replace(/\.e/ig, "E"); - } + if (!isFinite(magnitude)) { + return format.replace(/#/ig, "").replace(/\.e/ig, "E"); + } - num = num / Math.pow(10, magnitude); + num = num / Math.pow(10, magnitude); - // 让num转化成[1, 10)区间上的数 - if (num > 0 && num < 1) { - num *= 10; - magnitude -= 1; - } + // 让num转化成[1, 10)区间上的数 + if (num > 0 && num < 1) { + num *= 10; + magnitude -= 1; + } - // 计算出format中需要显示的整数部分的位数,然后更新这个数值,也更新数量级 - var integerLen = getInteger(magnitude, format); - integerLen > 1 && (magnitude -= integerLen - 1, num *= Math.pow(10, integerLen - 1)); + // 计算出format中需要显示的整数部分的位数,然后更新这个数值,也更新数量级 + var integerLen = getInteger(magnitude, format); + integerLen > 1 && (magnitude -= integerLen - 1, num *= Math.pow(10, integerLen - 1)); - magnitude < 0 && (magnitudeNeg = "-", magnitude *= -1); + magnitude < 0 && (magnitudeNeg = "-", magnitude *= -1); - // 获取科学计数法精确到的位数 - var precision = getPrecision(format); - // 判断num经过四舍五入之后是否有进位 - var isValueCarry = isValueCarried(num); + // 获取科学计数法精确到的位数 + var precision = getPrecision(format); + // 判断num经过四舍五入之后是否有进位 + var isValueCarry = isValueCarried(num); - num *= Math.pow(10, precision); - num = Math.round(num); - // 如果出现进位的情况,将num除以10 - isValueCarry && (num /= 10, magnitude += magnitudeNeg === "-" ? -1 : 1); - num /= Math.pow(10, precision); + num *= Math.pow(10, precision); + num = Math.round(num); + // 如果出现进位的情况,将num除以10 + isValueCarry && (num /= 10, magnitude += magnitudeNeg === "-" ? -1 : 1); + num /= Math.pow(10, precision); - // 小数部分保留precision位 - num = num.toFixed(precision); - // 格式化指数的部分 - magnitude = formatExponential(format, magnitude, magnitudeNeg); + // 小数部分保留precision位 + num = num.toFixed(precision); + // 格式化指数的部分 + magnitude = formatExponential(format, magnitude, magnitudeNeg); - return neg + num + "E" + magnitude; + return neg + num + "E" + magnitude; + } + + // 获取format格式规定的数量级的形式 + function formatExponential(format, num, magnitudeNeg) { + num += ""; + if (!/e/ig.test(format)) { + return num; } + format = format.split(/e/ig)[1]; - // 获取format格式规定的数量级的形式 - function formatExponential (format, num, magnitudeNeg) { - num += ""; - if (!/e/ig.test(format)) { - return num; - } - format = format.split(/e/ig)[1]; + while (num.length < format.length) { + num = "0" + num; + } - while (num.length < format.length) { - num = "0" + num; + // 如果magnitudeNeg是一个"-",而且num正好全是0,那么就别显示负号了 + var isAllZero = true; + for (var i = 0, len = num.length; i < len; i++) { + if (!isAllZero) { + continue; } + isAllZero = num.charAt(i) === "0"; + } + magnitudeNeg = isAllZero ? "" : magnitudeNeg; - // 如果magnitudeNeg是一个"-",而且num正好全是0,那么就别显示负号了 - var isAllZero = true; - for (var i = 0, len = num.length; i < len; i++) { - if (!isAllZero) { - continue; - } - isAllZero = num.charAt(i) === "0"; - } - magnitudeNeg = isAllZero ? "" : magnitudeNeg; + return magnitudeNeg + num; + } - return magnitudeNeg + num; + // 获取format规定的科学计数法精确到的位数 + function getPrecision(format) { + if (!/e/ig.test(format)) { + return 0; } + var arr = format.split(/e/ig)[0].split("."); - // 获取format规定的科学计数法精确到的位数 - function getPrecision (format) { - if (!/e/ig.test(format)) { - return 0; - } - var arr = format.split(/e/ig)[0].split("."); + return arr.length > 1 ? arr[1].length : 0; + } - return arr.length > 1 ? arr[1].length : 0; + // 获取数值科学计数法表示之后整数的位数 + // 这边我们还需要考虑#和0的问题 + function getInteger(magnitude, format) { + if (!/e/ig.test(format)) { + return 0; } + // return format.split(/e/ig)[0].split(".")[0].length; - // 获取数值科学计数法表示之后整数的位数 - // 这边我们还需要考虑#和0的问题 - function getInteger (magnitude, format) { - if (!/e/ig.test(format)) { - return 0; - } - // return format.split(/e/ig)[0].split(".")[0].length; - - var formatLeft = format.split(/e/ig)[0].split(".")[0], i, f, len = formatLeft.length; - var valueLeftLen = 0; + var formatLeft = format.split(/e/ig)[0].split(".")[0], i, f, len = formatLeft.length; + var valueLeftLen = 0; - for (i = 0; i < len; i++) { - f = formatLeft.charAt(i); - // "#"所在的位置到末尾长度小于等于值的整数部分长度,那么这个#才可以占位 - if (f == 0 || (f == "#" && (len - i <= magnitude + 1))) { - valueLeftLen++; - } + for (i = 0; i < len; i++) { + f = formatLeft.charAt(i); + // "#"所在的位置到末尾长度小于等于值的整数部分长度,那么这个#才可以占位 + if (f == 0 || (f == "#" && (len - i <= magnitude + 1))) { + valueLeftLen++; } - - return valueLeftLen; } - // 判断num通过round函数之后是否有进位 - function isValueCarried (num) { - var roundNum = Math.round(num); - num = (num + "").split(".")[0]; - roundNum = (roundNum + "").split(".")[0]; - return num.length !== roundNum.length; - } + return valueLeftLen; } - //'#.##'之类的格式处理 1.324e-18 这种的科学数字 - function _dealNumberPrecision (text, fright) { - if (/[eE]/.test(text)) { - var precision = 0, i = 0, ch; + // 判断num通过round函数之后是否有进位 + function isValueCarried(num) { + var roundNum = Math.round(num); + num = (num + "").split(".")[0]; + roundNum = (roundNum + "").split(".")[0]; + return num.length !== roundNum.length; + } +} - if (/[%‰]$/.test(fright)) { - precision = /[%]$/.test(fright) ? 2 : 3; - } +//'#.##'之类的格式处理 1.324e-18 这种的科学数字 +function _dealNumberPrecision(text, fright) { + if (/[eE]/.test(text)) { + var precision = 0, i = 0, ch; - for (var len = fright.length; i < len; i++) { - if ((ch = fright.charAt(i)) == "0" || ch == "#") { - precision++; - } - } - return Number(text).toFixed(precision); + if (/[%‰]$/.test(fright)) { + precision = /[%]$/.test(fright) ? 2 : 3; } - return text; + for (var len = fright.length; i < len; i++) { + if ((ch = fright.charAt(i)) == "0" || ch == "#") { + precision++; + } + } + return Number(text).toFixed(precision); } - /** - * 数字格式 - */ - function _numberFormat (text, format) { - var text = text + ""; + return text; +} - //在调用数字格式的时候如果text里没有任何数字则不处理 - if (!(/[0-9]/.test(text)) || !format) { - return text; - } +/** + * 数字格式 + */ +function _numberFormat(text, format) { + var text = text + ""; - // 数字格式,区分正负数 - var numMod = format.indexOf(";"); - if (numMod > -1) { - if (text >= 0) { - return _numberFormat(text + "", format.substring(0, numMod)); - } - return _numberFormat((-text) + "", format.substr(numMod + 1)); + //在调用数字格式的时候如果text里没有任何数字则不处理 + if (!(/[0-9]/.test(text)) || !format) { + return text; + } - } else { - // 兼容格式处理负数的情况(copy:fr-jquery.format.js) - if (+text < 0 && format.charAt(0) !== "-") { - return _numberFormat((-text) + "", "-" + format); - } + // 数字格式,区分正负数 + var numMod = format.indexOf(";"); + if (numMod > -1) { + if (text >= 0) { + return _numberFormat(text + "", format.substring(0, numMod)); } + return _numberFormat((-text) + "", format.substring(numMod + 1)); - var fp = format.split("."), fleft = fp[0] || "", fright = fp[1] || ""; - text = _dealNumberPrecision(text, fright); - var tp = text.split("."), tleft = tp[0] || "", tright = tp[1] || ""; - - // 百分比,千分比的小数点移位处理 - if (/[%‰]$/.test(format)) { - var paddingZero = /[%]$/.test(format) ? "00" : "000"; - tright += paddingZero; - tleft += tright.substr(0, paddingZero.length); - tleft = tleft.replace(/^0+/gi, ""); - tright = tright.substr(paddingZero.length).replace(/0+$/gi, ""); + } else { + // 兼容格式处理负数的情况(copy:fr-jquery.format.js) + if (+text < 0 && format.charAt(0) !== "-") { + return _numberFormat((-text) + "", "-" + format); } - var right = _dealWithRight(tright, fright); - if (right.leftPlus) { - // 小数点后有进位 - tleft = parseInt(tleft) + 1 + ""; + } - tleft = isNaN(tleft) ? "1" : tleft; - } - right = right.num; - var left = _dealWithLeft(tleft, fleft); - if (!(/[0-9]/.test(left))) { - left = left + "0"; - } - if (!(/[0-9]/.test(right))) { - return left + right; - } else { - return left + "." + right; - } + var fp = format.split("."), fleft = fp[0] || "", fright = fp[1] || ""; + text = _dealNumberPrecision(text, fright); + var tp = text.split("."), tleft = tp[0] || "", tright = tp[1] || ""; + + // 百分比,千分比的小数点移位处理 + if (/[%‰]$/.test(format)) { + var paddingZero = /[%]$/.test(format) ? "00" : "000"; + tright += paddingZero; + tleft += tright.substring(0, paddingZero.length); + tleft = tleft.replace(/^0+/gi, ""); + tright = tright.substring(paddingZero.length).replace(/0+$/gi, ""); } + var right = _dealWithRight(tright, fright); + if (right.leftPlus) { + // 小数点后有进位 + tleft = parseInt(tleft) + 1 + ""; - /** - * 处理小数点右边小数部分 - * @param tright 右边内容 - * @param fright 右边格式 - * @returns {JSON} 返回处理结果和整数部分是否需要进位 - * @private - */ - function _dealWithRight (tright, fright) { - var right = "", j = 0, i = 0; - for (var len = fright.length; i < len; i++) { - var ch = fright.charAt(i); - var c = tright.charAt(j); - switch (ch) { - case "0": - if (isEmpty(c)) { - c = "0"; - } - right += c; - j++; - break; - case "#": - right += c; - j++; - break; - default : - right += ch; - break; - } - } - var rll = tright.substr(j); - var result = {}; - if (!isEmpty(rll) && rll.charAt(0) > 4) { - // 有多余字符,需要四舍五入 - result.leftPlus = true; - var numReg = right.match(/^[0-9]+/); - if (numReg) { - var num = numReg[0]; - var orilen = num.length; - var newnum = parseInt(num) + 1 + ""; - // 进位到整数部分 - if (newnum.length > orilen) { - newnum = newnum.substr(1); - } else { - newnum = BI.leftPad(newnum, orilen, "0"); - result.leftPlus = false; + tleft = isNaN(tleft) ? "1" : tleft; + } + right = right.num; + var left = _dealWithLeft(tleft, fleft); + if (!(/[0-9]/.test(left))) { + left = left + "0"; + } + if (!(/[0-9]/.test(right))) { + return left + right; + } else { + return left + "." + right; + } +} + +/** + * 处理小数点右边小数部分 + * @param tright 右边内容 + * @param fright 右边格式 + * @returns {JSON} 返回处理结果和整数部分是否需要进位 + * @private + */ +function _dealWithRight(tright, fright) { + var right = "", j = 0, i = 0; + for (var len = fright.length; i < len; i++) { + var ch = fright.charAt(i); + var c = tright.charAt(j); + switch (ch) { + case "0": + if (isEmpty(c)) { + c = "0"; } - right = right.replace(/^[0-9]+/, newnum); - } + right += c; + j++; + break; + case "#": + right += c; + j++; + break; + default : + right += ch; + break; } - result.num = right; - return result; } - - /** - * 处理小数点左边整数部分 - * @param tleft 左边内容 - * @param fleft 左边格式 - * @returns {string} 返回处理结果 - * @private - */ - function _dealWithLeft (tleft, fleft) { - var left = ""; - var j = tleft.length - 1; - var combo = -1, last = -1; - var i = fleft.length - 1; - for (; i >= 0; i--) { - var ch = fleft.charAt(i); - var c = tleft.charAt(j); - switch (ch) { - case "0": - if (isEmpty(c)) { - c = "0"; - } - last = -1; - left = c + left; - j--; - break; - case "#": - last = i; - left = c + left; - j--; - break; - case ",": - if (!isEmpty(c)) { - // 计算一个,分隔区间的长度 - var com = fleft.match(/,[#0]+/); - if (com) { - combo = com[0].length - 1; - } - left = "," + left; - } - break; - default : - left = ch + left; - break; + var rll = tright.substring(j); + var result = {}; + if (!isEmpty(rll) && rll.charAt(0) > 4) { + // 有多余字符,需要四舍五入 + result.leftPlus = true; + var numReg = right.match(/^[0-9]+/); + if (numReg) { + var num = numReg[0]; + var orilen = num.length; + var newnum = parseInt(num) + 1 + ""; + // 进位到整数部分 + if (newnum.length > orilen) { + newnum = newnum.substring(1); + } else { + newnum = leftPad(newnum, orilen, "0"); + result.leftPlus = false; } + right = right.replace(/^[0-9]+/, newnum); } - if (last > -1) { - // 处理剩余字符 - var tll = tleft.substr(0, j + 1); - left = left.substr(0, last) + tll + left.substr(last); - } - if (combo > 0) { - // 处理,分隔区间 - var res = left.match(/[0-9]+,/); - if (res) { - res = res[0]; - var newstr = "", n = res.length - 1 - combo; - for (; n >= 0; n = n - combo) { - newstr = res.substr(n, combo) + "," + newstr; + } + result.num = right; + return result; +} + +/** + * 处理小数点左边整数部分 + * @param tleft 左边内容 + * @param fleft 左边格式 + * @returns {string} 返回处理结果 + * @private + */ +function _dealWithLeft(tleft, fleft) { + var left = ""; + var j = tleft.length - 1; + var combo = -1, last = -1; + var i = fleft.length - 1; + for (; i >= 0; i--) { + var ch = fleft.charAt(i); + var c = tleft.charAt(j); + switch (ch) { + case "0": + if (isEmpty(c)) { + c = "0"; } - var lres = res.substr(0, n + combo); - if (!isEmpty(lres)) { - newstr = lres + "," + newstr; + last = -1; + left = c + left; + j--; + break; + case "#": + last = i; + left = c + left; + j--; + break; + case ",": + if (!isEmpty(c)) { + // 计算一个,分隔区间的长度 + var com = fleft.match(/,[#0]+/); + if (com) { + combo = com[0].length - 1; + } + left = "," + left; } + break; + default : + left = ch + left; + break; + } + } + if (last > -1) { + // 处理剩余字符 + var tll = tleft.substring(0, j + 1); + left = left.substring(0, last) + tll + left.substring(last); + } + if (combo > 0) { + // 处理,分隔区间 + var res = left.match(/[0-9]+,/); + if (res) { + res = res[0]; + var newstr = "", n = res.length - 1 - combo; + for (; n >= 0; n = n - combo) { + newstr = res.substring(n, combo) + "," + newstr; + } + var lres = res.substring(0, n + combo); + if (!isEmpty(lres)) { + newstr = lres + "," + newstr; } - left = left.replace(/[0-9]+,/, newstr); } - return left; + left = left.replace(/[0-9]+,/, newstr); } + return left; +} +export const cjkEncode = function (text) { + // alex:如果非字符串,返回其本身(cjkEncode(234) 返回 ""是不对的) + if (typeof text !== "string") { + return text; + } - BI.cjkEncode = function (text) { - // alex:如果非字符串,返回其本身(cjkEncode(234) 返回 ""是不对的) - if (typeof text !== "string") { - return text; - } - - var newText = ""; - for (var i = 0; i < text.length; i++) { - var code = text.charCodeAt(i); - if (code >= 128 || code === 91 || code === 93) {// 91 is "[", 93 is "]". - newText += "[" + code.toString(16) + "]"; - } else { - newText += text.charAt(i); - } + var newText = ""; + for (var i = 0; i < text.length; i++) { + var code = text.charCodeAt(i); + if (code >= 128 || code === 91 || code === 93) {// 91 is "[", 93 is "]". + newText += "[" + code.toString(16) + "]"; + } else { + newText += text.charAt(i); } + } - return newText; - }; - - /** - * 将cjkEncode处理过的字符串转化为原始字符串 - * - * @static - * @param text 需要做解码的字符串 - * @return {String} 解码后的字符串 - */ - BI.cjkDecode = function (text) { - if (text == null) { - return ""; - } - // 查找没有 "[", 直接返回. kunsnat:数字的时候, 不支持indexOf方法, 也是直接返回. - if (!isNaN(text) || text.indexOf("[") == -1) { - return text; - } - - var newText = ""; - for (var i = 0; i < text.length; i++) { - var ch = text.charAt(i); - if (ch == "[") { - var rightIdx = text.indexOf("]", i + 1); - if (rightIdx > i + 1) { - var subText = text.substring(i + 1, rightIdx); - // james:主要是考虑[CDATA[]]这样的值的出现 - if (subText.length > 0) { - ch = String.fromCharCode(eval("0x" + subText)); - } + return newText; +}; + +/** + * 将cjkEncode处理过的字符串转化为原始字符串 + * + * @static + * @param text 需要做解码的字符串 + * @return {String} 解码后的字符串 + */ +export const cjkDecode = function (text) { + if (text == null) { + return ""; + } + // 查找没有 "[", 直接返回. kunsnat:数字的时候, 不支持indexOf方法, 也是直接返回. + if (!isNaN(text) || text.indexOf("[") == -1) { + return text; + } - i = rightIdx; + var newText = ""; + for (var i = 0; i < text.length; i++) { + var ch = text.charAt(i); + if (ch == "[") { + var rightIdx = text.indexOf("]", i + 1); + if (rightIdx > i + 1) { + var subText = text.substring(i + 1, rightIdx); + // james:主要是考虑[CDATA[]]这样的值的出现 + if (subText.length > 0) { + ch = String.fromCharCode(eval("0x" + subText)); } - } - newText += ch; + i = rightIdx; + } } - return newText; - }; + newText += ch; + } - // replace the html special tags - var SPECIAL_TAGS = { - "&": "&", - "\"": """, - "<": "<", - ">": ">", - "\x20": " ", - "\n": " " - }; - BI.htmlEncode = function (text) { - return BI.isNull(text) ? "" : BI.replaceAll(text + "", BI.keys(SPECIAL_TAGS).join("|"), function (v) { - return SPECIAL_TAGS[v] ? SPECIAL_TAGS[v] : v; - }); - }; - // html decode - BI.htmlDecode = function (text) { - return BI.isNull(text) ? "" : BI.replaceAll(text + "", BI.values(SPECIAL_TAGS).join("|"), function (v) { - switch (v) { - case "&": - return "&"; - case """: - return "\""; - case "<": - return "<"; - case ">": - return ">"; - case " ": - return " "; - case " ": - return "\n"; - default: - return v; + return newText; +}; + +// replace the html special tags +const SPECIAL_TAGS = { + "&": "&", + "\"": """, + "<": "<", + ">": ">", + "\x20": " ", + "\n": " " +}; +export const htmlEncode = function (text) { + return isNull(text) ? "" : replaceAll(text + "", keys(SPECIAL_TAGS).join("|"), function (v) { + return SPECIAL_TAGS[v] ? SPECIAL_TAGS[v] : v; + }); +}; +// html decode +export const htmlDecode = function (text) { + return isNull(text) ? "" : replaceAll(text + "", values(SPECIAL_TAGS).join("|"), function (v) { + switch (v) { + case "&": + return "&"; + case """: + return "\""; + case "<": + return "<"; + case ">": + return ">"; + case " ": + return " "; + case " ": + return "\n"; + default: + return v; + } + }); +}; + +export const cjkEncodeDO = function (o) { + if (isPlainObject(o)) { + var result = {}; + each(o, function (v, k) { + if (!(typeof v === "string")) { + v = jsonEncode(v); } + // wei:bug 43338,如果key是中文,cjkencode后o的长度就加了1,ie9以下版本死循环,所以新建对象result。 + k = cjkEncode(k); + result[k] = cjkEncode(v); }); + return result; + } + return o; +}; + +export const jsonEncode = function (o) { + // james:这个Encode是抄的EXT的 + var useHasOwn = !!{}.hasOwnProperty; + + // crashes Safari in some instances + // var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/; + + var m = { + "\b": "\\b", + "\t": "\\t", + "\n": "\\n", + "\f": "\\f", + "\r": "\\r", + "\"": "\\\"", + "\\": "\\\\" }; - BI.cjkEncodeDO = function (o) { - if (BI.isPlainObject(o)) { - var result = {}; - BI._.each(o, function (v, k) { - if (!(typeof v === "string")) { - v = BI.jsonEncode(v); + var encodeString = function (s) { + if (/["\\\x00-\x1f]/.test(s)) { + return "\"" + s.replace(/([\x00-\x1f\\"])/g, function (a, b) { + var c = m[b]; + if (c) { + return c; } - // wei:bug 43338,如果key是中文,cjkencode后o的长度就加了1,ie9以下版本死循环,所以新建对象result。 - k = BI.cjkEncode(k); - result[k] = BI.cjkEncode(v); - }); - return result; + c = b.charCodeAt(); + return "\\u00" + + Math.floor(c / 16).toString(16) + + (c % 16).toString(16); + }) + "\""; } - return o; + return "\"" + s + "\""; }; - BI.jsonEncode = function (o) { - // james:这个Encode是抄的EXT的 - var useHasOwn = !!{}.hasOwnProperty; - - // crashes Safari in some instances - // var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/; - - var m = { - "\b": "\\b", - "\t": "\\t", - "\n": "\\n", - "\f": "\\f", - "\r": "\\r", - "\"": "\\\"", - "\\": "\\\\" - }; - - var encodeString = function (s) { - if (/["\\\x00-\x1f]/.test(s)) { - return "\"" + s.replace(/([\x00-\x1f\\"])/g, function (a, b) { - var c = m[b]; - if (c) { - return c; + var encodeArray = function (o) { + var a = ["["], b, i, l = o.length, v; + for (i = 0; i < l; i += 1) { + v = o[i]; + switch (typeof v) { + case "undefined": + case "function": + case "unknown": + break; + default: + if (b) { + a.push(","); } - c = b.charCodeAt(); - return "\\u00" + - Math.floor(c / 16).toString(16) + - (c % 16).toString(16); - }) + "\""; - } - return "\"" + s + "\""; - }; - - var encodeArray = function (o) { - var a = ["["], b, i, l = o.length, v; - for (i = 0; i < l; i += 1) { - v = o[i]; - switch (typeof v) { - case "undefined": - case "function": - case "unknown": - break; - default: - if (b) { - a.push(","); - } - a.push(v === null ? "null" : BI.jsonEncode(v)); - b = true; - } - } - a.push("]"); - return a.join(""); - }; - - if (typeof o === "undefined" || o === null) { - return "null"; - } else if (BI.isArray(o)) { - return encodeArray(o); - } else if (o instanceof Date) { - /* - * alex:原来只是把年月日时分秒简单地拼成一个String,无法decode - * 现在这么处理就可以decode了,但是JS.jsonDecode和Java.JSONObject也要跟着改一下 - */ - return BI.jsonEncode({ - __time__: o.getTime() - }); - } else if (typeof o === "string") { - return encodeString(o); - } else if (typeof o === "number") { - return isFinite(o) ? String(o) : "null"; - } else if (typeof o === "boolean") { - return String(o); - } else if (BI.isFunction(o)) { - return String(o); - } - var a = ["{"], b, i, v; - for (i in o) { - if (!useHasOwn || o.hasOwnProperty(i)) { - v = o[i]; - switch (typeof v) { - case "undefined": - case "unknown": - break; - default: - if (b) { - a.push(","); - } - a.push(BI.jsonEncode(i), ":", - v === null ? "null" : BI.jsonEncode(v)); - b = true; - } + a.push(v === null ? "null" : jsonEncode(v)); + b = true; } } - a.push("}"); + a.push("]"); return a.join(""); - - }; - - BI.jsonDecode = function (text) { - - try { - // 注意0啊 - // var jo = $.parseJSON(text) || {}; - var jo = BI.$ ? BI.$.parseJSON(text) : _global.JSON.parse(text); - if (jo == null) { - jo = {}; - } - } catch (e) { - /* - * richie:浏览器只支持标准的JSON字符串转换,而jQuery会默认调用浏览器的window.JSON.parse()函数进行解析 - * 比如:var str = "{'a':'b'}",这种形式的字符串转换为JSON就会抛异常 - */ - try { - jo = new Function("return " + text)() || {}; - } catch (e) { - // do nothing - } - if (jo == null) { - jo = []; - } - } - if (!_hasDateInJson(text)) { - return jo; - } - - function _hasDateInJson (json) { - if (!json || typeof json !== "string") { - return false; - } - return json.indexOf("__time__") != -1; - } - - return (function (o) { - if (typeof o === "string") { - return o; - } - if (o && o.__time__ != null) { - return new Date(o.__time__); - } - for (var a in o) { - if (o[a] == o || typeof o[a] === "object" || BI._.isFunction(o[a])) { - break; - } - o[a] = arguments.callee(o[a]); - } - - return o; - })(jo); }; - /** - * 获取编码后的url - * @param urlTemplate url模板 - * @param param 参数 - * @returns {*|String} - * @example - * BI.getEncodeURL("design/{tableName}/{fieldName}",{tableName: "A", fieldName: "a"}) // design/A/a - */ - BI.getEncodeURL = function (urlTemplate, param) { - return BI.replaceAll(urlTemplate, "\\{(.*?)\\}", function (ori, str) { - return BI.encodeURIComponent(BI.isObject(param) ? param[str] : param); + if (typeof o === "undefined" || o === null) { + return "null"; + } else if (isArray(o)) { + return encodeArray(o); + } else if (o instanceof Date) { + /* + * alex:原来只是把年月日时分秒简单地拼成一个String,无法decode + * 现在这么处理就可以decode了,但是JS.jsonDecode和Java.JSONObject也要跟着改一下 + */ + return jsonEncode({ + __time__: o.getTime() }); - }; - - BI.encodeURIComponent = function (url) { - BI.specialCharsMap = BI.specialCharsMap || {}; - url = url || ""; - url = BI.replaceAll(url + "", BI.keys(BI.specialCharsMap || []).join("|"), function (str) { - switch (str) { - case "\\": - return BI.specialCharsMap["\\\\"] || str; + } else if (typeof o === "string") { + return encodeString(o); + } else if (typeof o === "number") { + return isFinite(o) ? String(o) : "null"; + } else if (typeof o === "boolean") { + return String(o); + } else if (isFunction(o)) { + return String(o); + } + var a = ["{"], b, i, v; + for (i in o) { + if (!useHasOwn || o.hasOwnProperty(i)) { + v = o[i]; + switch (typeof v) { + case "undefined": + case "unknown": + break; default: - return BI.specialCharsMap[str] || str; + if (b) { + a.push(","); + } + a.push(jsonEncode(i), ":", + v === null ? "null" : jsonEncode(v)); + b = true; } - }); - return _global.encodeURIComponent(url); - }; + } + } + a.push("}"); + return a.join(""); - BI.decodeURIComponent = function (url) { - var reserveSpecialCharsMap = {}; - BI.each(BI.specialCharsMap, function (initialChar, encodeChar) { - reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; - }); - url = url || ""; - url = BI.replaceAll(url + "", BI.keys(reserveSpecialCharsMap || []).join("|"), function (str) { - return reserveSpecialCharsMap[str] || str; - }); - return _global.decodeURIComponent(url); - }; +}; - BI.contentFormat = function (cv, fmt) { - if (isEmpty(cv)) { - // 原值为空,返回空字符 - return ""; - } - var text = cv.toString(); - if (isEmpty(fmt)) { - // 格式为空,返回原字符 - return text; - } - if (fmt.match(/^T/)) { - // T - 文本格式 - return text; - } else if (fmt.match(/^D/)) { - // D - 日期(时间)格式 - if (!(cv instanceof Date)) { - if (typeof cv === "number") { - // 毫秒数类型 - cv = new Date(cv); - } else { - //字符串类型转化为date类型 - cv = new Date(Date.parse(("" + cv).replace(/-|\./g, "/"))); - } - } - if (!isInvalidDate(cv) && !BI.isNull(cv)) { - var needTrim = fmt.match(/^DT/); - text = BI.date2Str(cv, fmt.substring(needTrim ? 2 : 1)); - } - } else if (fmt.match(/E/)) { - // 科学计数格式 - text = _eFormat(text, fmt); - } else { - // 数字格式 - text = _numberFormat(text, fmt); - } - // ¤ - 货币格式 - text = text.replace(/¤/g, "¥"); - return text; - }; +export const jsonDecode = function (text) { - /** - * 将Java提供的日期格式字符串装换为JS识别的日期格式字符串 - * @class FR.parseFmt - * @param fmt 日期格式 - * @returns {String} - */ - BI.parseFmt = function (fmt) { - if (!fmt) { - return ""; - } - //日期 - fmt = String(fmt) - //年 - .replace(/y{4,}/g, "%Y")//yyyy的时候替换为Y - .replace(/y{2}/g, "%y")//yy的时候替换为y - //月 - .replace(/M{4,}/g, "%b")//MMMM的时候替换为b,八 - .replace(/M{3}/g, "%B")//MMM的时候替换为M,八月 - .replace(/M{2}/g, "%X")//MM的时候替换为X,08 - .replace(/M{1}/g, "%x")//M的时候替换为x,8 - .replace(/a{1}/g, "%p"); - //天 - if (new RegExp("d{2,}", "g").test(fmt)) { - fmt = fmt.replace(/d{2,}/g, "%d");//dd的时候替换为d - } else { - fmt = fmt.replace(/d{1}/g, "%e");//d的时候替换为j + try { + var jo = JSON.parse(text); + if (jo == null) { + jo = {}; } - //时 - if (new RegExp("h{2,}", "g").test(fmt)) {//12小时制 - fmt = fmt.replace(/h{2,}/g, "%I"); - } else { - fmt = fmt.replace(/h{1}/g, "%I"); + } catch (e) { + /* + * richie:浏览器只支持标准的JSON字符串转换,而jQuery会默认调用浏览器的window.JSON.parse()函数进行解析 + * 比如:var str = "{'a':'b'}",这种形式的字符串转换为JSON就会抛异常 + */ + try { + jo = new Function("return " + text)() || {}; + } catch (e) { + // do nothing } - if (new RegExp("H{2,}", "g").test(fmt)) {//24小时制 - fmt = fmt.replace(/H{2,}/g, "%H"); - } else { - fmt = fmt.replace(/H{1}/g, "%H"); + if (jo == null) { + jo = []; } - fmt = fmt.replace(/m{2,}/g, "%M")//分 - //秒 - .replace(/s{2,}/g, "%S"); - - return fmt; - }; + } + if (!_hasDateInJson(text)) { + return jo; + } - /** - * 把字符串按照对应的格式转化成日期对象 - * - * @example - * var result = BI.str2Date('2013-12-12', 'yyyy-MM-dd');//Thu Dec 12 2013 00:00:00 GMT+0800 - * - * @class BI.str2Date - * @param str 字符串 - * @param format 日期格式 - * @returns {*} - */ - BI.str2Date = function (str, format) { - if (typeof str != "string" || typeof format != "string") { - return null; + function _hasDateInJson(json) { + if (!json || typeof json !== "string") { + return false; } - var fmt = BI.parseFmt(format); - return BI.parseDateTime(str, fmt); - }; + return json.indexOf("__time__") !== -1; + } - /** - * 把日期对象按照指定格式转化成字符串 - * - * @example - * var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800'); - * var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12 - * - * @class BI.date2Str - * @param date 日期 - * @param format 日期格式 - * @returns {String} - */ - BI.date2Str = function (date, format) { - if (!date) { - return ""; - } - // O(len(format)) - var len = format.length, result = ""; - if (len > 0) { - var flagch = format.charAt(0), start = 0, str = flagch; - for (var i = 1; i < len; i++) { - var ch = format.charAt(i); - if (flagch !== ch) { - result += compileJFmt({ - char: flagch, - str: str, - len: i - start - }, date); - flagch = ch; - start = i; - str = flagch; - } else { - str += ch; - } - } - result += compileJFmt({ - char: flagch, - str: str, - len: len - start - }, date); + return (function parse(o) { + if (typeof o === "string") { + return o; } - return result; - - function compileJFmt (jfmt, date) { - var str = jfmt.str, len = jfmt.len, ch = jfmt["char"]; - switch (ch) { - case "E": // 星期 - str = BI.getFullDayName(date.getDay()); - break; - case "y": // 年 - if (len <= 3) { - str = (date.getFullYear() + "").slice(2, 4); - } else { - str = date.getFullYear(); - } - break; - case "M": // 月 - if (len > 2) { - str = BI.getMonthName(date.getMonth()); - } else if (len < 2) { - str = date.getMonth() + 1; - } else { - str = BI.leftPad(date.getMonth() + 1 + "", 2, "0"); - } - break; - case "d": // 日 - if (len > 1) { - str = BI.leftPad(date.getDate() + "", 2, "0"); - } else { - str = date.getDate(); - } - break; - case "h": // 时(12) - var hour = date.getHours() % 12; - if (hour === 0) { - hour = 12; - } - if (len > 1) { - str = BI.leftPad(hour + "", 2, "0"); - } else { - str = hour; - } - break; - case "H": // 时(24) - if (len > 1) { - str = BI.leftPad(date.getHours() + "", 2, "0"); - } else { - str = date.getHours(); - } - break; - case "m": - if (len > 1) { - str = BI.leftPad(date.getMinutes() + "", 2, "0"); - } else { - str = date.getMinutes(); - } - break; - case "s": - if (len > 1) { - str = BI.leftPad(date.getSeconds() + "", 2, "0"); - } else { - str = date.getSeconds(); - } - break; - case "a": - str = date.getHours() < 12 ? "am" : "pm"; - break; - case "z": - str = BI.getTimezone(date); - break; - default: - str = jfmt.str; - break; + if (o && o.__time__ != null) { + return new Date(o.__time__); + } + for (var a in o) { + if (o[a] == o || typeof o[a] === "object" || isFunction(o[a])) { + break; } - return str; + o[a] = parse(o[a]); } - }; - BI.object2Number = function (value) { - if (value == null) { - return 0; + return o; + })(jo); +}; + +/** + * 获取编码后的url + * @param urlTemplate url模板 + * @param param 参数 + * @returns {*|String} + * @example + * BI.getEncodeURL("design/{tableName}/{fieldName}",{tableName: "A", fieldName: "a"}) // design/A/a + */ +export const getEncodeURL = function (urlTemplate, param) { + return replaceAll(urlTemplate, "\\{(.*?)\\}", function (ori, str) { + return encodeURIComponent(isObject(param) ? param[str] : param); + }); +}; + +export const encodeURIComponent = function (url) { + BI.specialCharsMap = BI.specialCharsMap || {}; + url = url || ""; + url = replaceAll(url + "", keys(BI.specialCharsMap || []).join("|"), function (str) { + switch (str) { + case "\\": + return BI.specialCharsMap["\\\\"] || str; + default: + return BI.specialCharsMap[str] || str; + } + }); + return _global.encodeURIComponent(url); +}; + +export const decodeURIComponent = function (url) { + var reserveSpecialCharsMap = {}; + each(BI.specialCharsMap, function (initialChar, encodeChar) { + reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; + }); + url = url || ""; + url = replaceAll(url + "", keys(reserveSpecialCharsMap || []).join("|"), function (str) { + return reserveSpecialCharsMap[str] || str; + }); + return _global.decodeURIComponent(url); +}; + +export const contentFormat = function (cv, fmt) { + if (isEmpty(cv)) { + // 原值为空,返回空字符 + return ""; + } + var text = cv.toString(); + if (isEmpty(fmt)) { + // 格式为空,返回原字符 + return text; + } + if (fmt.match(/^T/)) { + // T - 文本格式 + return text; + } else if (fmt.match(/^D/)) { + // D - 日期(时间)格式 + if (!(cv instanceof Date)) { + if (typeof cv === "number") { + // 毫秒数类型 + cv = new Date(cv); + } else { + //字符串类型转化为date类型 + cv = new Date(Date.parse(("" + cv).replace(/-|\./g, "/"))); + } } - if (typeof value === "number") { - return value; + if (!isInvalidDate(cv) && !isNull(cv)) { + var needTrim = fmt.match(/^DT/); + text = date2Str(cv, fmt.substring(needTrim ? 2 : 1)); } - var str = value + ""; - if (str.indexOf(".") === -1) { - return parseInt(str); + } else if (fmt.match(/E/)) { + // 科学计数格式 + text = _eFormat(text, fmt); + } else { + // 数字格式 + text = _numberFormat(text, fmt); + } + // ¤ - 货币格式 + text = text.replace(/¤/g, "¥"); + return text; +}; + +/** + * 将Java提供的日期格式字符串装换为JS识别的日期格式字符串 + * @param fmt 日期格式 + * @returns {string} + */ +export const parseFmt = function (fmt) { + if (!fmt) { + return ""; + } + //日期 + fmt = String(fmt) + //年 + .replace(/y{4,}/g, "%Y")//yyyy的时候替换为Y + .replace(/y{2}/g, "%y")//yy的时候替换为y + //月 + .replace(/M{4,}/g, "%b")//MMMM的时候替换为b,八 + .replace(/M{3}/g, "%B")//MMM的时候替换为M,八月 + .replace(/M{2}/g, "%X")//MM的时候替换为X,08 + .replace(/M{1}/g, "%x")//M的时候替换为x,8 + .replace(/a{1}/g, "%p"); + //天 + if (new RegExp("d{2,}", "g").test(fmt)) { + fmt = fmt.replace(/d{2,}/g, "%d");//dd的时候替换为d + } else { + fmt = fmt.replace(/d{1}/g, "%e");//d的时候替换为j + } + //时 + if (new RegExp("h{2,}", "g").test(fmt)) {//12小时制 + fmt = fmt.replace(/h{2,}/g, "%I"); + } else { + fmt = fmt.replace(/h{1}/g, "%I"); + } + if (new RegExp("H{2,}", "g").test(fmt)) {//24小时制 + fmt = fmt.replace(/H{2,}/g, "%H"); + } else { + fmt = fmt.replace(/H{1}/g, "%H"); + } + fmt = fmt.replace(/m{2,}/g, "%M")//分 + //秒 + .replace(/s{2,}/g, "%S"); + + return fmt; +}; + +/** + * 把字符串按照对应的格式转化成日期对象 + * + * @example + * var result = BI.str2Date('2013-12-12', 'yyyy-MM-dd');//Thu Dec 12 2013 00:00:00 GMT+0800 + * @param str 字符串 + * @param format 日期格式 + * @returns {Date} + */ +export const str2Date = function (str, format) { + if (typeof str != "string" || typeof format != "string") { + return null; + } + var fmt = parseFmt(format); + return parseDateTime(str, fmt); +}; + +/** + * 把日期对象按照指定格式转化成字符串 + *@example + * var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800'); + * var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12 + * @param date + * @param format + * @returns {string} + */ +export const date2Str = function (date, format) { + if (!date) { + return ""; + } + // O(len(format)) + var len = format.length, result = ""; + if (len > 0) { + var flagch = format.charAt(0), start = 0, str = flagch; + for (var i = 1; i < len; i++) { + var ch = format.charAt(i); + if (flagch !== ch) { + result += compileJFmt({ + char: flagch, + str: str, + len: i - start + }, date); + flagch = ch; + start = i; + str = flagch; + } else { + str += ch; + } } - return parseFloat(str); - }; + result += compileJFmt({ + char: flagch, + str: str, + len: len - start + }, date); + } + return result; + + function compileJFmt(jfmt, date) { + var str = jfmt.str, len = jfmt.len, ch = jfmt["char"]; + switch (ch) { + case "E": // 星期 + str = getFullDayName(date.getDay()); + break; + case "y": // 年 + if (len <= 3) { + str = (date.getFullYear() + "").slice(2, 4); + } else { + str = date.getFullYear(); + } + break; + case "M": // 月 + if (len > 2) { + str = getMonthName(date.getMonth()); + } else if (len < 2) { + str = date.getMonth() + 1; + } else { + str = leftPad(date.getMonth() + 1 + "", 2, "0"); + } + break; + case "d": // 日 + if (len > 1) { + str = leftPad(date.getDate() + "", 2, "0"); + } else { + str = date.getDate(); + } + break; + case "h": // 时(12) + var hour = date.getHours() % 12; + if (hour === 0) { + hour = 12; + } + if (len > 1) { + str = leftPad(hour + "", 2, "0"); + } else { + str = hour; + } + break; + case "H": // 时(24) + if (len > 1) { + str = leftPad(date.getHours() + "", 2, "0"); + } else { + str = date.getHours(); + } + break; + case "m": + if (len > 1) { + str = leftPad(date.getMinutes() + "", 2, "0"); + } else { + str = date.getMinutes(); + } + break; + case "s": + if (len > 1) { + str = leftPad(date.getSeconds() + "", 2, "0"); + } else { + str = date.getSeconds(); + } + break; + case "a": + str = date.getHours() < 12 ? "am" : "pm"; + break; + case "z": + str = getTimezone(date); + break; + default: + str = jfmt.str; + break; + } + return str; + } +}; - BI.object2Date = function (obj) { - if (obj == null) { - return new Date(); - } - if (obj instanceof Date) { - return obj; - } else if (typeof obj === "number") { - return new Date(obj); - } - var str = obj + ""; - str = str.replace(/-/g, "/"); - var dt = new Date(str); - if (!isInvalidDate(dt)) { - return dt; - } +export const object2Number = function (value) { + if (value == null) { + return 0; + } + if (typeof value === "number") { + return value; + } + var str = value + ""; + if (str.indexOf(".") === -1) { + return parseInt(str); + } + return parseFloat(str); +}; +export const object2Date = function (obj) { + if (obj == null) { return new Date(); + } + if (obj instanceof Date) { + return obj; + } else if (typeof obj === "number") { + return new Date(obj); + } + var str = obj + ""; + str = str.replace(/-/g, "/"); + var dt = new Date(str); + if (!isInvalidDate(dt)) { + return dt; + } - }; + return new Date(); - BI.object2Time = function (obj) { - if (obj == null) { - return new Date(); - } - if (obj instanceof Date) { - return obj; - } - var str = obj + ""; - str = str.replace(/-/g, "/"); - var dt = new Date(str); - if (!isInvalidDate(dt)) { - return dt; - } - if (str.indexOf("/") === -1 && str.indexOf(":") !== -1) { - dt = new Date("1970/01/01 " + str); - if (!isInvalidDate(dt)) { - return dt; - } - } - dt = BI.parseDateTime(str, "HH:mm:ss"); +}; + +export const object2Time = function (obj) { + if (obj == null) { + return new Date(); + } + if (obj instanceof Date) { + return obj; + } + var str = obj + ""; + str = str.replace(/-/g, "/"); + var dt = new Date(str); + if (!isInvalidDate(dt)) { + return dt; + } + if (str.indexOf("/") === -1 && str.indexOf(":") !== -1) { + dt = new Date("1970/01/01 " + str); if (!isInvalidDate(dt)) { return dt; } - return new Date(); + } + dt = parseDateTime(str, "HH:mm:ss"); + if (!isInvalidDate(dt)) { + return dt; + } + return new Date(); - }; -})(); +}; diff --git a/src/core/func/array.js b/src/core/func/array.js index a96292352..98f7d3703 100644 --- a/src/core/func/array.js +++ b/src/core/func/array.js @@ -2,21 +2,18 @@ * 对数组对象的扩展 * @class Array */ -BI._.extend(BI, { +export function pushArray(sArray, array) { + sArray.push(...array); +} - pushArray: function (sArray, array) { - for (var i = 0; i < array.length; i++) { - sArray.push(array[i]); - } - }, - pushDistinct: function (sArray, obj) { - if (!BI.contains(sArray, obj)) { - sArray.push(obj); - } - }, - pushDistinctArray: function (sArray, array) { - for (var i = 0, len = array.length; i < len; i++) { - BI.pushDistinct(sArray, array[i]); - } +export function pushDistinct(sArray, obj) { + if (sArray.indexOf(obj) !== -1) { + sArray.push(obj); } -}); +} + +export function pushDistinctArray(sArray, array) { + for (let i = 0, len = array.length; i < len; i++) { + pushDistinct(sArray, array[i]); + } +} diff --git a/src/core/func/date.js b/src/core/func/date.js index d603d235c..0d6ea79d3 100644 --- a/src/core/func/date.js +++ b/src/core/func/date.js @@ -1,16 +1,14 @@ /** Constants used for time computations */ -BI.Date = BI.Date || {}; -BI.Date.SECOND = 1000; -BI.Date.MINUTE = 60 * BI.Date.SECOND; -BI.Date.HOUR = 60 * BI.Date.MINUTE; -BI.Date.DAY = 24 * BI.Date.HOUR; -BI.Date.WEEK = 7 * BI.Date.DAY; +import {getDate, getTime} from "../2.base"; -// Monday first, etc. -BI.Date._FD = 1; - -// short month names -BI.Date._SMN = [0, +const SECOND = 1000; +const MINUTE = 60 * SECOND; +const HOUR = 60 * MINUTE; +const DAY = 24 * HOUR; +const WEEK = 7 * DAY; +const _FD = 1; +const _SMN = [ + 0, 1, 2, 3, @@ -21,292 +19,361 @@ BI.Date._SMN = [0, 8, 9, 10, - 11]; + 11 +]; +const _MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; +const _OFFSET = [0, -1, -2, -3, -4, -5, -6]; // 实际上无论周几作为一周的第一天,周初周末都是在-6-0间做偏移,用一个数组就可以 -/** Adds the number of days array to the Date object. */ -BI.Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; +export const Date = { + SECOND, + MINUTE, + HOUR, + DAY, + WEEK, + _FD, + _SMN, + _MD, + _OFFSET, +}; -// 实际上无论周几作为一周的第一天,周初周末都是在-6-0间做偏移,用一个数组就可以 -BI.Date._OFFSET = [0, -1, -2, -3, -4, -5, -6]; +/** + * 获取时区 + * @returns {String} + */ +export function getTimezone(date) { + return date.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, "$1$2").replace(/[^A-Z]/g, ""); +} -BI._.extend(BI, { - /** - * 获取时区 - * @returns {String} - */ - getTimezone: function (date) { - return date.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, "$1$2").replace(/[^A-Z]/g, ""); - }, +/** + * Returns the number of days in the current month + */ +export function getMonthDays(date, month = date.getMonth()) { + var year = date.getFullYear(); + if (((0 === (year % 4)) && ((0 !== (year % 100)) || (0 === (year % 400)))) && month === 1) { + return 29; + } + return _MD[month]; +} - /** Returns the number of days in the current month */ - getMonthDays: function (date, month) { - var year = date.getFullYear(); - if (typeof month === "undefined") { - month = date.getMonth(); - } - if (((0 == (year % 4)) && ((0 != (year % 100)) || (0 == (year % 400)))) && month == 1) { - return 29; - } - return BI.Date._MD[month]; +/** + * 获取每月的最后一天 + * @returns {Date} + */ +export function getLastDateOfMont(date) { + return getDate(date.getFullYear(), date.getMonth(), getMonthDays(date)); +} - }, +/** + * 获取每月的最后一天 + * @returns {Date} + */ +export function getLastDateOfMonth(date) { + return getDate(date.getFullYear(), date.getMonth(), getMonthDays(date)); +} - /** - * 获取每月的最后一天 - * @returns {Date} - */ - getLastDateOfMonth: function (date) { - return BI.getDate(date.getFullYear(), date.getMonth(), BI.getMonthDays(date)); - }, +/** + * Returns the number of day in the year. + * @param date + * @returns {number} + */ +export function getDayOfYear(date) { + var now = getDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); + var then = getDate(date.getFullYear(), 0, 0, 0, 0, 0); + var time = now - then; + return Math.floor(time / DAY); +} - /** Returns the number of day in the year. */ - getDayOfYear: function (date) { - var now = BI.getDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); - var then = BI.getDate(date.getFullYear(), 0, 0, 0, 0, 0); - var time = now - then; - return Math.floor(time / BI.Date.DAY); - }, - /** Returns the number of the week in year, as defined in ISO 8601. */ - getWeekNumber: function (date) { - var d = BI.getDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); - var week = d.getDay(); - var startOfWeek = BI.StartOfWeek % 7; - var middleDay = (startOfWeek + 3) % 7; - middleDay = middleDay || 7; - // 偏移到周周首之前需要多少天 - var offsetWeekStartCount = week < startOfWeek ? (7 + week - startOfWeek) : (week - startOfWeek); - var offsetWeekMiddleCount = middleDay < startOfWeek ? (7 + middleDay - startOfWeek) : (middleDay - startOfWeek); - d.setDate(d.getDate() - offsetWeekStartCount + offsetWeekMiddleCount); - var ms = d.valueOf(); - d.setMonth(0); - d.setDate(1); - return Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1; - }, +/** + * Returns the number of the week in year, as defined in ISO 8601. + * @param date + * @returns {number} + */ +export function getWeekNumber(date) { + var d = getDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); + var week = d.getDay(); + var startOfWeek = BI.StartOfWeek % 7; + var middleDay = (startOfWeek + 3) % 7; + middleDay = middleDay || 7; + // 偏移到周周首之前需要多少天 + var offsetWeekStartCount = week < startOfWeek ? (7 + week - startOfWeek) : (week - startOfWeek); + var offsetWeekMiddleCount = middleDay < startOfWeek ? (7 + middleDay - startOfWeek) : (middleDay - startOfWeek); + d.setDate(d.getDate() - offsetWeekStartCount + offsetWeekMiddleCount); + var ms = d.valueOf(); + d.setMonth(0); + d.setDate(1); + return Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1; +} - getQuarter: function (date) { - return Math.floor(date.getMonth() / 3) + 1; - }, +export function getQuarter(date) { + return Math.floor(date.getMonth() / 3) + 1; +} - // 离当前时间多少天的时间 - getOffsetDate: function (date, offset) { - return BI.getDate(BI.getTime(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()) + offset * 864e5); - }, +/** + * 离当前时间多少天的时间 + * @param date + * @param offset + * @returns {Date} + */ +export function getOffsetDate(date, offset) { + return getDate(getTime(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()) + offset * 864e5); +} - getOffsetQuarter: function (date, n) { - var dt = BI.getDate(BI.getTime(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds())); - var day = dt.getDate(); - var monthDay = BI.getMonthDays(BI.getDate(dt.getFullYear(), dt.getMonth() + BI.parseInt(n) * 3, 1)); - if (day > monthDay) { - day = monthDay; - } - dt.setDate(day); - dt.setMonth(dt.getMonth() + parseInt(n) * 3); - return dt; - }, +export function getOffsetQuarter(date, n) { + var dt = getDate(getTime(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds())); + var day = dt.getDate(); + var monthDay = BI.getMonthDays(getDate(dt.getFullYear(), dt.getMonth() + parseInt(n, 10) * 3, 1)); + if (day > monthDay) { + day = monthDay; + } + dt.setDate(day); + dt.setMonth(dt.getMonth() + parseInt(n, 10) * 3); + return dt; +} - // 得到本季度的起始月份 - getQuarterStartMonth: function (date) { - var quarterStartMonth = 0; - var nowMonth = date.getMonth(); - if (nowMonth < 3) { - quarterStartMonth = 0; - } - if (2 < nowMonth && nowMonth < 6) { - quarterStartMonth = 3; - } - if (5 < nowMonth && nowMonth < 9) { - quarterStartMonth = 6; - } - if (nowMonth > 8) { - quarterStartMonth = 9; - } - return quarterStartMonth; - }, - // 获得本季度的起始日期 - getQuarterStartDate: function (date) { - return BI.getDate(date.getFullYear(), BI.getQuarterStartMonth(date), 1); - }, - // 得到本季度的结束日期 - getQuarterEndDate: function (date) { - var quarterEndMonth = BI.getQuarterStartMonth(date) + 2; - return BI.getDate(date.getFullYear(), quarterEndMonth, BI.getMonthDays(date, quarterEndMonth)); - }, +/** + * 得到本季度的起始月份 + * @param date + * @returns {number} + */ +export function getQuarterStartMonth(date) { + var quarterStartMonth = 0; + var nowMonth = date.getMonth(); + if (nowMonth < 3) { + quarterStartMonth = 0; + } + if (2 < nowMonth && nowMonth < 6) { + quarterStartMonth = 3; + } + if (5 < nowMonth && nowMonth < 9) { + quarterStartMonth = 6; + } + if (nowMonth > 8) { + quarterStartMonth = 9; + } + return quarterStartMonth; +} - // 指定日期n个月之前或之后的日期 - getOffsetMonth: function (date, n) { - var dt = BI.getDate(BI.getTime(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds())); - var day = dt.getDate(); - var monthDay = BI.getMonthDays(BI.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1)); - if (day > monthDay) { - day = monthDay; - } - dt.setDate(day); - dt.setMonth(dt.getMonth() + parseInt(n)); - return dt; - }, +/** + * 获得本季度的起始日期 + * @param date + * @returns {Date} + */ +export function getQuarterStartDate(date) { + return getDate(date.getFullYear(), getQuarterStartMonth(date), 1); +} - // 获得本周的起始日期 - getWeekStartDate: function (date) { - var w = date.getDay(); - var startOfWeek = BI.StartOfWeek % 7; - return BI.getOffsetDate(date, BI.Date._OFFSET[w < startOfWeek ? (7 + w - startOfWeek) : (w - startOfWeek)]); - }, - // 得到本周的结束日期 - getWeekEndDate: function (date) { - var w = date.getDay(); - var startOfWeek = BI.StartOfWeek % 7; - return BI.getOffsetDate(date, BI.Date._OFFSET[w < startOfWeek ? (7 + w - startOfWeek) : (w - startOfWeek)] + 6); - }, +/** + * 得到本季度的结束日期 + * @param date + * @returns {Date} + */ +export function getQuarterEndDate(date) { + var quarterEndMonth = getQuarterStartMonth(date) + 2; + return getDate(date.getFullYear(), quarterEndMonth, getMonthDays(date)); +} - getFullDayName: function (index) { - return [BI.i18nText("BI-Basic_Sunday"), - BI.i18nText("BI-Basic_Monday"), - BI.i18nText("BI-Basic_Tuesday"), - BI.i18nText("BI-Basic_Wednesday"), - BI.i18nText("BI-Basic_Thursday"), - BI.i18nText("BI-Basic_Friday"), - BI.i18nText("BI-Basic_Saturday"), - BI.i18nText("BI-Basic_Sunday")][index]; - }, +/** + * 指定日期n个月之前或之后的日期 + * @param date + * @param n + * @returns {Date} + */ +export function getOffsetMonth(date, n) { + var dt = getDate(getTime(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds())); + var day = dt.getDate(); + var monthDay = getMonthDays(getDate(dt.getFullYear(), dt.getMonth() + parseInt(n, 10), 1)); + if (day > monthDay) { + day = monthDay; + } + dt.setDate(day); + dt.setMonth(dt.getMonth() + parseInt(n, 10)); + return dt; +} - getShortDayName: function (index) { - return [BI.i18nText("BI-Basic_Simple_Sunday"), - BI.i18nText("BI-Basic_Simple_Monday"), - BI.i18nText("BI-Basic_Simple_Tuesday"), - BI.i18nText("BI-Basic_Simple_Wednesday"), - BI.i18nText("BI-Basic_Simple_Thursday"), - BI.i18nText("BI-Basic_Simple_Friday"), - BI.i18nText("BI-Basic_Simple_Saturday"), - BI.i18nText("BI-Basic_Simple_Sunday")][index]; - }, +/** + * 获得本周的起始日期 + * @param date + * @returns {Date} + */ +export function getWeekStartDate(date) { + var w = date.getDay(); + var startOfWeek = BI.StartOfWeek % 7; + return getOffsetDate(date, _OFFSET[w < startOfWeek ? (7 + w - startOfWeek) : (w - startOfWeek)]); +} - getMonthName: function (index) { - return [BI.i18nText("BI-Basic_January"), - BI.i18nText("BI-Basic_February"), - BI.i18nText("BI-Basic_March"), - BI.i18nText("BI-Basic_April"), - BI.i18nText("BI-Basic_May"), - BI.i18nText("BI-Basic_June"), - BI.i18nText("BI-Basic_July"), - BI.i18nText("BI-Basic_August"), - BI.i18nText("BI-Basic_September"), - BI.i18nText("BI-Basic_October"), - BI.i18nText("BI-Basic_November"), - BI.i18nText("BI-Basic_December")][index] - }, +/** + * 得到本周的结束日期 + * @param date + * @returns {Date} + */ +export function getWeekEndDate(date) { + var w = date.getDay(); + var startOfWeek = BI.StartOfWeek % 7; + return getOffsetDate(date, _OFFSET[w < startOfWeek ? (7 + w - startOfWeek) : (w - startOfWeek)] + 6); +} - getQuarterName: function (index) { - return ["", BI.i18nText("BI-Quarter_1"), - BI.i18nText("BI-Quarter_2"), - BI.i18nText("BI-Quarter_3"), - BI.i18nText("BI-Quarter_4")][index]; - }, +export function getFullDayName(index) { + return [ + BI.i18nText("BI-Basic_Sunday"), + BI.i18nText("BI-Basic_Monday"), + BI.i18nText("BI-Basic_Tuesday"), + BI.i18nText("BI-Basic_Wednesday"), + BI.i18nText("BI-Basic_Thursday"), + BI.i18nText("BI-Basic_Friday"), + BI.i18nText("BI-Basic_Saturday"), + BI.i18nText("BI-Basic_Sunday") + ][index]; +} - // 格式化打印日期 - print: function (date, str) { - var m = date.getMonth(); - var d = date.getDate(); - var y = date.getFullYear(); - var yWith4number = y + ""; - while (yWith4number.length < 4) { - yWith4number = "0" + yWith4number; - } - var wn = BI.getWeekNumber(date); - var qr = BI.getQuarter(date); - var w = date.getDay(); - var s = {}; - var hr = date.getHours(); - var pm = (hr >= 12); - var ir = (pm) ? (hr - 12) : hr; - var dy = BI.getDayOfYear(date); - if (ir == 0) { - ir = 12; - } - var min = date.getMinutes(); - var sec = date.getSeconds(); - s["%a"] = BI.getShortDayName(w); // abbreviated weekday name [FIXME: I18N] - s["%A"] = BI.getFullDayName(w); // full weekday name - s["%b"] = BI.Date._SMN[m]; // abbreviated month name [FIXME: I18N] - s["%B"] = BI.getMonthName(m); // full month name - // FIXME: %c : preferred date and time representation for the current locale - s["%C"] = 1 + Math.floor(y / 100); // the century number - s["%d"] = (d < 10) ? ("0" + d) : d; // the day of the month (range 01 to 31) - s["%e"] = d; // the day of the month (range 1 to 31) - // FIXME: %D : american date style: %m/%d/%y - // FIXME: %E, %F, %G, %g, %h (man strftime) - s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format) - s["%I"] = (ir < 10) ? ("0" + ir) : ir; // hour, range 01 to 12 (12h format) - s["%j"] = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy; // day of the year (range 001 to 366) - s["%k"] = hr + ""; // hour, range 0 to 23 (24h format) - s["%l"] = ir + ""; // hour, range 1 to 12 (12h format) - s["%X"] = (m < 9) ? ("0" + (1 + m)) : (1 + m); // month, range 01 to 12 - s["%x"] = m + 1; // month, range 1 to 12 - s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 - s["%n"] = "\n"; // a newline character - s["%p"] = pm ? "PM" : "AM"; - s["%P"] = pm ? "pm" : "am"; - // FIXME: %r : the time in am/pm notation %I:%M:%S %p - // FIXME: %R : the time in 24-hour notation %H:%M - s["%s"] = Math.floor(date.getTime() / 1000); - s["%S"] = (sec < 10) ? ("0" + sec) : sec; // seconds, range 00 to 59 - s["%t"] = "\t"; // a tab character - // FIXME: %T : the time in 24-hour notation (%H:%M:%S) - s["%U"] = s["%W"] = s["%V"] = (wn < 10) ? ("0" + wn) : wn; - s["%u"] = w + 1; // the day of the week (range 1 to 7, 1 = MON) - s["%w"] = w; // the day of the week (range 0 to 6, 0 = SUN) - // FIXME: %x : preferred date representation for the current locale without the time - // FIXME: %X : preferred time representation for the current locale without the date - s["%y"] = yWith4number.substr(2, 2); // year without the century (range 00 to 99) - s["%Y"] = yWith4number; // year with the century - s["%%"] = "%"; // a literal '%' character - s["%q"] = "0" + qr; - s["%Q"] = qr; +export function getShortDayName(index) { + return [ + BI.i18nText("BI-Basic_Simple_Sunday"), + BI.i18nText("BI-Basic_Simple_Monday"), + BI.i18nText("BI-Basic_Simple_Tuesday"), + BI.i18nText("BI-Basic_Simple_Wednesday"), + BI.i18nText("BI-Basic_Simple_Thursday"), + BI.i18nText("BI-Basic_Simple_Friday"), + BI.i18nText("BI-Basic_Simple_Saturday"), + BI.i18nText("BI-Basic_Simple_Sunday") + ][index]; +} - var re = /%./g; - BI.isKhtml = BI.isKhtml || function () { - if(!_global.navigator) { - return false; - } - return /Konqueror|Safari|KHTML/i.test(navigator.userAgent); - }; +export function getMonthName(index) { + return [ + BI.i18nText("BI-Basic_January"), + BI.i18nText("BI-Basic_February"), + BI.i18nText("BI-Basic_March"), + BI.i18nText("BI-Basic_April"), + BI.i18nText("BI-Basic_May"), + BI.i18nText("BI-Basic_June"), + BI.i18nText("BI-Basic_July"), + BI.i18nText("BI-Basic_August"), + BI.i18nText("BI-Basic_September"), + BI.i18nText("BI-Basic_October"), + BI.i18nText("BI-Basic_November"), + BI.i18nText("BI-Basic_December") + ][index]; +} - // 包含年周的格式化,ISO8601标准周的计数会影响年 - if ((str.indexOf("%Y") !== -1 || str.indexOf("%y") !== -1) && (str.indexOf("%W") !== -1 || str.indexOf("%U") !== -1 || str.indexOf("%V") !== -1)) { - switch (wn) { - // 如果周数是1,但是当前却在12月,表示此周数为下一年的 - case 1: - if (m === 11) { - s["%y"] = parseInt(s["%y"]) + 1; - s["%Y"] = parseInt(s["%Y"]) + 1; - } - break; - // 如果周数是53,但是当前却在1月,表示此周数为上一年的 - case 53: - if (m === 0) { - s["%y"] = parseInt(s["%y"]) - 1; - s["%Y"] = parseInt(s["%Y"]) - 1; - } - break; - default: - break; - } - } +export function getQuarterName(index) { + return [ + "", + BI.i18nText("BI-Quarter_1"), + BI.i18nText("BI-Quarter_2"), + BI.i18nText("BI-Quarter_3"), + BI.i18nText("BI-Quarter_4") + ][index]; +} - if (!BI.isKhtml()) { - return str.replace(re, function (par) { - return s[par] || par; - }); +/** + * 格式化打印日期 + * @param date + * @param str + * @returns {*} + */ +export function print(date, str) { + var m = date.getMonth(); + var d = date.getDate(); + var y = date.getFullYear(); + var yWith4number = y + ""; + while (yWith4number.length < 4) { + yWith4number = "0" + yWith4number; + } + var wn = getWeekNumber(date); + var qr = getQuarter(date); + var w = date.getDay(); + var s = {}; + var hr = date.getHours(); + var pm = (hr >= 12); + var ir = (pm) ? (hr - 12) : hr; + var dy = getDayOfYear(date); + if (ir === 0) { + ir = 12; + } + var min = date.getMinutes(); + var sec = date.getSeconds(); + s["%a"] = getShortDayName(w); // abbreviated weekday name [FIXME: I18N] + s["%A"] = getFullDayName(w); // full weekday name + s["%b"] = _SMN[m]; // abbreviated month name [FIXME: I18N] + s["%B"] = getMonthName(m); // full month name + // FIXME: %c : preferred date and time representation for the current locale + s["%C"] = 1 + Math.floor(y / 100); // the century number + s["%d"] = (d < 10) ? ("0" + d) : d; // the day of the month (range 01 to 31) + s["%e"] = d; // the day of the month (range 1 to 31) + // FIXME: %D : american date style: %m/%d/%y + // FIXME: %E, %F, %G, %g, %h (man strftime) + s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format) + s["%I"] = (ir < 10) ? ("0" + ir) : ir; // hour, range 01 to 12 (12h format) + s["%j"] = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy; // day of the year (range 001 to 366) + s["%k"] = hr + ""; // hour, range 0 to 23 (24h format) + s["%l"] = ir + ""; // hour, range 1 to 12 (12h format) + s["%X"] = (m < 9) ? ("0" + (1 + m)) : (1 + m); // month, range 01 to 12 + s["%x"] = m + 1; // month, range 1 to 12 + s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 + s["%n"] = "\n"; // a newline character + s["%p"] = pm ? "PM" : "AM"; + s["%P"] = pm ? "pm" : "am"; + // FIXME: %r : the time in am/pm notation %I:%M:%S %p + // FIXME: %R : the time in 24-hour notation %H:%M + s["%s"] = Math.floor(date.getTime() / 1000); + s["%S"] = (sec < 10) ? ("0" + sec) : sec; // seconds, range 00 to 59 + s["%t"] = "\t"; // a tab character + // FIXME: %T : the time in 24-hour notation (%H:%M:%S) + s["%U"] = s["%W"] = s["%V"] = (wn < 10) ? ("0" + wn) : wn; + s["%u"] = w + 1; // the day of the week (range 1 to 7, 1 = MON) + s["%w"] = w; // the day of the week (range 0 to 6, 0 = SUN) + // FIXME: %x : preferred date representation for the current locale without the time + // FIXME: %X : preferred time representation for the current locale without the date + s["%y"] = yWith4number.substr(2, 2); // year without the century (range 00 to 99) + s["%Y"] = yWith4number; // year with the century + s["%%"] = "%"; // a literal '%' character + s["%q"] = "0" + qr; + s["%Q"] = qr; + + var re = /%./g; + BI.isKhtml = BI.isKhtml || function () { + if (!_global.navigator) { + return false; } - var a = str.match(re); - for (var i = 0; i < a.length; i++) { - var tmp = s[a[i]]; - if (tmp) { - re = new RegExp(a[i], "g"); - str = str.replace(re, tmp); - } + return /Konqueror|Safari|KHTML/i.test(navigator.userAgent); + }; + + // 包含年周的格式化,ISO8601标准周的计数会影响年 + if ((str.indexOf("%Y") !== -1 || str.indexOf("%y") !== -1) && (str.indexOf("%W") !== -1 || str.indexOf("%U") !== -1 || str.indexOf("%V") !== -1)) { + switch (wn) { + // 如果周数是1,但是当前却在12月,表示此周数为下一年的 + case 1: + if (m === 11) { + s["%y"] = parseInt(s["%y"]) + 1; + s["%Y"] = parseInt(s["%Y"]) + 1; + } + break; + // 如果周数是53,但是当前却在1月,表示此周数为上一年的 + case 53: + if (m === 0) { + s["%y"] = parseInt(s["%y"]) - 1; + s["%Y"] = parseInt(s["%Y"]) - 1; + } + break; + default: + break; } + } - return str; + if (!BI.isKhtml()) { + return str.replace(re, function (par) { + return s[par] || par; + }); } -}); + var a = str.match(re); + for (var i = 0; i < a.length; i++) { + var tmp = s[a[i]]; + if (tmp) { + re = new RegExp(a[i], "g"); + str = str.replace(re, tmp); + } + } + + return str; +} diff --git a/src/core/func/function.js b/src/core/func/function.js index 83d58c5ec..e66b54453 100644 --- a/src/core/func/function.js +++ b/src/core/func/function.js @@ -2,167 +2,173 @@ * 基本的函数 * Created by GUY on 2015/6/24. */ -BI.Func = BI.Func || {}; -BI._.extend(BI.Func, { - /** - * 创建唯一的名字 - * @param array - * @param name - * @returns {*} - */ - createDistinctName: function (array, name) { - var src = name, idx = 1; - name = name || ""; - while (true) { - if (BI.every(array, function (i, item) { - return BI.isKey(item) ? item !== name : item.name !== name; - })) { - break; - } - name = src + (idx++); +import {every, isKey, isArray, toUpperCase, each, stripEL, isNotNull, isNull, isObject} from "../2.base"; +import {makeFirstPY} from "../utils/chinesePY"; + +/** + * 创建唯一的名字 + * @param array + * @param name + * @returns {*} + */ +export function createDistinctName(array, name) { + var src = name, idx = 1; + name = name || ""; + while (true) { + if (every(array, function (i, item) { + return isKey(item) ? item !== name : item.name !== name; + })) { + break; } - return name; - }, + name = src + (idx++); + } + return name; +} - /** - * 获取字符宽度 - * @param str - * @return {number} - */ - getGBWidth: function (str) { - str = str + ""; - str = str.replace(/[^\x00-\xff]/g, "xx"); - return Math.ceil(str.length / 2); - }, +/** + * 获取字符宽度 + * @param str + * @return {number} + */ +export function getGBWidth(str) { + str = str + ""; + str = str.replace(/[^\x00-\xff]/g, "xx"); + return Math.ceil(str.length / 2); +} - /** - * 获取搜索结果 - * @param items - * @param keyword - * @param param 搜索哪个属性 - */ - getSearchResult: function (items, keyword, param) { - var isArray = BI.isArray(items); - items = isArray ? BI.flatten(items) : items; - param || (param = "text"); - if (!BI.isKey(keyword)) { - return { - find: items, - match: isArray ? [] : {} - }; +/** + * 获取搜索结果 + * @param items + * @param keyword + * @param param 搜索哪个属性 + */ +export function getSearchResult(items, keyword, param) { + var array = isArray(items); + items = array ? BI.flatten(items) : items; + param || (param = "text"); + if (!isKey(keyword)) { + return { + find: items, + match: array ? [] : {} + }; + } + var t, text, py; + keyword = toUpperCase(keyword); + var matched = array ? [] : {}, find = array ? [] : {}; + each(items, function (i, item) { + // 兼容item为null的处理 + if (isNull(item)) { + return; } - var t, text, py; - keyword = BI.toUpperCase(keyword); - var matched = isArray ? [] : {}, find = isArray ? [] : {}; - BI.each(items, function (i, item) { - // 兼容item为null的处理 - if (BI.isNull(item)) { - return; - } - t = BI.stripEL(item); - text = BI.find([t[param], t.text, t.value, t.name, t], function (index, val) { - return BI.isNotNull(val); - }); + t = stripEL(item); + text = [t[param], t.text, t.value, t.name, t].find(isNotNull); - if (BI.isNull(text) || BI.isObject(text)) return; + if (isNull(text) || isObject(text)) return; - py = BI.makeFirstPY(text, { - splitChar: "\u200b" - }); - text = BI.toUpperCase(text); - py = BI.toUpperCase(py); - var pidx; - if (text.indexOf(keyword) > -1) { - if (text === keyword) { - isArray ? matched.push(item) : (matched[i] = item); - } else { - isArray ? find.push(item) : (find[i] = item); - } - // BI-56386 这边两个pid / text.length是为了防止截取的首字符串不是完整的,但光这样做还不够,即时错位了,也不能说明就不符合条件 - } else if (pidx = py.indexOf(keyword), (pidx > -1)) { + py = makeFirstPY(text, { + splitChar: "\u200b" + }); + text = toUpperCase(text); + py = toUpperCase(py); + var pidx; + if (text.indexOf(keyword) > -1) { + if (text === keyword) { + array ? matched.push(item) : (matched[i] = item); + } else { + array ? find.push(item) : (find[i] = item); + } + } else { // BI-56386 这边两个pid / text.length是为了防止截取的首字符串不是完整的,但光这样做还不够,即时错位了,也不能说明就不符合条件 + pidx = py.indexOf(keyword); + if (pidx > -1) { if (text === keyword || keyword.length === text.length) { - isArray ? matched.push(item) : (matched[i] = item); + array ? matched.push(item) : (matched[i] = item); } else { - isArray ? find.push(item) : (find[i] = item); + array ? find.push(item) : (find[i] = item); } } - }); - return { - match: matched, - find: find - }; - }, - - /** - * 获取按GB2312排序的结果 - * @param items - * @param key - * @return {any[]} - */ - getSortedResult: function (items, key) { - var getTextOfItem = BI.isFunction(key) ? key : - function (item, key) { - if (BI.isNotNull(key)) { - return item[key]; - } - if (BI.isNotNull(item.text)) { - return item.text; - } - if (BI.isNotNull(item.value)) { - return item.value; - } - return item; - }; + } + }); + return { + match: matched, + find: find + }; +} - return items.sort(function (item1, item2) { - var str1 = getTextOfItem(item1, key); - var str2 = getTextOfItem(item2, key); - if (BI.isNull(str1) && BI.isNull(str2)) { - return 0; - } - if (BI.isNull(str1)) { - return -1; - } - if (BI.isNull(str2)) { - return 1; - } - if (str1 === str2) { - return 0; +/** + * 获取按GB2312排序的结果 + * @param items + * @param key + * @return {any[]} + */ +export function getSortedResult(items, key) { + var getTextOfItem = BI.isFunction(key) ? key : + function (item, key) { + if (BI.isNotNull(key)) { + return item[key]; } - var len1 = str1.length, len2 = str2.length; - for (var i = 0; i < len1 && i < len2; i++) { - var char1 = str1[i]; - var char2 = str2[i]; - if (char1 !== char2) { - // 找不到的字符都往后面放 - return (BI.isNull(BI.CODE_INDEX[char1]) ? BI.MAX : BI.CODE_INDEX[char1]) - (BI.isNull(BI.CODE_INDEX[char2]) ? BI.MAX : BI.CODE_INDEX[char2]); - } + if (BI.isNotNull(item.text)) { + return item.text; } - return len1 - len2; - }); - } -}); - -BI._.extend(BI, { - beforeFunc: function (sFunc, func) { - var __self = sFunc; - return function () { - if (func.apply(sFunc, arguments) === false) { - return false; + if (BI.isNotNull(item.value)) { + return item.value; } - return __self.apply(sFunc, arguments); + return item; }; - }, - afterFunc: function (sFunc, func) { - var __self = sFunc; - return function () { - var ret = __self.apply(sFunc, arguments); - if (ret === false) { - return false; + return items.sort(function (item1, item2) { + var str1 = getTextOfItem(item1, key); + var str2 = getTextOfItem(item2, key); + if (BI.isNull(str1) && BI.isNull(str2)) { + return 0; + } + if (BI.isNull(str1)) { + return -1; + } + if (BI.isNull(str2)) { + return 1; + } + if (str1 === str2) { + return 0; + } + var len1 = str1.length, len2 = str2.length; + for (var i = 0; i < len1 && i < len2; i++) { + var char1 = str1[i]; + var char2 = str2[i]; + if (char1 !== char2) { + // 找不到的字符都往后面放 + return (BI.isNull(BI.CODE_INDEX[char1]) ? BI.MAX : BI.CODE_INDEX[char1]) - (BI.isNull(BI.CODE_INDEX[char2]) ? BI.MAX : BI.CODE_INDEX[char2]); } - func.apply(sFunc, arguments); - return ret; - }; - } -}); + } + return len1 - len2; + }); +} + +export function beforeFunc(sFunc, func) { + var __self = sFunc; + return function () { + if (func.apply(sFunc, arguments) === false) { + return false; + } + return __self.apply(sFunc, arguments); + }; +} + +export function afterFunc(sFunc, func) { + var __self = sFunc; + return function () { + var ret = __self.apply(sFunc, arguments); + if (ret === false) { + return false; + } + func.apply(sFunc, arguments); + return ret; + }; +} + + +export const Func = { + createDistinctName, + getGBWidth, + getSearchResult, + getSortedResult, +}; diff --git a/src/core/func/index.js b/src/core/func/index.js new file mode 100644 index 000000000..3475bf8d6 --- /dev/null +++ b/src/core/func/index.js @@ -0,0 +1,23 @@ +export * from "./alias"; +export * from "./array"; +export * from "./date"; +export * from "./function"; +export * from "./number"; +export * from "./string"; + +// need delete +import * as _alias from "./alias"; +import * as _array from "./array"; +import * as _date from "./date"; +import * as _function from "./function"; +import * as _number from "./number"; +import * as _string from "./string"; + +Object.assign(BI, { + ..._alias, + ..._array, + ..._date, + ..._function, + ..._number, + ..._string +}); diff --git a/src/core/func/number.js b/src/core/func/number.js index 59021349f..73f9dbec6 100644 --- a/src/core/func/number.js +++ b/src/core/func/number.js @@ -1,156 +1,154 @@ -BI._.extend(BI, { - // 给Number类型增加一个add方法,调用起来更加方便。 - add: function (num, arg) { - return accAdd(arg, num); +// 给Number类型增加一个add方法,调用起来更加方便。 +export function add(num, arg) { + return accAdd(arg, num); - /** - ** 加法函数,用来得到精确的加法结果 - ** 说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。 - ** 调用:accAdd(arg1,arg2) - ** 返回值:arg1加上arg2的精确结果 - **/ - function accAdd (arg1, arg2) { - var r1, r2, m, c; - try { - r1 = arg1.toString().split(".")[1].length; - } catch (e) { - r1 = 0; - } - try { - r2 = arg2.toString().split(".")[1].length; - } catch (e) { - r2 = 0; - } - c = Math.abs(r1 - r2); - m = Math.pow(10, Math.max(r1, r2)); - if (c > 0) { - var cm = Math.pow(10, c); - if (r1 > r2) { - arg1 = Number(arg1.toString().replace(".", "")); - arg2 = Number(arg2.toString().replace(".", "")) * cm; - } else { - arg1 = Number(arg1.toString().replace(".", "")) * cm; - arg2 = Number(arg2.toString().replace(".", "")); - } - } else { + /** + ** 加法函数,用来得到精确的加法结果 + ** 说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。 + ** 调用:accAdd(arg1,arg2) + ** 返回值:arg1加上arg2的精确结果 + **/ + function accAdd(arg1, arg2) { + var r1, r2, m, c; + try { + r1 = arg1.toString().split(".")[1].length; + } catch (e) { + r1 = 0; + } + try { + r2 = arg2.toString().split(".")[1].length; + } catch (e) { + r2 = 0; + } + c = Math.abs(r1 - r2); + m = Math.pow(10, Math.max(r1, r2)); + if (c > 0) { + var cm = Math.pow(10, c); + if (r1 > r2) { arg1 = Number(arg1.toString().replace(".", "")); + arg2 = Number(arg2.toString().replace(".", "")) * cm; + } else { + arg1 = Number(arg1.toString().replace(".", "")) * cm; arg2 = Number(arg2.toString().replace(".", "")); } - return (arg1 + arg2) / m; + } else { + arg1 = Number(arg1.toString().replace(".", "")); + arg2 = Number(arg2.toString().replace(".", "")); } - }, + return (arg1 + arg2) / m; + } +} - // 给Number类型增加一个sub方法,调用起来更加方便。 - sub: function (num, arg) { - return accSub(num, arg); +// 给Number类型增加一个sub方法,调用起来更加方便。 +export function sub(num, arg) { + return accSub(num, arg); - /** - ** 减法函数,用来得到精确的减法结果 - ** 说明:javascript的减法结果会有误差,在两个浮点数相减的时候会比较明显。这个函数返回较为精确的减法结果。 - ** 调用:accSub(arg1,arg2) - ** 返回值:arg1加上arg2的精确结果 - **/ - function accSub (arg1, arg2) { - var r1, r2, m, n; - try { - r1 = arg1.toString().split(".")[1].length; - } catch (e) { - r1 = 0; - } - try { - r2 = arg2.toString().split(".")[1].length; - } catch (e) { - r2 = 0; - } - m = Math.pow(10, Math.max(r1, r2)); // last modify by deeka //动态控制精度长度 - n = (r1 >= r2) ? r1 : r2; - return ((arg1 * m - arg2 * m) / m).toFixed(n); + /** + ** 减法函数,用来得到精确的减法结果 + ** 说明:javascript的减法结果会有误差,在两个浮点数相减的时候会比较明显。这个函数返回较为精确的减法结果。 + ** 调用:accSub(arg1,arg2) + ** 返回值:arg1加上arg2的精确结果 + **/ + function accSub(arg1, arg2) { + var r1, r2, m, n; + try { + r1 = arg1.toString().split(".")[1].length; + } catch (e) { + r1 = 0; + } + try { + r2 = arg2.toString().split(".")[1].length; + } catch (e) { + r2 = 0; } - }, + m = Math.pow(10, Math.max(r1, r2)); // last modify by deeka //动态控制精度长度 + n = (r1 >= r2) ? r1 : r2; + return ((arg1 * m - arg2 * m) / m).toFixed(n); + } +} - // 给Number类型增加一个mul方法,调用起来更加方便。 - mul: function (num, arg) { - return accMul(arg, num); +// 给Number类型增加一个mul方法,调用起来更加方便。 +export function mul(num, arg) { + return accMul(arg, num); - /** - ** 乘法函数,用来得到精确的乘法结果 - ** 说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。 - ** 调用:accMul(arg1,arg2) - ** 返回值:arg1乘以 arg2的精确结果 - **/ - function accMul (arg1, arg2) { - var m = 0, s1 = arg1.toString(), s2 = arg2.toString(); - try { - m += s1.split(".")[1].length; - } catch (e) { - } - try { - m += s2.split(".")[1].length; - } catch (e) { - } - return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m); + /** + ** 乘法函数,用来得到精确的乘法结果 + ** 说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。 + ** 调用:accMul(arg1,arg2) + ** 返回值:arg1乘以 arg2的精确结果 + **/ + function accMul(arg1, arg2) { + var m = 0, s1 = arg1.toString(), s2 = arg2.toString(); + try { + m += s1.split(".")[1].length; + } catch (e) { } - }, - - // 给Number类型增加一个div方法,调用起来更加方便。 - div: function (num, arg) { - return accDivide(num, arg); - - /** - * Return digits length of a number - * @param {*number} num Input number - */ - function digitLength (num) { - // Get digit length of e - var eSplit = num.toString().split(/[eE]/); - var len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0)); - return len > 0 ? len : 0; - } - /** - * 把小数转成整数,支持科学计数法。如果是小数则放大成整数 - * @param {*number} num 输入数 - */ - function float2Fixed (num) { - if (num.toString().indexOf("e") === -1) { - return Number(num.toString().replace(".", "")); - } - var dLen = digitLength(num); - return dLen > 0 ? num * Math.pow(10, dLen) : num; + try { + m += s2.split(".")[1].length; + } catch (e) { } + return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m); + } +} - /** - * 精确乘法 - */ - function times (num1, num2) { - var others = []; - for (var _i = 2; _i < arguments.length; _i++) { - others[_i - 2] = arguments[_i]; - } - if (others.length > 0) { - return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1))); - } - var num1Changed = float2Fixed(num1); - var num2Changed = float2Fixed(num2); - var baseNum = digitLength(num1) + digitLength(num2); - var leftValue = num1Changed * num2Changed; - return leftValue / Math.pow(10, baseNum); +// 给Number类型增加一个div方法,调用起来更加方便。 +export function div(num, arg) { + return accDivide(num, arg); + + /** + * Return digits length of a number + * @param {*number} num Input number + */ + function digitLength(num) { + // Get digit length of e + var eSplit = num.toString().split(/[eE]/); + var len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0)); + return len > 0 ? len : 0; + } + + /** + * 把小数转成整数,支持科学计数法。如果是小数则放大成整数 + * @param {*number} num 输入数 + */ + function float2Fixed(num) { + if (num.toString().indexOf("e") === -1) { + return Number(num.toString().replace(".", "")); } + var dLen = digitLength(num); + return dLen > 0 ? num * Math.pow(10, dLen) : num; + } - /** - * 精确除法 - */ - function accDivide (num1, num2) { - var others = []; - for (var _i = 2; _i < arguments.length; _i++) { - others[_i - 2] = arguments[_i]; - } - if (others.length > 0) { - return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1))); - } - var num1Changed = float2Fixed(num1); - var num2Changed = float2Fixed(num2); - return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1))); + /** + * 精确乘法 + */ + function times(num1, num2) { + var others = []; + for (var _i = 2; _i < arguments.length; _i++) { + others[_i - 2] = arguments[_i]; + } + if (others.length > 0) { + return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1))); } + var num1Changed = float2Fixed(num1); + var num2Changed = float2Fixed(num2); + var baseNum = digitLength(num1) + digitLength(num2); + var leftValue = num1Changed * num2Changed; + return leftValue / Math.pow(10, baseNum); } -}); \ No newline at end of file + /** + * 精确除法 + */ + function accDivide(num1, num2) { + var others = []; + for (var _i = 2; _i < arguments.length; _i++) { + others[_i - 2] = arguments[_i]; + } + if (others.length > 0) { + return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1))); + } + var num1Changed = float2Fixed(num1); + var num2Changed = float2Fixed(num2); + return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1))); + } +} diff --git a/src/core/func/string.js b/src/core/func/string.js index 55a89e63f..de5b29628 100644 --- a/src/core/func/string.js +++ b/src/core/func/string.js @@ -1,123 +1,121 @@ +import {isString} from "../2.base"; + /** - * 对字符串对象的扩展 - * @class String + * 判断字符串是否已指定的字符串开始 + * @param str source字符串 + * @param {String} startTag 指定的开始字符串 + * @return {Boolean} 如果字符串以指定字符串开始则返回true,否则返回false */ -BI._.extend(BI, { +export function startWith(str, startTag) { + str = str || ""; + if (startTag == null || startTag == "" || str.length === 0 || startTag.length > str.length) { + return false; + } + return str.substr(0, startTag.length) == startTag; +} - /** - * 判断字符串是否已指定的字符串开始 - * @param str source字符串 - * @param {String} startTag 指定的开始字符串 - * @return {Boolean} 如果字符串以指定字符串开始则返回true,否则返回false - */ - startWith: function (str, startTag) { - str = str || ""; - if (startTag == null || startTag == "" || str.length === 0 || startTag.length > str.length) { - return false; - } - return str.substr(0, startTag.length) == startTag; - }, - /** - * 判断字符串是否以指定的字符串结束 - * @param str source字符串 - * @param {String} endTag 指定的字符串 - * @return {Boolean} 如果字符串以指定字符串结束则返回true,否则返回false - */ - endWith: function (str, endTag) { - if (endTag == null || endTag == "" || str.length === 0 || endTag.length > str.length) { - return false; - } - return str.substring(str.length - endTag.length) == endTag; - }, +/** + * 判断字符串是否以指定的字符串结束 + * @param str source字符串 + * @param {String} endTag 指定的字符串 + * @return {Boolean} 如果字符串以指定字符串结束则返回true,否则返回false + */ +export function endWith(str, endTag) { + if (endTag == null || endTag == "" || str.length === 0 || endTag.length > str.length) { + return false; + } + return str.substring(str.length - endTag.length) == endTag; +} - /** - * 获取url中指定名字的参数 - * @param str source字符串 - * @param {String} name 参数的名字 - * @return {String} 参数的值 - */ - getQuery: function (str, name) { - var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); - var r = str.substr(str.indexOf("?") + 1).match(reg); - if (r) { - return unescape(r[2]); - } - return null; - }, +/** + * 获取url中指定名字的参数 + * @param str source字符串 + * @param {String} name 参数的名字 + * @return {String} 参数的值 + */ +export function getQuery(str, name) { + var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); + var r = str.substr(str.indexOf("?") + 1).match(reg); + if (r) { + return unescape(r[2]); + } + return null; +} - /** - * 给url加上给定的参数 - * @param str source字符串 - * @param {Object} paras 参数对象,是一个键值对对象 - * @return {String} 添加了给定参数的url - */ - appendQuery: function (str, paras) { - if (!paras) { - return str; - } - var src = str; - // 没有问号说明还没有参数 - if (src.indexOf("?") === -1) { - src += "?"; - } - // 如果以问号结尾,说明没有其他参数 - if (BI.endWith(src, "?") !== false) { - } else { - src += "&"; - } - BI._.each(paras, function (value, name) { - if (typeof(name) === "string") { - src += name + "=" + value + "&"; - } - }); - src = src.substr(0, src.length - 1); - return src; - }, - /** - * 将所有符合第一个字符串所表示的字符串替换成为第二个字符串 - * @param str source字符串 - * @param {String} s1 要替换的字符串的正则表达式 - * @param {String} s2 替换的结果字符串 - * @returns {String} 替换后的字符串 - */ - replaceAll: function (str, s1, s2) { - return BI.isString(str) ? str.replace(new RegExp(s1, "gm"), s2) : str; - }, - /** - * 总是让字符串以指定的字符开头 - * @param str source字符串 - * @param {String} start 指定的字符 - * @returns {String} 以指定字符开头的字符串 - */ - perfectStart: function (str, start) { - if (BI.startWith(str, start)) { - return str; +/** + * 给url加上给定的参数 + * @param str source字符串 + * @param {Object} paras 参数对象,是一个键值对对象 + * @return {String} 添加了给定参数的url + */ +export function appendQuery(str, paras) { + if (!paras) { + return str; + } + var src = str; + // 没有问号说明还没有参数 + if (src.indexOf("?") === -1) { + src += "?"; + } + // 如果以问号结尾,说明没有其他参数 + if (BI.endWith(src, "?") !== false) { + } else { + src += "&"; + } + BI._.each(paras, function (value, name) { + if (typeof (name) === "string") { + src += name + "=" + value + "&"; } - return start + str; + }); + src = src.substr(0, src.length - 1); + return src; +} - }, +/** + * 将所有符合第一个字符串所表示的字符串替换成为第二个字符串 + * @param str source字符串 + * @param {String} s1 要替换的字符串的正则表达式 + * @param {String} s2 替换的结果字符串 + * @returns {String} 替换后的字符串 + */ +export function replaceAll(str, s1, s2) { + return isString(str) ? str.replace(new RegExp(s1, "gm"), s2) : str; +} - /** - * 获取字符串中某字符串的所有项位置数组 - * @param str source字符串 - * @param {String} sub 子字符串 - * @return {Number[]} 子字符串在父字符串中出现的所有位置组成的数组 - */ - allIndexOf: function (str, sub) { - if (typeof sub !== "string") { - return []; - } - var location = []; - var offset = 0; - while (str.length > 0) { - var loc = str.indexOf(sub); - if (loc === -1) { - break; - } - location.push(offset + loc); - str = str.substring(loc + sub.length, str.length); - offset += loc + sub.length; +/** + * 总是让字符串以指定的字符开头 + * @param str source字符串 + * @param {String} start 指定的字符 + * @returns {String} 以指定字符开头的字符串 + */ +export function perfectStart(str, start) { + if (BI.startWith(str, start)) { + return str; + } + return start + str; + +} + +/** + * 获取字符串中某字符串的所有项位置数组 + * @param str source字符串 + * @param {String} sub 子字符串 + * @return {Number[]} 子字符串在父字符串中出现的所有位置组成的数组 + */ +export function allIndexOf(str, sub) { + if (typeof sub !== "string") { + return []; + } + var location = []; + var offset = 0; + while (str.length > 0) { + var loc = str.indexOf(sub); + if (loc === -1) { + break; } - return location; + location.push(offset + loc); + str = str.substring(loc + sub.length, str.length); + offset += loc + sub.length; } -}); \ No newline at end of file + return location; +} diff --git a/src/core/index.js b/src/core/index.js index 0b0f014c0..dbcd9f509 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,4 +1,4 @@ -import { shortcut } from "./decorator"; +import {shortcut} from "./decorator"; import OB from "./3.ob"; import Widget from "./4.widget"; import Action from "./action/action"; @@ -16,6 +16,7 @@ import PopoverController from "./controller/controller.popover"; import ResizeController from "./controller/controller.resizer"; import TooltipsController from "./controller/controller.tooltips"; import StyleLoaderManager from "./loader/loader.style"; +import "./h"; BI.extend(BI, { OB, @@ -56,6 +57,7 @@ export { ResizeController, TooltipsController, StyleLoaderManager, -} +}; -export * from './2.base'; \ No newline at end of file +export * from './2.base'; +export * from "./func"; diff --git a/src/core/platform/web/detectElementResize.js b/src/core/platform/web/detectElementResize.js index 3183a57c4..502ebb0ee 100644 --- a/src/core/platform/web/detectElementResize.js +++ b/src/core/platform/web/detectElementResize.js @@ -323,7 +323,22 @@ var ResizeObserverPolyfill = (function (exports) { }; var CATCH_PERIOD = 250; var observerConfig = { attributes: true, characterData: true, childList: true, subtree: true }; - var events = ['resize', 'load', 'transitionend', 'animationend', 'animationstart', 'animationiteration', 'keyup', 'keydown', 'mouseup', 'mousedown', 'mouseover', 'mouseout', 'blur', 'focus']; + var events = [ + 'resize', + 'load', + 'transitionend', + 'animationend', + 'animationstart', + 'animationiteration', + 'keyup', + 'keydown', + 'mouseup', + 'mousedown', + 'mouseover', + 'mouseout', + 'blur', + 'focus' + ]; var time = function (timeout) { if (timeout === void 0) { timeout = 0; @@ -412,14 +427,17 @@ var ResizeObserverPolyfill = (function (exports) { }; var skipNotifyOnElement = function (target) { - return !isSVG(target) && !isReplacedElement(target) && getComputedStyle(target).display === 'inline'; + return !isSVG(target) + && !isReplacedElement(target) + && getComputedStyle(target).display === 'inline'; }; var ResizeObservation = (function () { function ResizeObservation(target, observedBox) { this.target = target; this.observedBox = observedBox || ResizeObserverBoxOptions.CONTENT_BOX; this.lastReportedSize = { - inlineSize: -1, blockSize: -1 + inlineSize: -1, + blockSize: -1 }; } @@ -428,7 +446,8 @@ var ResizeObserverPolyfill = (function (exports) { if (skipNotifyOnElement(this.target)) { this.lastReportedSize = size; } - if (this.lastReportedSize.inlineSize !== size.inlineSize || this.lastReportedSize.blockSize !== size.blockSize) { + if (this.lastReportedSize.inlineSize !== size.inlineSize + || this.lastReportedSize.blockSize !== size.blockSize) { return true; } return false; @@ -534,64 +553,58 @@ var ResizeObserverPolyfill = (function (exports) { return ResizeObserver; }()); - exports.ResizeObserver = ResizeObserver; - exports.ResizeObserverEntry = ResizeObserverEntry; - exports.ResizeObserverSize = ResizeObserverSize; - - Object.defineProperty(exports, '__esModule', { value: true }); - - return exports; - -})({}); - -var ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill.ResizeObserver; + return ResizeObserver; +})(); -!(function () { +var ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill; - var addResizeListener = function (element, fn) { - if (ResizeObserver) { - if (!element.__resizeObserver__) { - var resizeObserver = new ResizeObserver(function () { - element.__resizeListeners__.forEach(function (listener) { - BI.$(element).is(":visible") && listener(); - }); +var addResizeListener = function (element, fn) { + if (ResizeObserver) { + if (!element.__resizeObserver__) { + var resizeObserver = new ResizeObserver(function () { + element.__resizeListeners__.forEach(function (listener) { + BI.$(element).is(":visible") && listener(); }); - resizeObserver.observe(element); - element.__resizeObserver__ = resizeObserver; - } - if (!element.__resizeListeners__) { - element.__resizeListeners__ = []; - } - element.__resizeListeners__.push(fn); + }); + resizeObserver.observe(element); + element.__resizeObserver__ = resizeObserver; } - }; - var removeResizeListener = function (element, fn) { - if (ResizeObserver) { - if (BI.isNull(fn)) { - element.__resizeListeners__ = []; + if (!element.__resizeListeners__) { + element.__resizeListeners__ = []; + } + element.__resizeListeners__.push(fn); + } +}; +var removeResizeListener = function (element, fn) { + if (ResizeObserver) { + if (BI.isNull(fn)) { + element.__resizeListeners__ = []; + element.__resizeObserver__ && element.__resizeObserver__.unobserve(element); + element.__resizeObserver__ = null; + return; + } + var index = element.__resizeListeners__.indexOf(fn); + if (index >= 0) { + element.__resizeListeners__.splice(index, 1); + if (!element.__resizeListeners__.length) { element.__resizeObserver__ && element.__resizeObserver__.unobserve(element); element.__resizeObserver__ = null; - return; - } - var index = element.__resizeListeners__.indexOf(fn); - if (index >= 0) { - element.__resizeListeners__.splice(index, 1); - if (!element.__resizeListeners__.length) { - element.__resizeObserver__ && element.__resizeObserver__.unobserve(element); - element.__resizeObserver__ = null; - } } } - }; + } +}; - BI.ResizeDetector = { - addResizeListener: function (widget, fn) { - addResizeListener(widget.element[0], fn); - return function () { - removeResizeListener(widget.element[0], fn); - }; - }, removeResizeListener: function (widget, fn) { +export const ResizeDetector = { + addResizeListener: function (widget, fn) { + addResizeListener(widget.element[0], fn); + return function () { removeResizeListener(widget.element[0], fn); - } - }; -})(); + }; + }, removeResizeListener: function (widget, fn) { + removeResizeListener(widget.element[0], fn); + } +}; + +Object.assign(BI, { + ResizeDetector +}); diff --git a/src/core/utils/chinesePY.js b/src/core/utils/chinesePY.js index b22cd94cb..3ef5567db 100644 --- a/src/core/utils/chinesePY.js +++ b/src/core/utils/chinesePY.js @@ -2,439 +2,444 @@ * 汉字拼音索引 */ -!(function () { - var _ChineseFirstPY = "YDYQSXMWZSSXJBYMGCCZQPSSQBYCDSCDQLDYLYBSSJGYZZJJFKCCLZDHWDWZJLJPFYYNWJJTMYHZWZHFLZPPQHGSCYYYNJQYXXGJHHSDSJNKKTMOMLCRXYPSNQSECCQZGGLLYJLMYZZSECYKYYHQWJSSGGYXYZYJWWKDJHYCHMYXJTLXJYQBYXZLDWRDJRWYSRLDZJPCBZJJBRCFTLECZSTZFXXZHTRQHYBDLYCZSSYMMRFMYQZPWWJJYFCRWFDFZQPYDDWYXKYJAWJFFXYPSFTZYHHYZYSWCJYXSCLCXXWZZXNBGNNXBXLZSZSBSGPYSYZDHMDZBQBZCWDZZYYTZHBTSYYBZGNTNXQYWQSKBPHHLXGYBFMJEBJHHGQTJCYSXSTKZHLYCKGLYSMZXYALMELDCCXGZYRJXSDLTYZCQKCNNJWHJTZZCQLJSTSTBNXBTYXCEQXGKWJYFLZQLYHYXSPSFXLMPBYSXXXYDJCZYLLLSJXFHJXPJBTFFYABYXBHZZBJYZLWLCZGGBTSSMDTJZXPTHYQT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XYTSXXYLBYQHWWKXHZXWZNNZZJZJJQJCCCHYYXBZXZCYZTLLCQXYNJYCYYCYNZZQYYYEWYCZDCJYCCHYJLBTZYYCQWMPWPYMLGKDLDLGKQQBGYCHJXY"; - // 此处收录了375个多音字,数据来自于http://www.51windows.net/pages/pinyin.asp - var oMultiDiff = { - 19969: "DZ", - 19975: "WM", - 19988: "QJ", - 20048: "YL", - 20056: "SC", - 20060: "NM", - 20094: "QG", - 20127: "QJ", - 20167: "QC", - 20193: "YG", - 20250: "KH", - 20256: "ZC", - 20282: "SC", - 20285: "QJG", - 20291: "TD", - 20314: "YD", - 20315: "BF", - 20340: "NE", - 20375: "TD", - 20389: "YJ", - 20391: "CZ", - 20415: "PB", - 20446: "YS", - 20447: "SQ", - 20504: "TC", - 20608: "KG", - 20854: "QJ", - 20857: "ZC", - 20911: "PF", - 20985: "AW", - 21032: "PB", - 21048: "XQ", - 21049: "SC", - 21089: "YS", - 21119: "JC", - 21242: "SB", - 21273: "SC", - 21305: "YP", - 21306: "QO", - 21330: "ZC", - 21333: "SDC", - 21345: "QK", - 21378: "CA", - 21397: "SC", - 21414: "XS", - 21442: "SC", - 21477: "JG", - 21480: "TD", - 21484: "ZS", - 21494: "YX", - 21505: "YX", - 21512: "HG", - 21523: "XH", - 21537: "PB", - 21542: "PF", - 21549: "KH", - 21571: "E", - 21574: "DA", - 21588: "TD", - 21589: "O", - 21618: "ZC", - 21621: "KHA", - 21632: "ZJ", - 21654: "KG", - 21679: "LKG", - 21683: "KH", - 21710: "A", - 21719: "YH", - 21734: "WOE", - 21769: "A", - 21780: "WN", - 21804: "XH", - 21834: "A", - 21899: "ZD", - 21903: "RN", - 21908: "WO", - 21939: "ZC", - 21956: "SA", - 21964: "YA", - 21970: "TD", - 22003: "A", - 22031: "JG", - 22040: "XS", - 22060: "ZC", - 22066: "ZC", - 22079: "MH", - 22129: "XJ", - 22179: "XA", - 22237: "NJ", - 22244: "TD", - 22280: "JQ", - 22300: "YH", - 22313: "XW", - 22331: "YQ", - 22343: "YJ", - 22351: "PH", - 22395: "DC", - 22412: "TD", - 22484: "PB", - 22500: "PB", - 22534: "ZD", - 22549: "DH", - 22561: "PB", - 22612: "TD", - 22771: "KQ", - 22831: "HB", - 22841: "JG", - 22855: "QJ", - 22865: "XQ", - 23013: "ML", - 23081: "WM", - 23487: "SX", - 23558: "QJ", - 23561: "YW", - 23586: "YW", - 23614: "YW", - 23615: "SN", - 23631: "PB", - 23646: "ZS", - 23663: "ZT", - 23673: "YG", - 23762: "TD", - 23769: "ZS", - 23780: "QJ", - 23884: "QK", - 24055: "XH", - 24113: "DC", - 24162: "ZC", - 24191: "GA", - 24273: "QJ", - 24324: "NL", - 24377: "TD", - 24378: "QJ", - 24439: "PF", - 24554: "ZS", - 24683: "TD", - 24694: "WE", - 24733: "LK", - 24925: "TN", - 25094: "ZG", - 25100: "XQ", - 25103: "XH", - 25153: "PB", - 25170: "PB", - 25179: "KG", - 25203: "PB", - 25240: "ZS", - 25282: "FB", - 25303: "NA", - 25324: "KG", - 25341: "ZY", - 25373: "WZ", - 25375: "XJ", - 25384: "A", - 25457: "A", - 25528: "SD", - 25530: "SC", - 25552: "TD", - 25774: "ZC", - 25874: "ZC", - 26044: "YW", - 26080: "WM", - 26292: "PB", - 26333: "PB", - 26355: "ZY", - 26366: "CZ", - 26397: "ZC", - 26399: "QJ", - 26415: "ZS", - 26451: "SB", - 26526: "ZC", - 26552: "JG", - 26561: "TD", - 26588: "JG", - 26597: "CZ", - 26629: "ZS", - 26638: "YL", - 26646: "XQ", - 26653: "KG", - 26657: "XJ", - 26727: "HG", - 26894: "ZC", - 26937: "ZS", - 26946: "ZC", - 26999: "KJ", - 27099: "KJ", - 27449: "YQ", - 27481: "XS", - 27542: "ZS", - 27663: "ZS", - 27748: "TS", - 27784: "SC", - 27788: "ZD", - 27795: "TD", - 27812: "O", - 27850: "PB", - 27852: "MB", - 27895: "SL", - 27898: "PL", - 27973: "QJ", - 27981: "KH", - 27986: "HX", - 27994: "XJ", - 28044: "YC", - 28065: "WG", - 28177: "SM", - 28267: "QJ", - 28291: "KH", - 28337: "ZQ", - 28463: "TL", - 28548: "DC", - 28601: "TD", - 28689: "PB", - 28805: "JG", - 28820: "QG", - 28846: "PB", - 28952: "TD", - 28975: "ZC", - 29100: "A", - 29325: "QJ", - 29575: "SL", - 29602: "FB", - 30010: "TD", - 30044: "CX", - 30058: "PF", - 30091: "YSP", - 30111: "YN", - 30229: "XJ", - 30427: "SC", - 30465: "SX", - 30631: "YQ", - 30655: "QJ", - 30684: "QJG", - 30707: "SD", - 30729: "XH", - 30796: "LG", - 30917: "PB", - 31074: "NM", - 31085: "JZ", - 31109: "SC", - 31181: "ZC", - 31192: "MLB", - 31293: "JQ", - 31400: "YX", - 31584: "YJ", - 31896: "ZN", - 31909: "ZY", - 31995: "XJ", - 32321: "PF", - 32327: "ZY", - 32418: "HG", - 32420: "XQ", - 32421: "HG", - 32438: "LG", - 32473: "GJ", - 32488: "TD", - 32521: "QJ", - 32527: "PB", - 32562: "ZSQ", - 32564: "JZ", - 32735: "ZD", - 32793: "PB", - 33071: "PF", - 33098: "XL", - 33100: "YA", - 33152: "PB", - 33261: "CX", - 33324: "BP", - 33333: "TD", - 33406: "YA", - 33426: "WM", - 33432: "PB", - 33445: "JG", - 33486: "ZN", - 33493: "TS", - 33507: "QJ", - 33540: "QJ", - 33544: "ZC", - 33564: "XQ", - 33617: "YT", - 33632: "QJ", - 33636: "XH", - 33637: "YX", - 33694: "WG", - 33705: "PF", - 33728: "YW", - 33882: "SR", - 34067: "WM", - 34074: "YW", - 34121: "QJ", - 34255: "ZC", - 34259: "XL", - 34425: "JH", - 34430: "XH", - 34485: "KH", - 34503: "YS", - 34532: "HG", - 34552: "XS", - 34558: "YE", - 34593: "ZL", - 34660: "YQ", - 34892: "XH", - 34928: "SC", - 34999: "QJ", - 35048: "PB", - 35059: "SC", - 35098: "ZC", - 35203: "TQ", - 35265: "JX", - 35299: "JX", - 35782: "SZ", - 35828: "YS", - 35830: "E", - 35843: "TD", - 35895: "YG", - 35977: "MH", - 36158: "JG", - 36228: "QJ", - 36426: "XQ", - 36466: "DC", - 36710: "CJ", - 36711: "ZYG", - 36767: "PB", - 36866: "SK", - 36951: "YW", - 37034: "YX", - 37063: "XH", - 37218: "ZC", - 37325: "ZC", - 38063: "PB", - 38079: "TD", - 38085: "QY", - 38107: "DC", - 38116: "TD", - 38123: "YD", - 38224: "HG", - 38241: "XTC", - 38271: "ZC", - 38415: "YE", - 38426: "KH", - 38461: "YD", - 38463: "AE", - 38466: "PB", - 38477: "XJ", - 38518: "YT", - 38551: "WK", - 38585: "ZC", - 38704: "XS", - 38739: "LJ", - 38761: "GJ", - 38808: "SQ", - 39048: "JG", - 39049: "XJ", - 39052: "HG", - 39076: "CZ", - 39271: "XT", - 39534: "TD", - 39552: "TD", - 39584: "PB", - 39647: "SB", - 39730: "LG", - 39748: "TPB", - 40109: "ZQ", - 40479: "ND", - 40516: "HG", - 40536: "HG", - 40583: "QJ", - 40765: "YQ", - 40784: "QJ", - 40840: "YK", - 40863: "QJG" - }; +// 此处收录了375个多音字,数据来自于http://www.51windows.net/pages/pinyin.asp +const oMultiDiff = { + 19969: "DZ", + 19975: "WM", + 19988: "QJ", + 20048: "YL", + 20056: "SC", + 20060: "NM", + 20094: "QG", + 20127: "QJ", + 20167: "QC", + 20193: "YG", + 20250: "KH", + 20256: "ZC", + 20282: "SC", + 20285: "QJG", + 20291: "TD", + 20314: "YD", + 20315: "BF", + 20340: "NE", + 20375: "TD", + 20389: "YJ", + 20391: "CZ", + 20415: "PB", + 20446: "YS", + 20447: "SQ", + 20504: "TC", + 20608: "KG", + 20854: "QJ", + 20857: "ZC", + 20911: "PF", + 20985: "AW", + 21032: "PB", + 21048: "XQ", + 21049: "SC", + 21089: "YS", + 21119: "JC", + 21242: "SB", + 21273: "SC", + 21305: "YP", + 21306: "QO", + 21330: "ZC", + 21333: "SDC", + 21345: "QK", + 21378: "CA", + 21397: "SC", + 21414: "XS", + 21442: "SC", + 21477: "JG", + 21480: "TD", + 21484: "ZS", + 21494: "YX", + 21505: "YX", + 21512: "HG", + 21523: "XH", + 21537: "PB", + 21542: "PF", + 21549: "KH", + 21571: "E", + 21574: "DA", + 21588: "TD", + 21589: "O", + 21618: "ZC", + 21621: "KHA", + 21632: "ZJ", + 21654: "KG", + 21679: "LKG", + 21683: "KH", + 21710: "A", + 21719: "YH", + 21734: "WOE", + 21769: "A", + 21780: "WN", + 21804: "XH", + 21834: "A", + 21899: "ZD", + 21903: "RN", + 21908: "WO", + 21939: "ZC", + 21956: "SA", + 21964: "YA", + 21970: "TD", + 22003: "A", + 22031: "JG", + 22040: "XS", + 22060: "ZC", + 22066: "ZC", + 22079: "MH", + 22129: "XJ", + 22179: "XA", + 22237: "NJ", + 22244: "TD", + 22280: "JQ", + 22300: "YH", + 22313: "XW", + 22331: "YQ", + 22343: "YJ", + 22351: "PH", + 22395: "DC", + 22412: "TD", + 22484: "PB", + 22500: "PB", + 22534: "ZD", + 22549: "DH", + 22561: "PB", + 22612: "TD", + 22771: "KQ", + 22831: "HB", + 22841: "JG", + 22855: "QJ", + 22865: "XQ", + 23013: "ML", + 23081: "WM", + 23487: "SX", + 23558: "QJ", + 23561: "YW", + 23586: "YW", + 23614: "YW", + 23615: "SN", + 23631: "PB", + 23646: "ZS", + 23663: "ZT", + 23673: "YG", + 23762: "TD", + 23769: "ZS", + 23780: "QJ", + 23884: "QK", + 24055: "XH", + 24113: "DC", + 24162: "ZC", + 24191: "GA", + 24273: "QJ", + 24324: "NL", + 24377: "TD", + 24378: "QJ", + 24439: "PF", + 24554: "ZS", + 24683: "TD", + 24694: "WE", + 24733: "LK", + 24925: "TN", + 25094: "ZG", + 25100: "XQ", + 25103: "XH", + 25153: "PB", + 25170: "PB", + 25179: "KG", + 25203: "PB", + 25240: "ZS", + 25282: "FB", + 25303: "NA", + 25324: "KG", + 25341: "ZY", + 25373: "WZ", + 25375: "XJ", + 25384: "A", + 25457: "A", + 25528: "SD", + 25530: "SC", + 25552: "TD", + 25774: "ZC", + 25874: "ZC", + 26044: "YW", + 26080: "WM", + 26292: "PB", + 26333: "PB", + 26355: "ZY", + 26366: "CZ", + 26397: "ZC", + 26399: "QJ", + 26415: "ZS", + 26451: "SB", + 26526: "ZC", + 26552: "JG", + 26561: "TD", + 26588: "JG", + 26597: "CZ", + 26629: "ZS", + 26638: "YL", + 26646: "XQ", + 26653: "KG", + 26657: "XJ", + 26727: "HG", + 26894: "ZC", + 26937: "ZS", + 26946: "ZC", + 26999: "KJ", + 27099: "KJ", + 27449: "YQ", + 27481: "XS", + 27542: "ZS", + 27663: "ZS", + 27748: "TS", + 27784: "SC", + 27788: "ZD", + 27795: "TD", + 27812: "O", + 27850: "PB", + 27852: "MB", + 27895: "SL", + 27898: "PL", + 27973: "QJ", + 27981: "KH", + 27986: "HX", + 27994: "XJ", + 28044: "YC", + 28065: "WG", + 28177: "SM", + 28267: "QJ", + 28291: "KH", + 28337: "ZQ", + 28463: "TL", + 28548: "DC", + 28601: "TD", + 28689: "PB", + 28805: "JG", + 28820: "QG", + 28846: "PB", + 28952: "TD", + 28975: "ZC", + 29100: "A", + 29325: "QJ", + 29575: "SL", + 29602: "FB", + 30010: "TD", + 30044: "CX", + 30058: "PF", + 30091: "YSP", + 30111: "YN", + 30229: "XJ", + 30427: "SC", + 30465: "SX", + 30631: "YQ", + 30655: "QJ", + 30684: "QJG", + 30707: "SD", + 30729: "XH", + 30796: "LG", + 30917: "PB", + 31074: "NM", + 31085: "JZ", + 31109: "SC", + 31181: "ZC", + 31192: "MLB", + 31293: "JQ", + 31400: "YX", + 31584: "YJ", + 31896: "ZN", + 31909: "ZY", + 31995: "XJ", + 32321: "PF", + 32327: "ZY", + 32418: "HG", + 32420: "XQ", + 32421: "HG", + 32438: "LG", + 32473: "GJ", + 32488: "TD", + 32521: "QJ", + 32527: "PB", + 32562: "ZSQ", + 32564: "JZ", + 32735: "ZD", + 32793: "PB", + 33071: "PF", + 33098: "XL", + 33100: "YA", + 33152: "PB", + 33261: "CX", + 33324: "BP", + 33333: "TD", + 33406: "YA", + 33426: "WM", + 33432: "PB", + 33445: "JG", + 33486: "ZN", + 33493: "TS", + 33507: "QJ", + 33540: "QJ", + 33544: "ZC", + 33564: "XQ", + 33617: "YT", + 33632: "QJ", + 33636: "XH", + 33637: "YX", + 33694: "WG", + 33705: "PF", + 33728: "YW", + 33882: "SR", + 34067: "WM", + 34074: "YW", + 34121: "QJ", + 34255: "ZC", + 34259: "XL", + 34425: "JH", + 34430: "XH", + 34485: "KH", + 34503: "YS", + 34532: "HG", + 34552: "XS", + 34558: "YE", + 34593: "ZL", + 34660: "YQ", + 34892: "XH", + 34928: "SC", + 34999: "QJ", + 35048: "PB", + 35059: "SC", + 35098: "ZC", + 35203: "TQ", + 35265: "JX", + 35299: "JX", + 35782: "SZ", + 35828: "YS", + 35830: "E", + 35843: "TD", + 35895: "YG", + 35977: "MH", + 36158: "JG", + 36228: "QJ", + 36426: "XQ", + 36466: "DC", + 36710: "CJ", + 36711: "ZYG", + 36767: "PB", + 36866: "SK", + 36951: "YW", + 37034: "YX", + 37063: "XH", + 37218: "ZC", + 37325: "ZC", + 38063: "PB", + 38079: "TD", + 38085: "QY", + 38107: "DC", + 38116: "TD", + 38123: "YD", + 38224: "HG", + 38241: "XTC", + 38271: "ZC", + 38415: "YE", + 38426: "KH", + 38461: "YD", + 38463: "AE", + 38466: "PB", + 38477: "XJ", + 38518: "YT", + 38551: "WK", + 38585: "ZC", + 38704: "XS", + 38739: "LJ", + 38761: "GJ", + 38808: "SQ", + 39048: "JG", + 39049: "XJ", + 39052: "HG", + 39076: "CZ", + 39271: "XT", + 39534: "TD", + 39552: "TD", + 39584: "PB", + 39647: "SB", + 39730: "LG", + 39748: "TPB", + 40109: "ZQ", + 40479: "ND", + 40516: "HG", + 40536: "HG", + 40583: "QJ", + 40765: "YQ", + 40784: "QJ", + 40840: "YK", + 40863: "QJG" +}; - var _checkPYCh = function (ch) { - var uni = ch.charCodeAt(0); - // 如果不在汉字处理范围之内,返回原字符,也可以调用自己的处理函数 - if (uni > 40869 || uni < 19968) {return ch;} // dealWithOthers(ch); - return (oMultiDiff[uni] ? oMultiDiff[uni] : (_ChineseFirstPY.charAt(uni - 19968))); - }; +const _checkPYCh = function (ch) { + var uni = ch.charCodeAt(0); + // 如果不在汉字处理范围之内,返回原字符,也可以调用自己的处理函数 + if (uni > 40869 || uni < 19968) { + return ch; + } // dealWithOthers(ch); + return (oMultiDiff[uni] ? oMultiDiff[uni] : (_ChineseFirstPY.charAt(uni - 19968))); +}; - var _mkPYRslt = function (arr, options) { - var ignoreMulti = options.ignoreMulti; - var splitChar = options.splitChar; - var arrRslt = [""], k, multiLen = 0; - for (var i = 0, len = arr.length; i < len; i++) { - var str = arr[i]; - var strlen = str.length; - // 多音字过多的情况下,指数增长会造成浏览器卡死,超过20完全卡死,18勉强能用,考虑到不同性能最好是16或者14 - // 超过14个多音字之后,后面的都用第一个拼音 - if (strlen == 1 || multiLen > 14 || ignoreMulti) { - var tmpStr = str.substring(0, 1); - for (k = 0; k < arrRslt.length; k++) { - arrRslt[k] += tmpStr; - } - } else { - var tmpArr = arrRslt.slice(0); - arrRslt = []; - multiLen ++; - for (k = 0; k < strlen; k++) { - // 复制一个相同的arrRslt - var tmp = tmpArr.slice(0); - // 把当前字符str[k]添加到每个元素末尾 - for (var j = 0; j < tmp.length; j++) { - tmp[j] += str.charAt(k); - } - // 把复制并修改后的数组连接到arrRslt上 - arrRslt = arrRslt.concat(tmp); +const _mkPYRslt = function (arr, options) { + var ignoreMulti = options.ignoreMulti; + var splitChar = options.splitChar; + var arrRslt = [""], k, multiLen = 0; + for (var i = 0, len = arr.length; i < len; i++) { + var str = arr[i]; + var strlen = str.length; + // 多音字过多的情况下,指数增长会造成浏览器卡死,超过20完全卡死,18勉强能用,考虑到不同性能最好是16或者14 + // 超过14个多音字之后,后面的都用第一个拼音 + if (strlen == 1 || multiLen > 14 || ignoreMulti) { + var tmpStr = str.substring(0, 1); + for (k = 0; k < arrRslt.length; k++) { + arrRslt[k] += tmpStr; + } + } else { + var tmpArr = arrRslt.slice(0); + arrRslt = []; + multiLen++; + for (k = 0; k < strlen; k++) { + // 复制一个相同的arrRslt + var tmp = tmpArr.slice(0); + // 把当前字符str[k]添加到每个元素末尾 + for (var j = 0; j < tmp.length; j++) { + tmp[j] += str.charAt(k); } + // 把复制并修改后的数组连接到arrRslt上 + arrRslt = arrRslt.concat(tmp); } } - // BI-56386 这边直接将所有多音字组合拼接是有风险的,因为丢失了每一组的起始索引信息, 外部使用indexOf等方法会造成错位 - // 一旦错位就可能认为不符合条件, 但实际上还是有可能符合条件的,故此处以一个无法搜索的不可见字符作为连接 - return arrRslt.join(splitChar || "").toLowerCase(); - }; + } + // BI-56386 这边直接将所有多音字组合拼接是有风险的,因为丢失了每一组的起始索引信息, 外部使用indexOf等方法会造成错位 + // 一旦错位就可能认为不符合条件, 但实际上还是有可能符合条件的,故此处以一个无法搜索的不可见字符作为连接 + return arrRslt.join(splitChar || "").toLowerCase(); +}; - BI._.extend(BI, { - makeFirstPY: function (str, options) { - options = options || {}; - if (typeof (str) !== "string") {return "" + str;} - var arrResult = []; // 保存中间结果的数组 - for (var i = 0, len = str.length; i < len; i++) { - // 获得unicode码 - var ch = str.charAt(i); - // 检查该unicode码是否在处理范围之内,在则返回该码对映汉字的拼音首字母,不在则调用其它函数处理 - arrResult.push(_checkPYCh(ch)); - } - // 处理arrResult,返回所有可能的拼音首字母串数组 - return _mkPYRslt(arrResult, options); - } - }); -})(); \ No newline at end of file + +export function makeFirstPY(str, options) { + options = options || {}; + if (typeof (str) !== "string") { + return "" + str; + } + var arrResult = []; // 保存中间结果的数组 + for (var i = 0, len = str.length; i < len; i++) { + // 获得unicode码 + var ch = str.charAt(i); + // 检查该unicode码是否在处理范围之内,在则返回该码对映汉字的拼音首字母,不在则调用其它函数处理 + arrResult.push(_checkPYCh(ch)); + } + // 处理arrResult,返回所有可能的拼音首字母串数组 + return _mkPYRslt(arrResult, options); +} + +Object.assign(BI, { + makeFirstPY +}); From 8ed5aaf502855bc4566b382896b7379480bcc2e7 Mon Sep 17 00:00:00 2001 From: zsmj Date: Wed, 4 Jan 2023 10:53:19 +0800 Subject: [PATCH 4/7] =?UTF-8?q?KERNEL-13991=20feat:=20core/func=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/func/alias.js | 171 +++++++++++++++++++------------------- src/core/func/date.js | 84 +++++++++---------- src/core/func/function.js | 36 ++++---- src/core/func/number.js | 34 ++++---- src/core/func/string.js | 14 ++-- 5 files changed, 171 insertions(+), 168 deletions(-) diff --git a/src/core/func/alias.js b/src/core/func/alias.js index f7ba2f324..7de1e9f60 100644 --- a/src/core/func/alias.js +++ b/src/core/func/alias.js @@ -2,7 +2,7 @@ import {each, isFunction, isNull, isObject, isPlainObject, keys, leftPad, parseD import {replaceAll} from "./string"; import {getFullDayName, getMonthName, getTimezone} from "./date"; -var _global; +let _global; if (typeof window !== "undefined") { _global = window; } else if (typeof global !== "undefined") { @@ -47,12 +47,12 @@ function _eFormat(text, fmt) { * @returns {*} */ function eFormat(num, format) { - var neg = num < 0 ? (num *= -1, "-") : "", + let neg = num < 0 ? (num *= -1, "-") : "", magnitudeNeg = ""; - var funcName = num > 0 && num < 1 ? "floor" : "ceil"; // -0.9999->-1 + const funcName = num > 0 && num < 1 ? "floor" : "ceil"; // -0.9999->-1 // 数量级 - var magnitude = Math[funcName](Math.log(num) / Math.log(10)); + let magnitude = Math[funcName](Math.log(num) / Math.log(10)); if (!isFinite(magnitude)) { return format.replace(/#/ig, "").replace(/\.e/ig, "E"); @@ -67,15 +67,15 @@ function _eFormat(text, fmt) { } // 计算出format中需要显示的整数部分的位数,然后更新这个数值,也更新数量级 - var integerLen = getInteger(magnitude, format); + const integerLen = getInteger(magnitude, format); integerLen > 1 && (magnitude -= integerLen - 1, num *= Math.pow(10, integerLen - 1)); magnitude < 0 && (magnitudeNeg = "-", magnitude *= -1); // 获取科学计数法精确到的位数 - var precision = getPrecision(format); + const precision = getPrecision(format); // 判断num经过四舍五入之后是否有进位 - var isValueCarry = isValueCarried(num); + const isValueCarry = isValueCarried(num); num *= Math.pow(10, precision); num = Math.round(num); @@ -104,8 +104,8 @@ function _eFormat(text, fmt) { } // 如果magnitudeNeg是一个"-",而且num正好全是0,那么就别显示负号了 - var isAllZero = true; - for (var i = 0, len = num.length; i < len; i++) { + let isAllZero = true; + for (let i = 0, len = num.length; i < len; i++) { if (!isAllZero) { continue; } @@ -121,7 +121,7 @@ function _eFormat(text, fmt) { if (!/e/ig.test(format)) { return 0; } - var arr = format.split(/e/ig)[0].split("."); + const arr = format.split(/e/ig)[0].split("."); return arr.length > 1 ? arr[1].length : 0; } @@ -134,8 +134,8 @@ function _eFormat(text, fmt) { } // return format.split(/e/ig)[0].split(".")[0].length; - var formatLeft = format.split(/e/ig)[0].split(".")[0], i, f, len = formatLeft.length; - var valueLeftLen = 0; + let formatLeft = format.split(/e/ig)[0].split(".")[0], i, f, len = formatLeft.length; + let valueLeftLen = 0; for (i = 0; i < len; i++) { f = formatLeft.charAt(i); @@ -150,7 +150,7 @@ function _eFormat(text, fmt) { // 判断num通过round函数之后是否有进位 function isValueCarried(num) { - var roundNum = Math.round(num); + let roundNum = Math.round(num); num = (num + "").split(".")[0]; roundNum = (roundNum + "").split(".")[0]; return num.length !== roundNum.length; @@ -160,13 +160,13 @@ function _eFormat(text, fmt) { //'#.##'之类的格式处理 1.324e-18 这种的科学数字 function _dealNumberPrecision(text, fright) { if (/[eE]/.test(text)) { - var precision = 0, i = 0, ch; + let precision = 0, i = 0, ch; if (/[%‰]$/.test(fright)) { precision = /[%]$/.test(fright) ? 2 : 3; } - for (var len = fright.length; i < len; i++) { + for (let len = fright.length; i < len; i++) { if ((ch = fright.charAt(i)) == "0" || ch == "#") { precision++; } @@ -181,7 +181,7 @@ function _dealNumberPrecision(text, fright) { * 数字格式 */ function _numberFormat(text, format) { - var text = text + ""; + text = text + ""; //在调用数字格式的时候如果text里没有任何数字则不处理 if (!(/[0-9]/.test(text)) || !format) { @@ -189,7 +189,7 @@ function _numberFormat(text, format) { } // 数字格式,区分正负数 - var numMod = format.indexOf(";"); + const numMod = format.indexOf(";"); if (numMod > -1) { if (text >= 0) { return _numberFormat(text + "", format.substring(0, numMod)); @@ -203,19 +203,19 @@ function _numberFormat(text, format) { } } - var fp = format.split("."), fleft = fp[0] || "", fright = fp[1] || ""; + const fp = format.split("."), fleft = fp[0] || "", fright = fp[1] || ""; text = _dealNumberPrecision(text, fright); - var tp = text.split("."), tleft = tp[0] || "", tright = tp[1] || ""; + let tp = text.split("."), tleft = tp[0] || "", tright = tp[1] || ""; // 百分比,千分比的小数点移位处理 if (/[%‰]$/.test(format)) { - var paddingZero = /[%]$/.test(format) ? "00" : "000"; + let paddingZero = /[%]$/.test(format) ? "00" : "000"; tright += paddingZero; tleft += tright.substring(0, paddingZero.length); tleft = tleft.replace(/^0+/gi, ""); tright = tright.substring(paddingZero.length).replace(/0+$/gi, ""); } - var right = _dealWithRight(tright, fright); + let right = _dealWithRight(tright, fright); if (right.leftPlus) { // 小数点后有进位 tleft = parseInt(tleft) + 1 + ""; @@ -223,7 +223,7 @@ function _numberFormat(text, format) { tleft = isNaN(tleft) ? "1" : tleft; } right = right.num; - var left = _dealWithLeft(tleft, fleft); + let left = _dealWithLeft(tleft, fleft); if (!(/[0-9]/.test(left))) { left = left + "0"; } @@ -242,10 +242,10 @@ function _numberFormat(text, format) { * @private */ function _dealWithRight(tright, fright) { - var right = "", j = 0, i = 0; - for (var len = fright.length; i < len; i++) { - var ch = fright.charAt(i); - var c = tright.charAt(j); + let right = "", j = 0, i = 0; + for (let len = fright.length; i < len; i++) { + const ch = fright.charAt(i); + let c = tright.charAt(j); switch (ch) { case "0": if (isEmpty(c)) { @@ -263,16 +263,16 @@ function _dealWithRight(tright, fright) { break; } } - var rll = tright.substring(j); - var result = {}; + const rll = tright.substring(j); + const result = {}; if (!isEmpty(rll) && rll.charAt(0) > 4) { // 有多余字符,需要四舍五入 result.leftPlus = true; - var numReg = right.match(/^[0-9]+/); + const numReg = right.match(/^[0-9]+/); if (numReg) { - var num = numReg[0]; - var orilen = num.length; - var newnum = parseInt(num) + 1 + ""; + const num = numReg[0]; + const orilen = num.length; + let newnum = parseInt(num) + 1 + ""; // 进位到整数部分 if (newnum.length > orilen) { newnum = newnum.substring(1); @@ -295,13 +295,14 @@ function _dealWithRight(tright, fright) { * @private */ function _dealWithLeft(tleft, fleft) { - var left = ""; - var j = tleft.length - 1; - var combo = -1, last = -1; - var i = fleft.length - 1; + let newstr; + let left = ""; + let j = tleft.length - 1; + let combo = -1, last = -1; + let i = fleft.length - 1; for (; i >= 0; i--) { - var ch = fleft.charAt(i); - var c = tleft.charAt(j); + const ch = fleft.charAt(i); + let c = tleft.charAt(j); switch (ch) { case "0": if (isEmpty(c)) { @@ -319,7 +320,7 @@ function _dealWithLeft(tleft, fleft) { case ",": if (!isEmpty(c)) { // 计算一个,分隔区间的长度 - var com = fleft.match(/,[#0]+/); + const com = fleft.match(/,[#0]+/); if (com) { combo = com[0].length - 1; } @@ -333,19 +334,20 @@ function _dealWithLeft(tleft, fleft) { } if (last > -1) { // 处理剩余字符 - var tll = tleft.substring(0, j + 1); + const tll = tleft.substring(0, j + 1); left = left.substring(0, last) + tll + left.substring(last); } if (combo > 0) { // 处理,分隔区间 - var res = left.match(/[0-9]+,/); + let res = left.match(/[0-9]+,/); if (res) { res = res[0]; - var newstr = "", n = res.length - 1 - combo; + newstr = ""; + let n = res.length - 1 - combo; for (; n >= 0; n = n - combo) { newstr = res.substring(n, combo) + "," + newstr; } - var lres = res.substring(0, n + combo); + const lres = res.substring(0, n + combo); if (!isEmpty(lres)) { newstr = lres + "," + newstr; } @@ -361,9 +363,9 @@ export const cjkEncode = function (text) { return text; } - var newText = ""; - for (var i = 0; i < text.length; i++) { - var code = text.charCodeAt(i); + let newText = ""; + for (let i = 0; i < text.length; i++) { + const code = text.charCodeAt(i); if (code >= 128 || code === 91 || code === 93) {// 91 is "[", 93 is "]". newText += "[" + code.toString(16) + "]"; } else { @@ -386,17 +388,17 @@ export const cjkDecode = function (text) { return ""; } // 查找没有 "[", 直接返回. kunsnat:数字的时候, 不支持indexOf方法, 也是直接返回. - if (!isNaN(text) || text.indexOf("[") == -1) { + if (!isNaN(text) || text.indexOf("[") === -1) { return text; } - var newText = ""; - for (var i = 0; i < text.length; i++) { - var ch = text.charAt(i); - if (ch == "[") { - var rightIdx = text.indexOf("]", i + 1); + let newText = ""; + for (let i = 0; i < text.length; i++) { + let ch = text.charAt(i); + if (ch === "[") { + const rightIdx = text.indexOf("]", i + 1); if (rightIdx > i + 1) { - var subText = text.substring(i + 1, rightIdx); + let subText = text.substring(i + 1, rightIdx); // james:主要是考虑[CDATA[]]这样的值的出现 if (subText.length > 0) { ch = String.fromCharCode(eval("0x" + subText)); @@ -419,7 +421,7 @@ const SPECIAL_TAGS = { "<": "<", ">": ">", "\x20": " ", - "\n": " " + "\n": " ", }; export const htmlEncode = function (text) { return isNull(text) ? "" : replaceAll(text + "", keys(SPECIAL_TAGS).join("|"), function (v) { @@ -450,7 +452,7 @@ export const htmlDecode = function (text) { export const cjkEncodeDO = function (o) { if (isPlainObject(o)) { - var result = {}; + let result = {}; each(o, function (v, k) { if (!(typeof v === "string")) { v = jsonEncode(v); @@ -466,25 +468,25 @@ export const cjkEncodeDO = function (o) { export const jsonEncode = function (o) { // james:这个Encode是抄的EXT的 - var useHasOwn = !!{}.hasOwnProperty; + let useHasOwn = !!{}.hasOwnProperty; // crashes Safari in some instances // var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/; - var m = { + let m = { "\b": "\\b", "\t": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", "\"": "\\\"", - "\\": "\\\\" + "\\": "\\\\", }; - var encodeString = function (s) { + let encodeString = function (s) { if (/["\\\x00-\x1f]/.test(s)) { return "\"" + s.replace(/([\x00-\x1f\\"])/g, function (a, b) { - var c = m[b]; + let c = m[b]; if (c) { return c; } @@ -497,8 +499,8 @@ export const jsonEncode = function (o) { return "\"" + s + "\""; }; - var encodeArray = function (o) { - var a = ["["], b, i, l = o.length, v; + let encodeArray = function (o) { + let a = ["["], b, i, l = o.length, v; for (i = 0; i < l; i += 1) { v = o[i]; switch (typeof v) { @@ -528,7 +530,7 @@ export const jsonEncode = function (o) { * 现在这么处理就可以decode了,但是JS.jsonDecode和Java.JSONObject也要跟着改一下 */ return jsonEncode({ - __time__: o.getTime() + __time__: o.getTime(), }); } else if (typeof o === "string") { return encodeString(o); @@ -539,7 +541,7 @@ export const jsonEncode = function (o) { } else if (isFunction(o)) { return String(o); } - var a = ["{"], b, i, v; + let a = ["{"], b, i, v; for (i in o) { if (!useHasOwn || o.hasOwnProperty(i)) { v = o[i]; @@ -564,8 +566,9 @@ export const jsonEncode = function (o) { export const jsonDecode = function (text) { + let jo; try { - var jo = JSON.parse(text); + jo = JSON.parse(text); if (jo == null) { jo = {}; } @@ -601,8 +604,8 @@ export const jsonDecode = function (text) { if (o && o.__time__ != null) { return new Date(o.__time__); } - for (var a in o) { - if (o[a] == o || typeof o[a] === "object" || isFunction(o[a])) { + for (const a in o) { + if (o[a] === o || typeof o[a] === "object" || isFunction(o[a])) { break; } o[a] = parse(o[a]); @@ -641,7 +644,7 @@ export const encodeURIComponent = function (url) { }; export const decodeURIComponent = function (url) { - var reserveSpecialCharsMap = {}; + const reserveSpecialCharsMap = {}; each(BI.specialCharsMap, function (initialChar, encodeChar) { reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; }); @@ -657,7 +660,7 @@ export const contentFormat = function (cv, fmt) { // 原值为空,返回空字符 return ""; } - var text = cv.toString(); + let text = cv.toString(); if (isEmpty(fmt)) { // 格式为空,返回原字符 return text; @@ -677,7 +680,7 @@ export const contentFormat = function (cv, fmt) { } } if (!isInvalidDate(cv) && !isNull(cv)) { - var needTrim = fmt.match(/^DT/); + const needTrim = fmt.match(/^DT/); text = date2Str(cv, fmt.substring(needTrim ? 2 : 1)); } } else if (fmt.match(/E/)) { @@ -749,7 +752,7 @@ export const str2Date = function (str, format) { if (typeof str != "string" || typeof format != "string") { return null; } - var fmt = parseFmt(format); + const fmt = parseFmt(format); return parseDateTime(str, fmt); }; @@ -767,16 +770,16 @@ export const date2Str = function (date, format) { return ""; } // O(len(format)) - var len = format.length, result = ""; + let len = format.length, result = ""; if (len > 0) { - var flagch = format.charAt(0), start = 0, str = flagch; - for (var i = 1; i < len; i++) { - var ch = format.charAt(i); + let flagch = format.charAt(0), start = 0, str = flagch; + for (let i = 1; i < len; i++) { + const ch = format.charAt(i); if (flagch !== ch) { result += compileJFmt({ char: flagch, str: str, - len: i - start + len: i - start, }, date); flagch = ch; start = i; @@ -788,13 +791,13 @@ export const date2Str = function (date, format) { result += compileJFmt({ char: flagch, str: str, - len: len - start + len: len - start, }, date); } return result; function compileJFmt(jfmt, date) { - var str = jfmt.str, len = jfmt.len, ch = jfmt["char"]; + let str = jfmt.str, len = jfmt.len, ch = jfmt["char"]; switch (ch) { case "E": // 星期 str = getFullDayName(date.getDay()); @@ -823,7 +826,7 @@ export const date2Str = function (date, format) { } break; case "h": // 时(12) - var hour = date.getHours() % 12; + let hour = date.getHours() % 12; if (hour === 0) { hour = 12; } @@ -875,7 +878,7 @@ export const object2Number = function (value) { if (typeof value === "number") { return value; } - var str = value + ""; + const str = value + ""; if (str.indexOf(".") === -1) { return parseInt(str); } @@ -891,9 +894,9 @@ export const object2Date = function (obj) { } else if (typeof obj === "number") { return new Date(obj); } - var str = obj + ""; + let str = obj + ""; str = str.replace(/-/g, "/"); - var dt = new Date(str); + const dt = new Date(str); if (!isInvalidDate(dt)) { return dt; } @@ -909,9 +912,9 @@ export const object2Time = function (obj) { if (obj instanceof Date) { return obj; } - var str = obj + ""; + let str = obj + ""; str = str.replace(/-/g, "/"); - var dt = new Date(str); + let dt = new Date(str); if (!isInvalidDate(dt)) { return dt; } diff --git a/src/core/func/date.js b/src/core/func/date.js index 0d6ea79d3..8ef71e9e7 100644 --- a/src/core/func/date.js +++ b/src/core/func/date.js @@ -48,7 +48,7 @@ export function getTimezone(date) { * Returns the number of days in the current month */ export function getMonthDays(date, month = date.getMonth()) { - var year = date.getFullYear(); + const year = date.getFullYear(); if (((0 === (year % 4)) && ((0 !== (year % 100)) || (0 === (year % 400)))) && month === 1) { return 29; } @@ -77,9 +77,9 @@ export function getLastDateOfMonth(date) { * @returns {number} */ export function getDayOfYear(date) { - var now = getDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); - var then = getDate(date.getFullYear(), 0, 0, 0, 0, 0); - var time = now - then; + const now = getDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); + const then = getDate(date.getFullYear(), 0, 0, 0, 0, 0); + const time = now - then; return Math.floor(time / DAY); } @@ -90,16 +90,16 @@ export function getDayOfYear(date) { * @returns {number} */ export function getWeekNumber(date) { - var d = getDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); - var week = d.getDay(); - var startOfWeek = BI.StartOfWeek % 7; - var middleDay = (startOfWeek + 3) % 7; + const d = getDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); + const week = d.getDay(); + const startOfWeek = BI.StartOfWeek % 7; + let middleDay = (startOfWeek + 3) % 7; middleDay = middleDay || 7; // 偏移到周周首之前需要多少天 - var offsetWeekStartCount = week < startOfWeek ? (7 + week - startOfWeek) : (week - startOfWeek); - var offsetWeekMiddleCount = middleDay < startOfWeek ? (7 + middleDay - startOfWeek) : (middleDay - startOfWeek); + const offsetWeekStartCount = week < startOfWeek ? (7 + week - startOfWeek) : (week - startOfWeek); + const offsetWeekMiddleCount = middleDay < startOfWeek ? (7 + middleDay - startOfWeek) : (middleDay - startOfWeek); d.setDate(d.getDate() - offsetWeekStartCount + offsetWeekMiddleCount); - var ms = d.valueOf(); + const ms = d.valueOf(); d.setMonth(0); d.setDate(1); return Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1; @@ -120,9 +120,9 @@ export function getOffsetDate(date, offset) { } export function getOffsetQuarter(date, n) { - var dt = getDate(getTime(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds())); - var day = dt.getDate(); - var monthDay = BI.getMonthDays(getDate(dt.getFullYear(), dt.getMonth() + parseInt(n, 10) * 3, 1)); + const dt = getDate(getTime(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds())); + let day = dt.getDate(); + const monthDay = BI.getMonthDays(getDate(dt.getFullYear(), dt.getMonth() + parseInt(n, 10) * 3, 1)); if (day > monthDay) { day = monthDay; } @@ -137,8 +137,8 @@ export function getOffsetQuarter(date, n) { * @returns {number} */ export function getQuarterStartMonth(date) { - var quarterStartMonth = 0; - var nowMonth = date.getMonth(); + let quarterStartMonth = 0; + const nowMonth = date.getMonth(); if (nowMonth < 3) { quarterStartMonth = 0; } @@ -169,7 +169,7 @@ export function getQuarterStartDate(date) { * @returns {Date} */ export function getQuarterEndDate(date) { - var quarterEndMonth = getQuarterStartMonth(date) + 2; + const quarterEndMonth = getQuarterStartMonth(date) + 2; return getDate(date.getFullYear(), quarterEndMonth, getMonthDays(date)); } @@ -180,9 +180,9 @@ export function getQuarterEndDate(date) { * @returns {Date} */ export function getOffsetMonth(date, n) { - var dt = getDate(getTime(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds())); - var day = dt.getDate(); - var monthDay = getMonthDays(getDate(dt.getFullYear(), dt.getMonth() + parseInt(n, 10), 1)); + const dt = getDate(getTime(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds())); + let day = dt.getDate(); + const monthDay = getMonthDays(getDate(dt.getFullYear(), dt.getMonth() + parseInt(n, 10), 1)); if (day > monthDay) { day = monthDay; } @@ -197,8 +197,8 @@ export function getOffsetMonth(date, n) { * @returns {Date} */ export function getWeekStartDate(date) { - var w = date.getDay(); - var startOfWeek = BI.StartOfWeek % 7; + const w = date.getDay(); + const startOfWeek = BI.StartOfWeek % 7; return getOffsetDate(date, _OFFSET[w < startOfWeek ? (7 + w - startOfWeek) : (w - startOfWeek)]); } @@ -208,8 +208,8 @@ export function getWeekStartDate(date) { * @returns {Date} */ export function getWeekEndDate(date) { - var w = date.getDay(); - var startOfWeek = BI.StartOfWeek % 7; + const w = date.getDay(); + const startOfWeek = BI.StartOfWeek % 7; return getOffsetDate(date, _OFFSET[w < startOfWeek ? (7 + w - startOfWeek) : (w - startOfWeek)] + 6); } @@ -273,26 +273,26 @@ export function getQuarterName(index) { * @returns {*} */ export function print(date, str) { - var m = date.getMonth(); - var d = date.getDate(); - var y = date.getFullYear(); - var yWith4number = y + ""; + const m = date.getMonth(); + const d = date.getDate(); + const y = date.getFullYear(); + let yWith4number = y + ""; while (yWith4number.length < 4) { yWith4number = "0" + yWith4number; } - var wn = getWeekNumber(date); - var qr = getQuarter(date); - var w = date.getDay(); - var s = {}; - var hr = date.getHours(); - var pm = (hr >= 12); - var ir = (pm) ? (hr - 12) : hr; - var dy = getDayOfYear(date); + const wn = getWeekNumber(date); + const qr = getQuarter(date); + const w = date.getDay(); + const s = {}; + const hr = date.getHours(); + const pm = (hr >= 12); + let ir = (pm) ? (hr - 12) : hr; + const dy = getDayOfYear(date); if (ir === 0) { ir = 12; } - var min = date.getMinutes(); - var sec = date.getSeconds(); + const min = date.getMinutes(); + const sec = date.getSeconds(); s["%a"] = getShortDayName(w); // abbreviated weekday name [FIXME: I18N] s["%A"] = getFullDayName(w); // full weekday name s["%b"] = _SMN[m]; // abbreviated month name [FIXME: I18N] @@ -331,7 +331,7 @@ export function print(date, str) { s["%q"] = "0" + qr; s["%Q"] = qr; - var re = /%./g; + let re = /%./g; BI.isKhtml = BI.isKhtml || function () { if (!_global.navigator) { return false; @@ -366,9 +366,9 @@ export function print(date, str) { return s[par] || par; }); } - var a = str.match(re); - for (var i = 0; i < a.length; i++) { - var tmp = s[a[i]]; + const a = str.match(re); + for (let i = 0; i < a.length; i++) { + const tmp = s[a[i]]; if (tmp) { re = new RegExp(a[i], "g"); str = str.replace(re, tmp); diff --git a/src/core/func/function.js b/src/core/func/function.js index e66b54453..f8fc3cdca 100644 --- a/src/core/func/function.js +++ b/src/core/func/function.js @@ -12,7 +12,7 @@ import {makeFirstPY} from "../utils/chinesePY"; * @returns {*} */ export function createDistinctName(array, name) { - var src = name, idx = 1; + let src = name, idx = 1; name = name || ""; while (true) { if (every(array, function (i, item) { @@ -43,18 +43,18 @@ export function getGBWidth(str) { * @param param 搜索哪个属性 */ export function getSearchResult(items, keyword, param) { - var array = isArray(items); + let array = isArray(items); items = array ? BI.flatten(items) : items; param || (param = "text"); if (!isKey(keyword)) { return { find: items, - match: array ? [] : {} + match: array ? [] : {}, }; } - var t, text, py; + let t, text, py; keyword = toUpperCase(keyword); - var matched = array ? [] : {}, find = array ? [] : {}; + let matched = array ? [] : {}, find = array ? [] : {}; each(items, function (i, item) { // 兼容item为null的处理 if (isNull(item)) { @@ -66,11 +66,11 @@ export function getSearchResult(items, keyword, param) { if (isNull(text) || isObject(text)) return; py = makeFirstPY(text, { - splitChar: "\u200b" + splitChar: "\u200b", }); text = toUpperCase(text); py = toUpperCase(py); - var pidx; + let pidx; if (text.indexOf(keyword) > -1) { if (text === keyword) { array ? matched.push(item) : (matched[i] = item); @@ -90,7 +90,7 @@ export function getSearchResult(items, keyword, param) { }); return { match: matched, - find: find + find: find, }; } @@ -101,7 +101,7 @@ export function getSearchResult(items, keyword, param) { * @return {any[]} */ export function getSortedResult(items, key) { - var getTextOfItem = BI.isFunction(key) ? key : + let getTextOfItem = BI.isFunction(key) ? key : function (item, key) { if (BI.isNotNull(key)) { return item[key]; @@ -116,8 +116,8 @@ export function getSortedResult(items, key) { }; return items.sort(function (item1, item2) { - var str1 = getTextOfItem(item1, key); - var str2 = getTextOfItem(item2, key); + let str1 = getTextOfItem(item1, key); + let str2 = getTextOfItem(item2, key); if (BI.isNull(str1) && BI.isNull(str2)) { return 0; } @@ -130,10 +130,10 @@ export function getSortedResult(items, key) { if (str1 === str2) { return 0; } - var len1 = str1.length, len2 = str2.length; - for (var i = 0; i < len1 && i < len2; i++) { - var char1 = str1[i]; - var char2 = str2[i]; + let len1 = str1.length, len2 = str2.length; + for (let i = 0; i < len1 && i < len2; i++) { + let char1 = str1[i]; + let char2 = str2[i]; if (char1 !== char2) { // 找不到的字符都往后面放 return (BI.isNull(BI.CODE_INDEX[char1]) ? BI.MAX : BI.CODE_INDEX[char1]) - (BI.isNull(BI.CODE_INDEX[char2]) ? BI.MAX : BI.CODE_INDEX[char2]); @@ -144,7 +144,7 @@ export function getSortedResult(items, key) { } export function beforeFunc(sFunc, func) { - var __self = sFunc; + let __self = sFunc; return function () { if (func.apply(sFunc, arguments) === false) { return false; @@ -154,9 +154,9 @@ export function beforeFunc(sFunc, func) { } export function afterFunc(sFunc, func) { - var __self = sFunc; + let __self = sFunc; return function () { - var ret = __self.apply(sFunc, arguments); + let ret = __self.apply(sFunc, arguments); if (ret === false) { return false; } diff --git a/src/core/func/number.js b/src/core/func/number.js index 73f9dbec6..9f9640f66 100644 --- a/src/core/func/number.js +++ b/src/core/func/number.js @@ -9,7 +9,7 @@ export function add(num, arg) { ** 返回值:arg1加上arg2的精确结果 **/ function accAdd(arg1, arg2) { - var r1, r2, m, c; + let r1, r2, m, c; try { r1 = arg1.toString().split(".")[1].length; } catch (e) { @@ -23,7 +23,7 @@ export function add(num, arg) { c = Math.abs(r1 - r2); m = Math.pow(10, Math.max(r1, r2)); if (c > 0) { - var cm = Math.pow(10, c); + let cm = Math.pow(10, c); if (r1 > r2) { arg1 = Number(arg1.toString().replace(".", "")); arg2 = Number(arg2.toString().replace(".", "")) * cm; @@ -50,7 +50,7 @@ export function sub(num, arg) { ** 返回值:arg1加上arg2的精确结果 **/ function accSub(arg1, arg2) { - var r1, r2, m, n; + let r1, r2, m, n; try { r1 = arg1.toString().split(".")[1].length; } catch (e) { @@ -78,7 +78,7 @@ export function mul(num, arg) { ** 返回值:arg1乘以 arg2的精确结果 **/ function accMul(arg1, arg2) { - var m = 0, s1 = arg1.toString(), s2 = arg2.toString(); + let m = 0, s1 = arg1.toString(), s2 = arg2.toString(); try { m += s1.split(".")[1].length; } catch (e) { @@ -101,8 +101,8 @@ export function div(num, arg) { */ function digitLength(num) { // Get digit length of e - var eSplit = num.toString().split(/[eE]/); - var len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0)); + let eSplit = num.toString().split(/[eE]/); + let len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0)); return len > 0 ? len : 0; } @@ -114,7 +114,7 @@ export function div(num, arg) { if (num.toString().indexOf("e") === -1) { return Number(num.toString().replace(".", "")); } - var dLen = digitLength(num); + let dLen = digitLength(num); return dLen > 0 ? num * Math.pow(10, dLen) : num; } @@ -122,17 +122,17 @@ export function div(num, arg) { * 精确乘法 */ function times(num1, num2) { - var others = []; - for (var _i = 2; _i < arguments.length; _i++) { + let others = []; + for (let _i = 2; _i < arguments.length; _i++) { others[_i - 2] = arguments[_i]; } if (others.length > 0) { return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1))); } - var num1Changed = float2Fixed(num1); - var num2Changed = float2Fixed(num2); - var baseNum = digitLength(num1) + digitLength(num2); - var leftValue = num1Changed * num2Changed; + let num1Changed = float2Fixed(num1); + let num2Changed = float2Fixed(num2); + let baseNum = digitLength(num1) + digitLength(num2); + let leftValue = num1Changed * num2Changed; return leftValue / Math.pow(10, baseNum); } @@ -140,15 +140,15 @@ export function div(num, arg) { * 精确除法 */ function accDivide(num1, num2) { - var others = []; - for (var _i = 2; _i < arguments.length; _i++) { + let others = []; + for (let _i = 2; _i < arguments.length; _i++) { others[_i - 2] = arguments[_i]; } if (others.length > 0) { return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1))); } - var num1Changed = float2Fixed(num1); - var num2Changed = float2Fixed(num2); + let num1Changed = float2Fixed(num1); + let num2Changed = float2Fixed(num2); return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1))); } } diff --git a/src/core/func/string.js b/src/core/func/string.js index de5b29628..8b5d5ceba 100644 --- a/src/core/func/string.js +++ b/src/core/func/string.js @@ -11,7 +11,7 @@ export function startWith(str, startTag) { if (startTag == null || startTag == "" || str.length === 0 || startTag.length > str.length) { return false; } - return str.substr(0, startTag.length) == startTag; + return str.substring(0, startTag.length) == startTag; } /** @@ -34,8 +34,8 @@ export function endWith(str, endTag) { * @return {String} 参数的值 */ export function getQuery(str, name) { - var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); - var r = str.substr(str.indexOf("?") + 1).match(reg); + let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); + let r = str.substr(str.indexOf("?") + 1).match(reg); if (r) { return unescape(r[2]); } @@ -52,7 +52,7 @@ export function appendQuery(str, paras) { if (!paras) { return str; } - var src = str; + let src = str; // 没有问号说明还没有参数 if (src.indexOf("?") === -1) { src += "?"; @@ -106,10 +106,10 @@ export function allIndexOf(str, sub) { if (typeof sub !== "string") { return []; } - var location = []; - var offset = 0; + let location = []; + let offset = 0; while (str.length > 0) { - var loc = str.indexOf(sub); + let loc = str.indexOf(sub); if (loc === -1) { break; } From df41ae3b784e874d30427f262365059fb8967581 Mon Sep 17 00:00:00 2001 From: zsmj Date: Wed, 4 Jan 2023 11:21:06 +0800 Subject: [PATCH 5/7] =?UTF-8?q?KERNEL-13991=20feat:=20core/func=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/func/__test__/function.test.js | 6 +++--- src/core/func/alias.js | 14 +++++++------- src/core/func/function.js | 22 +++++++++++----------- src/core/func/index.js | 2 +- src/core/func/number.js | 24 ++++++++++++------------ src/core/func/string.js | 8 ++++---- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/core/func/__test__/function.test.js b/src/core/func/__test__/function.test.js index 388af5fe6..db6901582 100644 --- a/src/core/func/__test__/function.test.js +++ b/src/core/func/__test__/function.test.js @@ -8,7 +8,7 @@ describe("core-function-test", function () { * test_author_lei.wang */ it("createDistinctName-支持字符串数组", function () { - var names = ["name", "name1"]; + const names = ["name", "name1"]; expect(BI.Func.createDistinctName(names, "name")).to.equal("name2"); expect(BI.Func.createDistinctName(names, "name2")).to.equal("name2"); }); @@ -17,8 +17,8 @@ describe("core-function-test", function () { * test_author_lei.wang */ it("createDistinctName-支持对象数组数组", function () { - var names = [{ name: "name" }, { name: "name1" }]; + const names = [{ name: "name" }, { name: "name1" }]; expect(BI.Func.createDistinctName(names, "name")).to.equal("name2"); expect(BI.Func.createDistinctName(names, "name2")).to.equal("name2"); }); -}); \ No newline at end of file +}); diff --git a/src/core/func/alias.js b/src/core/func/alias.js index 7de1e9f60..b8596e7cf 100644 --- a/src/core/func/alias.js +++ b/src/core/func/alias.js @@ -209,7 +209,7 @@ function _numberFormat(text, format) { // 百分比,千分比的小数点移位处理 if (/[%‰]$/.test(format)) { - let paddingZero = /[%]$/.test(format) ? "00" : "000"; + const paddingZero = /[%]$/.test(format) ? "00" : "000"; tright += paddingZero; tleft += tright.substring(0, paddingZero.length); tleft = tleft.replace(/^0+/gi, ""); @@ -398,7 +398,7 @@ export const cjkDecode = function (text) { if (ch === "[") { const rightIdx = text.indexOf("]", i + 1); if (rightIdx > i + 1) { - let subText = text.substring(i + 1, rightIdx); + const subText = text.substring(i + 1, rightIdx); // james:主要是考虑[CDATA[]]这样的值的出现 if (subText.length > 0) { ch = String.fromCharCode(eval("0x" + subText)); @@ -452,7 +452,7 @@ export const htmlDecode = function (text) { export const cjkEncodeDO = function (o) { if (isPlainObject(o)) { - let result = {}; + const result = {}; each(o, function (v, k) { if (!(typeof v === "string")) { v = jsonEncode(v); @@ -468,12 +468,12 @@ export const cjkEncodeDO = function (o) { export const jsonEncode = function (o) { // james:这个Encode是抄的EXT的 - let useHasOwn = !!{}.hasOwnProperty; + const useHasOwn = !!{}.hasOwnProperty; // crashes Safari in some instances // var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/; - let m = { + const m = { "\b": "\\b", "\t": "\\t", "\n": "\\n", @@ -483,7 +483,7 @@ export const jsonEncode = function (o) { "\\": "\\\\", }; - let encodeString = function (s) { + const encodeString = function (s) { if (/["\\\x00-\x1f]/.test(s)) { return "\"" + s.replace(/([\x00-\x1f\\"])/g, function (a, b) { let c = m[b]; @@ -499,7 +499,7 @@ export const jsonEncode = function (o) { return "\"" + s + "\""; }; - let encodeArray = function (o) { + const encodeArray = function (o) { let a = ["["], b, i, l = o.length, v; for (i = 0; i < l; i += 1) { v = o[i]; diff --git a/src/core/func/function.js b/src/core/func/function.js index f8fc3cdca..ecbd78f2d 100644 --- a/src/core/func/function.js +++ b/src/core/func/function.js @@ -43,7 +43,7 @@ export function getGBWidth(str) { * @param param 搜索哪个属性 */ export function getSearchResult(items, keyword, param) { - let array = isArray(items); + const array = isArray(items); items = array ? BI.flatten(items) : items; param || (param = "text"); if (!isKey(keyword)) { @@ -54,7 +54,7 @@ export function getSearchResult(items, keyword, param) { } let t, text, py; keyword = toUpperCase(keyword); - let matched = array ? [] : {}, find = array ? [] : {}; + const matched = array ? [] : {}, find = array ? [] : {}; each(items, function (i, item) { // 兼容item为null的处理 if (isNull(item)) { @@ -101,7 +101,7 @@ export function getSearchResult(items, keyword, param) { * @return {any[]} */ export function getSortedResult(items, key) { - let getTextOfItem = BI.isFunction(key) ? key : + const getTextOfItem = BI.isFunction(key) ? key : function (item, key) { if (BI.isNotNull(key)) { return item[key]; @@ -116,8 +116,8 @@ export function getSortedResult(items, key) { }; return items.sort(function (item1, item2) { - let str1 = getTextOfItem(item1, key); - let str2 = getTextOfItem(item2, key); + const str1 = getTextOfItem(item1, key); + const str2 = getTextOfItem(item2, key); if (BI.isNull(str1) && BI.isNull(str2)) { return 0; } @@ -130,10 +130,10 @@ export function getSortedResult(items, key) { if (str1 === str2) { return 0; } - let len1 = str1.length, len2 = str2.length; + const len1 = str1.length, len2 = str2.length; for (let i = 0; i < len1 && i < len2; i++) { - let char1 = str1[i]; - let char2 = str2[i]; + const char1 = str1[i]; + const char2 = str2[i]; if (char1 !== char2) { // 找不到的字符都往后面放 return (BI.isNull(BI.CODE_INDEX[char1]) ? BI.MAX : BI.CODE_INDEX[char1]) - (BI.isNull(BI.CODE_INDEX[char2]) ? BI.MAX : BI.CODE_INDEX[char2]); @@ -144,7 +144,7 @@ export function getSortedResult(items, key) { } export function beforeFunc(sFunc, func) { - let __self = sFunc; + const __self = sFunc; return function () { if (func.apply(sFunc, arguments) === false) { return false; @@ -154,9 +154,9 @@ export function beforeFunc(sFunc, func) { } export function afterFunc(sFunc, func) { - let __self = sFunc; + const __self = sFunc; return function () { - let ret = __self.apply(sFunc, arguments); + const ret = __self.apply(sFunc, arguments); if (ret === false) { return false; } diff --git a/src/core/func/index.js b/src/core/func/index.js index 3475bf8d6..9b24275bf 100644 --- a/src/core/func/index.js +++ b/src/core/func/index.js @@ -19,5 +19,5 @@ Object.assign(BI, { ..._date, ..._function, ..._number, - ..._string + ..._string, }); diff --git a/src/core/func/number.js b/src/core/func/number.js index 9f9640f66..d7a4f31f5 100644 --- a/src/core/func/number.js +++ b/src/core/func/number.js @@ -23,7 +23,7 @@ export function add(num, arg) { c = Math.abs(r1 - r2); m = Math.pow(10, Math.max(r1, r2)); if (c > 0) { - let cm = Math.pow(10, c); + const cm = Math.pow(10, c); if (r1 > r2) { arg1 = Number(arg1.toString().replace(".", "")); arg2 = Number(arg2.toString().replace(".", "")) * cm; @@ -101,8 +101,8 @@ export function div(num, arg) { */ function digitLength(num) { // Get digit length of e - let eSplit = num.toString().split(/[eE]/); - let len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0)); + const eSplit = num.toString().split(/[eE]/); + const len = (eSplit[0].split(".")[1] || "").length - (+(eSplit[1] || 0)); return len > 0 ? len : 0; } @@ -114,7 +114,7 @@ export function div(num, arg) { if (num.toString().indexOf("e") === -1) { return Number(num.toString().replace(".", "")); } - let dLen = digitLength(num); + const dLen = digitLength(num); return dLen > 0 ? num * Math.pow(10, dLen) : num; } @@ -122,17 +122,17 @@ export function div(num, arg) { * 精确乘法 */ function times(num1, num2) { - let others = []; + const others = []; for (let _i = 2; _i < arguments.length; _i++) { others[_i - 2] = arguments[_i]; } if (others.length > 0) { return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1))); } - let num1Changed = float2Fixed(num1); - let num2Changed = float2Fixed(num2); - let baseNum = digitLength(num1) + digitLength(num2); - let leftValue = num1Changed * num2Changed; + const num1Changed = float2Fixed(num1); + const num2Changed = float2Fixed(num2); + const baseNum = digitLength(num1) + digitLength(num2); + const leftValue = num1Changed * num2Changed; return leftValue / Math.pow(10, baseNum); } @@ -140,15 +140,15 @@ export function div(num, arg) { * 精确除法 */ function accDivide(num1, num2) { - let others = []; + const others = []; for (let _i = 2; _i < arguments.length; _i++) { others[_i - 2] = arguments[_i]; } if (others.length > 0) { return accDivide.apply(void 0, [accDivide(num1, num2), others[0]].concat(others.slice(1))); } - let num1Changed = float2Fixed(num1); - let num2Changed = float2Fixed(num2); + const num1Changed = float2Fixed(num1); + const num2Changed = float2Fixed(num2); return times((num1Changed / num2Changed), Math.pow(10, digitLength(num2) - digitLength(num1))); } } diff --git a/src/core/func/string.js b/src/core/func/string.js index 8b5d5ceba..d273db525 100644 --- a/src/core/func/string.js +++ b/src/core/func/string.js @@ -34,8 +34,8 @@ export function endWith(str, endTag) { * @return {String} 参数的值 */ export function getQuery(str, name) { - let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); - let r = str.substr(str.indexOf("?") + 1).match(reg); + const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); + const r = str.substr(str.indexOf("?") + 1).match(reg); if (r) { return unescape(r[2]); } @@ -106,10 +106,10 @@ export function allIndexOf(str, sub) { if (typeof sub !== "string") { return []; } - let location = []; + const location = []; let offset = 0; while (str.length > 0) { - let loc = str.indexOf(sub); + const loc = str.indexOf(sub); if (loc === -1) { break; } From c645f52ac8e54668cb6a5d1c074d2f128275fbc4 Mon Sep 17 00:00:00 2001 From: "Zhenfei.Li" Date: Wed, 4 Jan 2023 14:02:18 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20chore:=20?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=95=B4=E7=90=86=E4=B8=80=E4=B8=8Bimport?= =?UTF-8?q?=E5=92=8Cexport=E5=92=8C=E6=8C=82=E8=BD=BD=E5=88=B0BI=E7=9A=84?= =?UTF-8?q?=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/0.base.js | 13 --- src/base/1.pane.js | 2 +- src/base/combination/bubble.js | 2 +- src/base/combination/combo.js | 4 +- src/base/combination/expander.js | 2 +- src/base/combination/group.button.js | 2 +- src/base/combination/group.combo.js | 2 +- src/base/combination/group.virtual.js | 2 +- src/base/combination/index.js | 12 ++ src/base/combination/loader.js | 2 +- src/base/combination/navigation.js | 2 +- src/base/combination/searcher.js | 4 +- src/base/combination/switcher.js | 2 +- src/base/combination/tab.js | 2 +- src/base/combination/tree.button.js | 4 +- src/base/foundation/message.js | 54 ++++----- src/base/index.js | 98 +++------------- src/base/layer/index.js | 4 + src/base/layer/layer.drawer.js | 2 +- src/base/layer/layer.popup.js | 2 +- src/base/layer/layer.searcher.js | 4 +- src/base/list/index.js | 3 + src/base/list/listview.js | 2 +- src/base/list/virtualgrouplist.js | 2 +- src/base/list/virtuallist.js | 2 +- src/base/single/0.single.js | 2 +- src/base/single/1.text.js | 6 +- src/base/single/a/a.js | 4 +- src/base/single/index.js | 4 + src/base/single/tip/0.tip.js | 4 +- src/base/single/tip/index.js | 3 + src/base/single/tip/tip.toast.js | 4 +- src/base/single/tip/tip.tooltip.js | 4 +- src/core/2.base.js | 121 -------------------- src/core/3.ob.js | 6 +- src/core/4.widget.js | 16 +-- src/core/5.inject.js | 26 +---- src/core/action/action.js | 4 +- src/core/action/action.show.js | 4 +- src/core/action/index.js | 2 + src/core/behavior/0.behavior.js | 4 +- src/core/behavior/behavior.highlight.js | 4 +- src/core/behavior/behavior.redmark.js | 4 +- src/core/behavior/index.js | 3 + src/core/controller/0.controller.js | 4 +- src/core/controller/controller.broadcast.js | 4 +- src/core/controller/controller.bubbles.js | 4 +- src/core/controller/controller.drawer.js | 4 +- src/core/controller/controller.layer.js | 4 +- src/core/controller/controller.masker.js | 4 +- src/core/controller/controller.popover.js | 4 +- src/core/controller/controller.resizer.js | 4 +- src/core/controller/controller.tooltips.js | 4 +- src/core/controller/index.js | 9 ++ src/core/index.js | 89 +++++--------- src/core/listener/listener.show.js | 6 +- src/core/loader/loader.style.js | 4 +- 57 files changed, 190 insertions(+), 409 deletions(-) create mode 100644 src/base/combination/index.js create mode 100644 src/base/layer/index.js create mode 100644 src/base/list/index.js create mode 100644 src/base/single/index.js create mode 100644 src/base/single/tip/index.js create mode 100644 src/core/action/index.js create mode 100644 src/core/behavior/index.js create mode 100644 src/core/controller/index.js diff --git a/src/base/0.base.js b/src/base/0.base.js index 2b4960808..e4daef1cf 100644 --- a/src/base/0.base.js +++ b/src/base/0.base.js @@ -8,7 +8,6 @@ import { ResizeController, TooltipsController, StyleLoaderManager, - extend } from "../core"; const Resizers = new ResizeController(); @@ -21,18 +20,6 @@ const Drawers = new DrawerController(); const Broadcasts = new BroadcastController(); const StyleLoaders = new StyleLoaderManager(); -extend(BI, { - Resizers, - Layers, - Maskers, - Bubbles, - Tooltips, - Popovers, - Drawers, - Broadcasts, - StyleLoaders -}); - export { Resizers, Layers, diff --git a/src/base/1.pane.js b/src/base/1.pane.js index 51ceecfce..ebbaac636 100644 --- a/src/base/1.pane.js +++ b/src/base/1.pane.js @@ -10,7 +10,7 @@ import { Widget, shortcut, isNotEmptyString, extend, isNull, isEmpty, createWidg import { Layers } from "./0.base"; @shortcut() -export default class Pane extends Widget { +export class Pane extends Widget { static xtype = "bi.pane"; static EVENT_LOADED = "EVENT_LOADED"; static EVENT_LOADING = "EVENT_LOADING"; diff --git a/src/base/combination/bubble.js b/src/base/combination/bubble.js index 5d9e9e86a..49bc6d176 100644 --- a/src/base/combination/bubble.js +++ b/src/base/combination/bubble.js @@ -5,7 +5,7 @@ import { shortcut, Widget, Controller, extend, nextTick, createWidget, each, defer, debounce, delay, isNull, isFunction, contains, bind } from "../../core"; @shortcut() -export default class Bubble extends Widget { +export class Bubble extends Widget { static xtype = "bi.bubble"; static EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; diff --git a/src/base/combination/combo.js b/src/base/combination/combo.js index 277e9e224..6f16862e2 100644 --- a/src/base/combination/combo.js +++ b/src/base/combination/combo.js @@ -4,14 +4,14 @@ */ import { shortcut, Widget, Controller, extend, createWidget, nextTick, bind, isNotNull, isNull, isFunction, each } from "../../core"; -import Bubble from "./bubble"; +import { Bubble } from "./bubble"; import { Resizers } from "../0.base"; let needHideWhenAnotherComboOpen = {}; let currentOpenedCombos = {}; @shortcut() -export default class Combo extends Bubble { +export class Combo extends Bubble { static xtype = "bi.combo"; static EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; diff --git a/src/base/combination/expander.js b/src/base/combination/expander.js index 3c7e9f8cb..fe04aec7a 100644 --- a/src/base/combination/expander.js +++ b/src/base/combination/expander.js @@ -9,7 +9,7 @@ import { shortcut, Widget, Controller, extend, nextTick, each, debounce, isNull, createWidget } from "../../core"; @shortcut() -export default class Expander extends Widget { +export class Expander extends Widget { static xtype = "bi.expander"; static EVENT_EXPAND = "EVENT_EXPAND"; diff --git a/src/base/combination/group.button.js b/src/base/combination/group.button.js index 22c110720..57c2e47e2 100644 --- a/src/base/combination/group.button.js +++ b/src/base/combination/group.button.js @@ -6,7 +6,7 @@ import { shortcut, Widget, Controller, extend, createWidget, createWidgets, each, isFunction, isKey, isNotEmptyArray, createItems, isArray, remove, map, stripEL, makeArrayByArray, clone, deepClone, formatEL, isEmpty, concat, removeAt, deepContains, has, any } from "../../core"; @shortcut() -export default class ButtonGroup extends Widget { +export class ButtonGroup extends Widget { static xtype = "bi.button_group"; static EVENT_CHANGE = "EVENT_CHANGE"; diff --git a/src/base/combination/group.combo.js b/src/base/combination/group.combo.js index 97882f40f..e2c0d1f6f 100644 --- a/src/base/combination/group.combo.js +++ b/src/base/combination/group.combo.js @@ -5,7 +5,7 @@ import { shortcut, Widget, Controller, extend, isEmpty, each, formatEL, clone, createWidget } from "../../core"; @shortcut() -export default class ComboGroup extends Widget { +export class ComboGroup extends Widget { static xtype = "bi.combo_group"; static EVENT_CHANGE = "EVENT_CHANGE"; diff --git a/src/base/combination/group.virtual.js b/src/base/combination/group.virtual.js index f757c4b4e..a9f069ea7 100644 --- a/src/base/combination/group.virtual.js +++ b/src/base/combination/group.virtual.js @@ -1,7 +1,7 @@ import { shortcut, Widget, Controller, extend, isFunction, isKey, isArray, map, stripEL, deepClone, formatEL, isEmpty, each, createWidget } from "../../core"; @shortcut() -export default class VirtualGroup extends Widget { +export class VirtualGroup extends Widget { static xtype = "bi.virtual_group"; static EVENT_CHANGE = "EVENT_CHANGE"; diff --git a/src/base/combination/index.js b/src/base/combination/index.js new file mode 100644 index 000000000..0a3b52bd1 --- /dev/null +++ b/src/base/combination/index.js @@ -0,0 +1,12 @@ +export { Bubble } from "./bubble"; +export { Combo } from "./combo"; +export { Expander } from "./expander"; +export { ButtonGroup } from "./group.button"; +export { ComboGroup } from "./group.combo"; +export { VirtualGroup } from "./group.virtual"; +export { Loader } from "./loader"; +export { Navigation } from "./navigation"; +export { Searcher } from "./searcher"; +export { Switcher } from "./switcher"; +export { Tab } from "./tab"; +export { ButtonTree } from "./tree.button"; \ No newline at end of file diff --git a/src/base/combination/loader.js b/src/base/combination/loader.js index 0ebf26770..744f2bb12 100644 --- a/src/base/combination/loader.js +++ b/src/base/combination/loader.js @@ -8,7 +8,7 @@ import { shortcut, Widget, Controller, extend, createWidget, isEmpty, nextTick, bind, isFunction, isNotEmptyArray, isNumber, isObject, each } from "../../core"; @shortcut() -export default class Loader extends Widget { +export class Loader extends Widget { static xtype = "bi.loader"; static EVENT_CHANGE = "EVENT_CHANGE"; diff --git a/src/base/combination/navigation.js b/src/base/combination/navigation.js index febb44958..671459d5c 100644 --- a/src/base/combination/navigation.js +++ b/src/base/combination/navigation.js @@ -4,7 +4,7 @@ import { shortcut, Widget, Controller, extend, createWidget, bind, ShowListener, isFunction, each, nextTick, isKey, values } from "../../core"; @shortcut() -export default class Navigation extends Widget { +export class Navigation extends Widget { static xtype = "bi.navigation"; static EVENT_CHANGE = "EVENT_CHANGE"; diff --git a/src/base/combination/searcher.js b/src/base/combination/searcher.js index 56b03f720..acf316e76 100644 --- a/src/base/combination/searcher.js +++ b/src/base/combination/searcher.js @@ -6,11 +6,11 @@ * @extends BI.Widget */ import { shortcut, Widget, Controller, extend, createWidget, debounce, bind, endWith, deepWithout, nextTick, isEmptyString, isNull } from "../../core"; -import ButtonGroup from "./group.button"; +import { ButtonGroup } from "./group.button"; import { Maskers } from "../0.base"; @shortcut() -export default class Searcher extends Widget { +export class Searcher extends Widget { static xtype = "bi.searcher"; static EVENT_CHANGE = "EVENT_CHANGE"; diff --git a/src/base/combination/switcher.js b/src/base/combination/switcher.js index e89b31314..b19f75404 100644 --- a/src/base/combination/switcher.js +++ b/src/base/combination/switcher.js @@ -10,7 +10,7 @@ import { shortcut, Widget, Controller, extend, nextTick, createWidget, each, deb import { Maskers } from "../0.base"; @shortcut() -export default class Switcher extends Widget { +export class Switcher extends Widget { static xtype = "bi.switcher"; static EVENT_EXPAND = "EVENT_EXPAND"; diff --git a/src/base/combination/tab.js b/src/base/combination/tab.js index 7fcce06c4..f7a7e2038 100644 --- a/src/base/combination/tab.js +++ b/src/base/combination/tab.js @@ -4,7 +4,7 @@ import { shortcut, Widget, Controller, ShowListener, extend, createWidget, isObject, each, isFunction, contains, any, isEqual } from "../../core"; @shortcut() -export default class Tab extends Widget { +export class Tab extends Widget { static xtype = "bi.tab"; static EVENT_CHANGE = "EVENT_CHANGE"; diff --git a/src/base/combination/tree.button.js b/src/base/combination/tree.button.js index 6ed1a1b3f..be25898f9 100644 --- a/src/base/combination/tree.button.js +++ b/src/base/combination/tree.button.js @@ -4,10 +4,10 @@ * @extends BI.ButtonGroup */ import { shortcut, Widget, extend, isArray, each, isFunction, deepContains, concat, any, contains } from "../../core"; -import ButtonGroup from "./group.button"; +import { ButtonGroup } from "./group.button"; @shortcut() -export default class ButtonTree extends ButtonGroup { +export class ButtonTree extends ButtonGroup { static xtype = "bi.button_tree"; static EVENT_CHANGE = "EVENT_CHANGE"; diff --git a/src/base/foundation/message.js b/src/base/foundation/message.js index 380e12039..add1060ba 100644 --- a/src/base/foundation/message.js +++ b/src/base/foundation/message.js @@ -3,12 +3,14 @@ * 弹出提示消息框,用于模拟阻塞操作(通过回调函数实现) * @class BI.Msg */ -BI.Msg = ((function () { - var $mask, $pop; +import { Widget, isString, isNull, isFunction, createWidget, remove, each } from "../../core" - var messageShows = []; +export const Msg = ((() => { + let $mask, $pop; - var toastStack = []; + let messageShows = []; + + let toastStack = []; return { alert: function (title, message, callback) { @@ -21,13 +23,13 @@ BI.Msg = ((function () { // BI.Msg.prompt(title, message, value, callback, min_width); }, toast: function (message, options, context) { - BI.isString(options) && (options = { level: options }); + isString(options) && (options = { level: options }); options = options || {}; - context = context || BI.Widget._renderEngine.createElement("body"); - var level = options.level || "common"; - var autoClose = BI.isNull(options.autoClose) ? true : options.autoClose; - var callback = BI.isFunction(options.callback) ? options.callback : BI.emptyFn; - var toast = BI.createWidget({ + context = context || Widget._renderEngine.createElement("body"); + const level = options.level || "common"; + const autoClose = isNull(options.autoClose) ? true : options.autoClose; + const callback = isFunction(options.callback) ? options.callback : BI.emptyFn; + const toast = createWidget({ type: "bi.toast", cls: "bi-message-animate bi-message-leave", level: level, @@ -37,9 +39,9 @@ BI.Msg = ((function () { listeners: [{ eventName: BI.Toast.EVENT_DESTORY, action: function () { - BI.remove(toastStack, toast.element); - var _height = BI.SIZE_CONSANTS.TOAST_TOP; - BI.each(toastStack, function (i, element) { + remove(toastStack, toast.element); + let _height = BI.SIZE_CONSANTS.TOAST_TOP; + each(toastStack, function (i, element) { element.css({ "top": _height }); _height += element.outerHeight() + 10; }); @@ -47,11 +49,11 @@ BI.Msg = ((function () { }, }], }); - var height = BI.SIZE_CONSANTS.TOAST_TOP; - BI.each(toastStack, function (i, element) { + const height = BI.SIZE_CONSANTS.TOAST_TOP; + each(toastStack, function (i, element) { height += element.outerHeight() + 10; }); - BI.createWidget({ + createWidget({ type: "bi.absolute", element: context, items: [{ @@ -75,7 +77,7 @@ BI.Msg = ((function () { }; }, _show: function (hasCancel, title, message, callback) { - BI.isNull($mask) && ($mask = BI.Widget._renderEngine.createElement("
").css({ + isNull($mask) && ($mask = Widget._renderEngine.createElement("
").css({ position: "absolute", zIndex: BI.zIndex_tip - 2, top: 0, @@ -84,7 +86,7 @@ BI.Msg = ((function () { bottom: 0, opacity: 0.5, }).appendTo("body")); - $pop = BI.Widget._renderEngine.createElement("
").css({ + $pop = Widget._renderEngine.createElement("
").css({ position: "absolute", zIndex: BI.zIndex_tip - 1, top: 0, @@ -100,7 +102,7 @@ BI.Msg = ((function () { $mask = null; } } - var controlItems = []; + let controlItems = []; if (hasCancel === true) { controlItems.push({ el: { @@ -109,7 +111,7 @@ BI.Msg = ((function () { level: "ignore", handler: function () { close(); - if (BI.isFunction(callback)) { + if (isFunction(callback)) { callback.apply(null, [false]); } }, @@ -122,13 +124,13 @@ BI.Msg = ((function () { text: BI.i18nText("BI-Basic_OK"), handler: function () { close(); - if (BI.isFunction(callback)) { + if (isFunction(callback)) { callback.apply(null, [true]); } }, }, }); - var conf = { + const conf = { element: $pop, type: "bi.center_adapt", items: [ @@ -141,13 +143,13 @@ BI.Msg = ((function () { this.element.keyup(function (e) { if (e.keyCode === BI.KeyCode.ENTER) { close(); - if (BI.isFunction(callback)) { + if (isFunction(callback)) { callback.apply(null, [true]); } } else if (e.keyCode === BI.KeyCode.ESCAPE) { close(); if (hasCancel === true) { - if (BI.isFunction(callback)) { + if (isFunction(callback)) { callback.apply(null, [false]); } } @@ -183,7 +185,7 @@ BI.Msg = ((function () { // height: 50, handler: function () { close(); - if (BI.isFunction(callback)) { + if (isFunction(callback)) { callback.apply(null, [false]); } }, @@ -228,7 +230,7 @@ BI.Msg = ((function () { ], }; - messageShows[messageShows.length] = BI.createWidget(conf); + messageShows[messageShows.length] = createWidget(conf); }, }; })()); diff --git a/src/base/index.js b/src/base/index.js index 723070d48..2c1dc228c 100644 --- a/src/base/index.js +++ b/src/base/index.js @@ -1,93 +1,31 @@ -import { extend } from "../core"; -import Pane from "./1.pane"; -import Single from "./single/0.single"; -import Text from "./single/1.text"; -import A from "./single/a/a"; -import Tip from "./single/tip/0.tip"; -import Toast from "./single/tip/tip.toast"; -import Tooltip from "./single/tip/tip.tooltip"; -import Drawer from "./layer/layer.drawer"; -import { Popover, BarPopover } from "./layer/layer.popover"; -import PopupView from "./layer/layer.popup"; -import SearcherView from "./layer/layer.searcher"; -import ListView from "./list/listview"; -import VirtualGroupList from "./list/virtualgrouplist"; -import VirtualList from "./list/virtuallist"; +import { Pane } from "./1.pane"; +import * as single from "./single"; +import * as layer from "./layer"; +import * as list from "./list"; import GridView from "./grid/grid"; import Pager from "./pager/pager"; -import Bubble from "./combination/bubble"; -import Combo from "./combination/combo"; -import Expander from "./combination/expander"; -import ButtonGroup from "./combination/group.button"; -import ComboGroup from "./combination/group.combo"; -import VirtualGroup from "./combination/group.virtual"; -import Loader from "./combination/loader"; -import Navigation from "./combination/navigation"; -import Searcher from "./combination/searcher"; -import Switcher from "./combination/switcher"; -import Tab from "./combination/tab"; -import ButtonTree from "./combination/tree.button"; +import * as combination from "./combination"; +import { Msg } from "./foundation/message"; -extend(BI, { +Object.assign(BI, { Pane, - Single, - Text, - A, - Tip, - Toast, - Tooltip, - Drawer, - Popover, - BarPopover, - PopupView, - SearcherView, - ListView, - VirtualGroupList, - VirtualList, + ...layer, + ...list, + ...single, GridView, Pager, - Bubble, - Combo, - Expander, - ButtonGroup, - ComboGroup, - VirtualGroup, - Loader, - Navigation, - Searcher, - Switcher, - Tab, - ButtonTree, + ...combination, + Msg, }); +export * from "./0.base"; +export * from "./combination"; +export * from "./layer"; +export * from "./list"; +export * from "./single"; export { Pane, - Single, - Text, - A, - Tip, - Toast, - Tooltip, - Drawer, - Popover, - BarPopover, - PopupView, - SearcherView, - ListView, - VirtualGroupList, - VirtualList, GridView, Pager, - Bubble, - Combo, - Expander, - ButtonGroup, - ComboGroup, - VirtualGroup, - Loader, - Navigation, - Searcher, - Switcher, - Tab, - ButtonTree, + Msg, } \ No newline at end of file diff --git a/src/base/layer/index.js b/src/base/layer/index.js new file mode 100644 index 000000000..8f04625d9 --- /dev/null +++ b/src/base/layer/index.js @@ -0,0 +1,4 @@ +export { Drawer } from "./layer.drawer"; +export { Popover, BarPopover } from "./layer.popover"; +export { PopupView } from "./layer.popup"; +export { SearcherView } from "./layer.searcher"; \ No newline at end of file diff --git a/src/base/layer/layer.drawer.js b/src/base/layer/layer.drawer.js index 890981d0e..75ef6b04b 100644 --- a/src/base/layer/layer.drawer.js +++ b/src/base/layer/layer.drawer.js @@ -6,7 +6,7 @@ import { Widget, shortcut } from "../../core"; @shortcut() -export default class Drawer extends Widget { +export class Drawer extends Widget { SIZE = { SMALL: "small", NORMAL: "normal", diff --git a/src/base/layer/layer.popup.js b/src/base/layer/layer.popup.js index ea4a35196..fd79d015f 100644 --- a/src/base/layer/layer.popup.js +++ b/src/base/layer/layer.popup.js @@ -6,7 +6,7 @@ import { Widget, shortcut } from "../../core"; @shortcut() -export default class PopupView extends Widget { +export class PopupView extends Widget { _const = { TRIANGLE_LENGTH: 12, } diff --git a/src/base/layer/layer.searcher.js b/src/base/layer/layer.searcher.js index f76aa7a17..9d4cfbb0e 100644 --- a/src/base/layer/layer.searcher.js +++ b/src/base/layer/layer.searcher.js @@ -7,10 +7,10 @@ */ import { shortcut } from "../../core"; -import Pane from "../1.pane"; +import { Pane } from "../1.pane"; @shortcut() -export default class SearcherView extends Pane { +export class SearcherView extends Pane { static xtype = "bi.searcher_view"; static EVENT_CHANGE = "EVENT_CHANGE"; diff --git a/src/base/list/index.js b/src/base/list/index.js new file mode 100644 index 000000000..0a1c500cd --- /dev/null +++ b/src/base/list/index.js @@ -0,0 +1,3 @@ +export { ListView } from "./listview"; +export { VirtualGroupList } from "./virtualgrouplist"; +export { VirtualList } from "./virtuallist"; \ No newline at end of file diff --git a/src/base/list/listview.js b/src/base/list/listview.js index 3ec9dc162..ce2870e75 100644 --- a/src/base/list/listview.js +++ b/src/base/list/listview.js @@ -7,7 +7,7 @@ */ import { Widget, shortcut } from "../../core"; @shortcut() -export default class ListView extends Widget { +export class ListView extends Widget { props() { return { baseCls: "bi-list-view", diff --git a/src/base/list/virtualgrouplist.js b/src/base/list/virtualgrouplist.js index be9845cc1..d89cb32a0 100644 --- a/src/base/list/virtualgrouplist.js +++ b/src/base/list/virtualgrouplist.js @@ -8,7 +8,7 @@ import { Widget, shortcut } from "../../core"; @shortcut() -export default class VirtualGroupList extends Widget { +export class VirtualGroupList extends Widget { props() { return { baseCls: "bi-virtual-group-list", diff --git a/src/base/list/virtuallist.js b/src/base/list/virtuallist.js index ed788acdd..d2ce62311 100644 --- a/src/base/list/virtuallist.js +++ b/src/base/list/virtuallist.js @@ -8,7 +8,7 @@ import { Widget, shortcut } from "../../core"; @shortcut() -export default class VirtualList extends Widget { +export class VirtualList extends Widget { props() { return { baseCls: "bi-virtual-list", diff --git a/src/base/single/0.single.js b/src/base/single/0.single.js index 845e8c33d..cd6ec00b0 100644 --- a/src/base/single/0.single.js +++ b/src/base/single/0.single.js @@ -14,7 +14,7 @@ import { Widget, shortcut } from "../../core"; import { Tooltips } from "../0.base"; @shortcut() -export default class Single extends Widget { +export class Single extends Widget { static xtype = "bi.single"; _defaultConfig() { diff --git a/src/base/single/1.text.js b/src/base/single/1.text.js index 33001a7bd..294a2aaec 100644 --- a/src/base/single/1.text.js +++ b/src/base/single/1.text.js @@ -3,11 +3,11 @@ * @class BI.Text * @extends BI.Single */ -import { shortcut } from "../../core/decorator"; -import { Single } from "../index"; +import { shortcut } from "../../core"; +import { Single } from "./0.single"; @shortcut() -export default class Text extends Single { +export class Text extends Single { static xtype = "bi.text"; props = { diff --git a/src/base/single/a/a.js b/src/base/single/a/a.js index 7acf03231..c52006dd3 100644 --- a/src/base/single/a/a.js +++ b/src/base/single/a/a.js @@ -7,9 +7,9 @@ * @abstract */ import { shortcut } from "../../../core"; -import Text from "../1.text"; +import { Text } from "../1.text"; @shortcut() -export default class A extends Text { +export class A extends Text { static xtype = "bi.a"; _defaultConfig() { diff --git a/src/base/single/index.js b/src/base/single/index.js new file mode 100644 index 000000000..748788816 --- /dev/null +++ b/src/base/single/index.js @@ -0,0 +1,4 @@ +export { Single } from "./0.single"; +export { Text } from "./1.text"; +export { A } from "./a/a"; +export * from "./tip"; \ No newline at end of file diff --git a/src/base/single/tip/0.tip.js b/src/base/single/tip/0.tip.js index d9ac9fee7..a4b93f4e5 100644 --- a/src/base/single/tip/0.tip.js +++ b/src/base/single/tip/0.tip.js @@ -7,8 +7,8 @@ * @abstract */ -import Single from "../0.single"; -export default class Tip extends Single { +import { Single } from "../0.single"; +export class Tip extends Single { _defaultConfig() { const conf = super._defaultConfig(arguments); return BI.extend(conf, { diff --git a/src/base/single/tip/index.js b/src/base/single/tip/index.js new file mode 100644 index 000000000..509c6be4c --- /dev/null +++ b/src/base/single/tip/index.js @@ -0,0 +1,3 @@ +export { Tip } from "./0.tip"; +export { Toast } from "./tip.toast"; +export { Tooltip } from "./tip.tooltip"; \ No newline at end of file diff --git a/src/base/single/tip/tip.toast.js b/src/base/single/tip/tip.toast.js index e93b3627a..2dce887e5 100644 --- a/src/base/single/tip/tip.toast.js +++ b/src/base/single/tip/tip.toast.js @@ -7,9 +7,9 @@ */ import { shortcut } from "../../../core"; -import Tip from "./0.tip"; +import { Tip } from "./0.tip"; @shortcut() -export default class Toast extends Tip { +export class Toast extends Tip { _const= { closableMinWidth: 146, minWidth: 100, diff --git a/src/base/single/tip/tip.tooltip.js b/src/base/single/tip/tip.tooltip.js index d50a52c19..d101bcab8 100644 --- a/src/base/single/tip/tip.tooltip.js +++ b/src/base/single/tip/tip.tooltip.js @@ -7,9 +7,9 @@ */ import { shortcut } from "../../../core"; -import Tip from "./0.tip"; +import { Tip } from "./0.tip"; @shortcut() -export default class Tooltip extends Tip { +export class Tooltip extends Tip { _const = { hgap: 8, vgap: 4, diff --git a/src/core/2.base.js b/src/core/2.base.js index a4e8df688..01814415b 100644 --- a/src/core/2.base.js +++ b/src/core/2.base.js @@ -139,20 +139,6 @@ export function trans2Element(widgets) { return map(widgets, (i, wi) => wi.element); } -// Utility -BI._.extend(BI, { - assert, - warn, - UUID, - isWidget, - createWidgets, - createItems, - packageItems, - formatEL, - stripEL, - trans2Element, -}); - // 集合相关方法 BI._.each(["where", "findWhere", "invoke", "pluck", "shuffle", "sample", "toArray", "size"], function (name) { BI[name] = _apply(name); @@ -384,27 +370,6 @@ export function int2Abc(num) { return str; } -BI._.extend(BI, { - count, - inverse, - firstKey, - lastKey, - firstObject, - lastObject, - concat, - backEach, - backAny, - backEvery, - backFindKey, - backFind, - remove, - removeAt, - string2Array, - array2String, - abc2Int, - int2Abc, -}); - // 数组相关的方法 BI._.each([ "first", "initial", "last", "rest", "compact", "flatten", "without", "union", "intersection", @@ -493,13 +458,6 @@ export function uniq(array, isSorted, iteratee, context) { return uniq.call(BI._, array, isSorted, iteratee, context); } -BI._.extend(BI, { - makeArray, - makeObject, - makeArrayByArray, - uniq, -}); - // 对象相关方法 BI._.each([ "keys", "allKeys", "values", "pairs", "invert", "create", "functions", "extend", "extendOwn", @@ -652,24 +610,6 @@ export function isPromise(obj) { return !!obj && (isObject(obj) || isFunction(obj)) && isFunction(obj.then); } -BI._.extend(BI, { - inherit, - init, - has, - freeze, - isKey, - isCapitalEqual, - isWidthOrHeight, - isNotNull, - isNull, - isEmptyArray, - isNotEmptyArray, - isEmptyObject, - isNotEmptyObject, - isWindow, - isPromise, -}); - export const deepClone = BI._.cloneDeep; export const deepExtend = BI._.deepExtend; @@ -781,20 +721,6 @@ export function deepDiff(object, other) { return result; } -// deep方法 -BI._.extend(BI, { - deepClone: BI._.cloneDeep, - deepExtend: BI._.merge, - isDeepMatch, - contains, - deepContains, - deepIndexOf, - deepRemove, - deepWithout, - deepUnique, - deepDiff, -}); - // 通用方法 BI._.each(["uniqueId", "result", "chain", "iteratee", "unescape", "before", "after", "chunk"], function (name) { BI[name] = function () { @@ -893,8 +819,6 @@ export const nextTick = (function () { }; })(); -BI._.extend(BI, { nextTick }); - // 数字相关方法 BI._.each(["random"], function (name) { BI[name] = _apply(name); @@ -985,22 +909,6 @@ export function average(array, iteratee, context) { return sumResult / array.length; } -BI._.extend(BI, { - parseInt, - parseSafeInt, - parseFloat, - isNaturalNumber, - isPositiveInteger, - isNegativeInteger, - isInteger, - isNumeric, - isFloat, - isOdd, - isEven, - sum, - average, -}); - export function trim() { return BI._.trim.apply(BI._, arguments); } @@ -1126,25 +1034,6 @@ export function format(format) { return format.replace(/\{(\d+)\}/g, (m, i) => args[i]); } -// 字符串相关方法 -BI._.extend(BI, { - trim, - toUpperCase, - toLowerCase, - isEndWithBlank, - isLiteral, - stripQuotes, - camelize, - hyphenate, - isNotEmptyString, - isEmptyString, - encrypt, - decrypt, - escape, - leftPad, - format, -}); - /** * 是否是闰年 * @param year @@ -1454,15 +1343,5 @@ export function getTime() { return dt.getTime() - BI.timeZone - new Date().getTimezoneOffset() * 60000; } return dt.getTime(); - } -// 日期相关方法 -BI._.extend(BI, { - isLeapYear, - checkDateVoid, - checkDateLegal, - parseDateTime, - getDate, - getTime, -}); diff --git a/src/core/3.ob.js b/src/core/3.ob.js index f51a68f06..fcd9db92a 100644 --- a/src/core/3.ob.js +++ b/src/core/3.ob.js @@ -1,4 +1,4 @@ -import { isFunction, isArray, isObject, isArguments, reduce, bind, extend } from "./2.base"; +import { isFunction, isArray, isObject, isArguments, reduce, bind } from "./2.base"; function obExtend() { let target = arguments[0] || {}, length = arguments.length, i = 1, name, copy; @@ -26,7 +26,7 @@ function obExtend() { return target; } -export default class OB { +export class OB { // props = {}; // init = null; @@ -215,5 +215,3 @@ export default class OB { this.purgeListeners(); } } - -extend(BI, { OB }); diff --git a/src/core/4.widget.js b/src/core/4.widget.js index 54e833b51..e67bdb4dc 100644 --- a/src/core/4.widget.js +++ b/src/core/4.widget.js @@ -7,7 +7,7 @@ */ import { isFunction, isArray, each, extend, isPlainObject, isNull, uniqueId, isWidget, isWidthOrHeight, isKey, remove, any, isNotNull } from "./2.base"; -import OB from "./3.ob"; +import { OB } from "./3.ob"; import { Providers, _lazyCreateWidget } from "./5.inject"; const cancelAnimationFrame = @@ -35,7 +35,7 @@ function callLifeHook(self, life) { }); } -export default class Widget extends OB { +export class Widget extends OB { _defaultConfig () { return extend(super._defaultConfig(), { root: false, @@ -1079,15 +1079,3 @@ export function mount(widget, container, predicate, hydrate) { } return widget._mount(true, false, false, predicate); } - -extend(BI, { - Widget, - useStore, - useContext, - watch, - onBeforeMount, - onMounted, - onBeforeUnmount, - onUnmounted, - mount, -}); diff --git a/src/core/5.inject.js b/src/core/5.inject.js index a8ec6786d..77faa02f3 100644 --- a/src/core/5.inject.js +++ b/src/core/5.inject.js @@ -1,6 +1,6 @@ import { isFunction, isNull, isNotNull, isArray, each, isWidget, extend, init, isEmpty, remove } from "./2.base"; -import OB from "./3.ob"; -import Widget from "./4.widget" +import { OB } from "./3.ob"; +import { Widget } from "./4.widget" let moduleInjection = {}, moduleInjectionMap = { components: {}, @@ -39,7 +39,6 @@ export function module(xtype, cls) { return () => Modules.getModule(xtype); } -BI.module = BI.module || module; let constantInjection = {}; export function constant(xtype, cls) { @@ -51,7 +50,6 @@ export function constant(xtype, cls) { return () => Constants.getConstant(xtype); } -BI.constant = BI.constant || constant; let modelInjection = {}; export function model(xtype, cls) { @@ -63,7 +61,6 @@ export function model(xtype, cls) { return (config) => Models.getModel(xtype, config); } -BI.model = BI.model || model; let storeInjection = {}; export function store(xtype, cls) { @@ -75,7 +72,6 @@ export function store(xtype, cls) { return (config) => Stores.getStore(xtype, config); } -BI.store = BI.store || store; let serviceInjection = {}; export function service(xtype, cls) { @@ -87,7 +83,6 @@ export function service(xtype, cls) { return (config) => Services.getService(xtype, config); } -BI.service = BI.service || service; let providerInjection = {}; export function provider(xtype, cls) { @@ -99,7 +94,6 @@ export function provider(xtype, cls) { return (config) => Providers.getProvider(xtype, config); } -BI.provider = BI.provider || provider; let configFunctions = OB.configFunctions = {}; const runConfigFunction = function (type, configFn) { @@ -200,12 +194,10 @@ export function config(type, configFn, opt) { return runConfigFunction(type, configFn); } } -BI.config = BI.config || config; export function getReference(type, fn) { return BI.Plugin.registerObject(type, fn); } -BI.getReference = BI.getReference || getReference; let actions = {}; let globalAction = []; @@ -227,7 +219,6 @@ export function action(type, actionFn) { } }; } -BI.action = BI.action || action; let points = {}; export function point(type, action, pointFn, after) { @@ -242,7 +233,6 @@ export function point(type, action, pointFn, after) { } points[type][action][after ? "after" : "before"].push(pointFn); } -BI.point = BI.point || point; export const Modules = { getModule: function (type) { @@ -255,7 +245,6 @@ export const Modules = { return moduleInjection; } } -BI.Modules = BI.Modules || Modules; export const Constants = { getConstant: function (type) { @@ -266,7 +255,6 @@ export const Constants = { return isFunction(constantInjection[type]) ? constantInjection[type]() : constantInjection[type]; } } -BI.Constants = BI.Constants || Constants; const callPoint = function (inst, types) { types = isArray(types) ? types : [types]; @@ -319,7 +307,6 @@ export const Models = { return inst; } } -BI.Models = BI.Models || Models; let stores = {}; export const Stores = { @@ -338,7 +325,6 @@ export const Stores = { return inst; } } -BI.Stores = BI.Stores || Stores; let services = {}; export const Services = { @@ -354,7 +340,6 @@ export const Services = { return services[type]; } } -BI.Services = BI.Services || Services; let providers = {}, providerInstance = {}; @@ -373,7 +358,6 @@ export const Providers = { return providerInstance[type]; } } -BI.Providers = BI.Providers || Providers; export const Actions = { runAction: function (type, event, config) { @@ -396,7 +380,6 @@ export const Actions = { }); } } -BI.Actions = BI.Actions || Actions; let kv = {}; export function shortcut(xtype, cls) { @@ -408,7 +391,6 @@ export function shortcut(xtype, cls) { } kv[xtype] = cls; } -BI.shortcut = BI.component = BI.shortcut || shortcut; // 根据配置属性生成widget const createRealWidget = function (config, context, lazy) { @@ -496,18 +478,15 @@ export function createWidget(item, options, context, lazy) { } throw new Error("组件:无法根据item创建组件", item); } -BI.createWidget = BI.createWidget || createWidget; export function _lazyCreateWidget (item, options, context) { return createWidget(item, options, context, true); } -BI._lazyCreateWidget = BI._lazyCreateWidget || _lazyCreateWidget; export function createElement() { const widget = createWidget.apply(this, arguments); return widget.element; } -BI.createElement = BI.createElement || createElement; export function getResource(type, config) { if (isNotNull(constantInjection[type])) { @@ -527,4 +506,3 @@ export function getResource(type, config) { } throw new Error("未知类型: [" + type + "] 未定义"); } -BI.getResource = BI.getResource || getResource; diff --git a/src/core/action/action.js b/src/core/action/action.js index e582778ea..b87ea1e21 100644 --- a/src/core/action/action.js +++ b/src/core/action/action.js @@ -5,8 +5,8 @@ * @extends BI.OB * @abstract */ -import OB from "../3.ob"; -export default class Action extends OB { +import { OB } from "../3.ob"; +export class Action extends OB { props = { src: null, tar: null diff --git a/src/core/action/action.show.js b/src/core/action/action.show.js index 6ab3b7e1c..1084ec542 100644 --- a/src/core/action/action.show.js +++ b/src/core/action/action.show.js @@ -4,8 +4,8 @@ * @class BI.ShowAction * @extends BI.Action */ -import Action from "./action"; -export default class ShowAction extends Action { +import { Action } from "./action"; +export class ShowAction extends Action { actionPerformed(src, tar, callback) { tar = tar || this.options.tar; tar.setVisible(true); diff --git a/src/core/action/index.js b/src/core/action/index.js new file mode 100644 index 000000000..f82304e43 --- /dev/null +++ b/src/core/action/index.js @@ -0,0 +1,2 @@ +export { Action } from "./action"; +export { ShowAction } from "./action.show"; \ No newline at end of file diff --git a/src/core/behavior/0.behavior.js b/src/core/behavior/0.behavior.js index 25d82b529..5adc59d3d 100644 --- a/src/core/behavior/0.behavior.js +++ b/src/core/behavior/0.behavior.js @@ -20,8 +20,8 @@ BI.BehaviorFactory = { * @extends BI.OB */ -import OB from "../3.ob"; -export default class Behavior extends OB { +import { OB } from "../3.ob"; +export class Behavior extends OB { _defaultConfig() { return BI.extend(super._defaultConfig(arguments), { rule: () => true diff --git a/src/core/behavior/behavior.highlight.js b/src/core/behavior/behavior.highlight.js index 6ba710da0..1c0676b90 100644 --- a/src/core/behavior/behavior.highlight.js +++ b/src/core/behavior/behavior.highlight.js @@ -4,8 +4,8 @@ * @class BI.HighlightBehavior * @extends BI.Behavior */ -import Behavior from "./0.behavior"; -export default class HighlightBehavior extends Behavior { +import { Behavior } from "./0.behavior"; +export class HighlightBehavior extends Behavior { doBehavior(items) { const args = Array.prototype.slice.call(arguments, 1), o = this.options; diff --git a/src/core/behavior/behavior.redmark.js b/src/core/behavior/behavior.redmark.js index 1b2b349cf..5beb0797f 100644 --- a/src/core/behavior/behavior.redmark.js +++ b/src/core/behavior/behavior.redmark.js @@ -4,8 +4,8 @@ * @class BI.RedMarkBehavior * @extends BI.Behavior */ -import Behavior from "./0.behavior"; -export default class RedMarkBehavior extends Behavior { +import { Behavior } from "./0.behavior"; +export class RedMarkBehavior extends Behavior { doBehavior(items) { const args = Array.prototype.slice.call(arguments, 1), o = this.options; diff --git a/src/core/behavior/index.js b/src/core/behavior/index.js new file mode 100644 index 000000000..ee2ae69ed --- /dev/null +++ b/src/core/behavior/index.js @@ -0,0 +1,3 @@ +export { Behavior } from "./0.behavior"; +export { HighlightBehavior } from "./behavior.highlight"; +export { RedMarkBehavior } from "./behavior.redmark"; \ No newline at end of file diff --git a/src/core/controller/0.controller.js b/src/core/controller/0.controller.js index 0b5bd7b09..0841a9358 100644 --- a/src/core/controller/0.controller.js +++ b/src/core/controller/0.controller.js @@ -6,7 +6,7 @@ * @extends BI.OB * @abstract */ -import OB from "../3.ob"; -export default class Controller extends OB { +import { OB } from "../3.ob"; +export class Controller extends OB { static EVENT_CHANGE = "__EVENT_CHANGE__"; } diff --git a/src/core/controller/controller.broadcast.js b/src/core/controller/controller.broadcast.js index f6d7b8951..f0cc90c8d 100644 --- a/src/core/controller/controller.broadcast.js +++ b/src/core/controller/controller.broadcast.js @@ -4,8 +4,8 @@ * Created by GUY on 2015/12/23. * @class */ -import Controller from "./0.controller"; -export default class BroadcastController extends Controller { +import { Controller } from "./0.controller"; +export class BroadcastController extends Controller { init() { this._broadcasts = {}; } diff --git a/src/core/controller/controller.bubbles.js b/src/core/controller/controller.bubbles.js index 815b94728..e596eac60 100644 --- a/src/core/controller/controller.bubbles.js +++ b/src/core/controller/controller.bubbles.js @@ -5,8 +5,8 @@ * Created by GUY on 2015/8/21. * @class */ -import Controller from "./0.controller"; -export default class BubblesController extends Controller { +import { Controller } from "./0.controller"; +export class BubblesController extends Controller { init() { this.storeBubbles = {}; this.storePoppers = {}; diff --git a/src/core/controller/controller.drawer.js b/src/core/controller/controller.drawer.js index c288d019f..51a80b734 100644 --- a/src/core/controller/controller.drawer.js +++ b/src/core/controller/controller.drawer.js @@ -4,8 +4,8 @@ * @class BI.popoverController * @extends BI.Controller */ -import Controller from "./0.controller"; -export default class DrawerController extends Controller { +import { Controller } from "./0.controller"; +export class DrawerController extends Controller { constructor() { super(); this._constructor(); diff --git a/src/core/controller/controller.layer.js b/src/core/controller/controller.layer.js index 54273957b..6356588ab 100644 --- a/src/core/controller/controller.layer.js +++ b/src/core/controller/controller.layer.js @@ -4,8 +4,8 @@ * Created by GUY on 2015/6/24. * @class */ -import Controller from "./0.controller"; -export default class LayerController extends Controller { +import { Controller } from "./0.controller"; +export class LayerController extends Controller { constructor() { super(); this._constructor(); diff --git a/src/core/controller/controller.masker.js b/src/core/controller/controller.masker.js index 33bffef75..7ff0532bc 100644 --- a/src/core/controller/controller.masker.js +++ b/src/core/controller/controller.masker.js @@ -4,8 +4,8 @@ * Created by GUY on 2015/6/24. * @class */ -import LayerController from "./controller.layer"; -export default class MaskersController extends LayerController { +import { LayerController } from "./controller.layer"; +export class MaskersController extends LayerController { init() { super.init(arguments); this.zindex = BI.zIndex_masker; diff --git a/src/core/controller/controller.popover.js b/src/core/controller/controller.popover.js index 0c48b68ec..dc8e6a14d 100644 --- a/src/core/controller/controller.popover.js +++ b/src/core/controller/controller.popover.js @@ -4,8 +4,8 @@ * @class BI.popoverController * @extends BI.Controller */ -import Controller from "./0.controller"; -export default class PopoverController extends Controller { +import { Controller } from "./0.controller"; +export class PopoverController extends Controller { constructor() { super(); this._constructor(); diff --git a/src/core/controller/controller.resizer.js b/src/core/controller/controller.resizer.js index 3a6dcd31a..5b8c400b8 100644 --- a/src/core/controller/controller.resizer.js +++ b/src/core/controller/controller.resizer.js @@ -4,8 +4,8 @@ * Created by GUY on 2015/6/24. * @class */ -import Controller from "./0.controller"; -export default class ResizeController extends Controller { +import { Controller } from "./0.controller"; +export class ResizeController extends Controller { init() { this.resizerManger = {}; diff --git a/src/core/controller/controller.tooltips.js b/src/core/controller/controller.tooltips.js index 0e397aa33..e084caba9 100644 --- a/src/core/controller/controller.tooltips.js +++ b/src/core/controller/controller.tooltips.js @@ -6,8 +6,8 @@ * @class BI.TooltipsController * @extends BI.Controller */ -import Controller from "./0.controller"; -export default class TooltipsController extends Controller { +import { Controller } from "./0.controller"; +export class TooltipsController extends Controller { init() { this.tooltipsManager = {}; this.showingTips = {};// 存储正在显示的tooltip diff --git a/src/core/controller/index.js b/src/core/controller/index.js new file mode 100644 index 000000000..91701e15f --- /dev/null +++ b/src/core/controller/index.js @@ -0,0 +1,9 @@ +export { Controller } from "./0.controller"; +export { BroadcastController } from "./controller.broadcast"; +export { BubblesController } from "./controller.bubbles"; +export { DrawerController } from "./controller.drawer"; +export { LayerController } from "./controller.layer"; +export { MaskersController } from "./controller.masker"; +export { PopoverController } from "./controller.popover"; +export { ResizeController } from "./controller.resizer"; +export { TooltipsController } from "./controller.tooltips"; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 3c660e1de..397017380 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,68 +1,39 @@ -import {shortcut} from "./decorator"; -import OB from "./3.ob"; -import Widget from "./4.widget"; -import Action from "./action/action"; -import ShowAction from "./action/action.show"; -import Behavior from "./behavior/0.behavior"; -import HighlightBehavior from "./behavior/behavior.highlight"; -import RedMarkBehavior from "./behavior/behavior.redmark"; -import Controller from "./controller/0.controller"; -import BroadcastController from "./controller/controller.broadcast"; -import BubblesController from "./controller/controller.bubbles"; -import DrawerController from "./controller/controller.drawer"; -import LayerController from "./controller/controller.layer"; -import MaskersController from "./controller/controller.masker"; -import PopoverController from "./controller/controller.popover"; -import ResizeController from "./controller/controller.resizer"; -import TooltipsController from "./controller/controller.tooltips"; -import StyleLoaderManager from "./loader/loader.style"; -import "./h"; -import ShowListener from "./listener/listener.show"; -BI.extend(BI, { - OB, - Widget, - Action, - ShowAction, - Behavior, - HighlightBehavior, - RedMarkBehavior, - Controller, - BroadcastController, - BubblesController, - DrawerController, - LayerController, - MaskersController, - PopoverController, - ResizeController, - TooltipsController, - StyleLoaderManager, - ShowListener, -}); +import * as base from "./2.base"; +import * as ob from "./3.ob"; +import * as widget from "./4.widget"; +import * as inject from "./5.inject"; +import * as action from "./action"; +import * as behavior from "./behavior"; +import * as controllers from "./controller"; +import { StyleLoaderManager } from "./loader/loader.style"; +import "./h"; +import { ShowListener } from "./listener/listener.show"; +import { shortcut } from "./decorator"; export * from "./2.base"; +export * from "./3.ob"; export * from "./4.widget"; export * from "./5.inject"; -export * from "./func"; +export * from "./action"; +export * from "./behavior"; +export * from "./controller"; export { + StyleLoaderManager, + ShowListener, shortcut, - OB, - Widget, - Action, - ShowAction, - Behavior, - HighlightBehavior, - RedMarkBehavior, - Controller, - BroadcastController, - BubblesController, - DrawerController, - LayerController, - MaskersController, - PopoverController, - ResizeController, - TooltipsController, +} + +Object.assign(BI, { + ...base, + ...ob, + ...widget, + ...inject, + ...behavior, + component: inject.shortcut, + ...action, + ...controllers, StyleLoaderManager, - ShowListener -}; + ShowListener, +}); diff --git a/src/core/listener/listener.show.js b/src/core/listener/listener.show.js index 1c9469473..25ddc7ea2 100644 --- a/src/core/listener/listener.show.js +++ b/src/core/listener/listener.show.js @@ -5,12 +5,12 @@ * @class BI.ShowListener * @extends BI.OB */ -import OB from "../3.ob"; +import { OB } from "../3.ob"; import { isArray, isNull, nextTick, } from "../2.base"; import { createWidget } from "../5.inject"; -import Controller from "../controller/0.controller"; +import { Controller } from "../controller/0.controller"; -export default class ShowListener extends OB { +export class ShowListener extends OB { static EVENT_CHANGE = "EVENT_CHANGE"; props() { diff --git a/src/core/loader/loader.style.js b/src/core/loader/loader.style.js index e10007cc3..1c65a2ede 100644 --- a/src/core/loader/loader.style.js +++ b/src/core/loader/loader.style.js @@ -4,9 +4,9 @@ * Created by GUY on 2015/9/7. * @class */ -import OB from "../3.ob"; +import { OB } from "../3.ob"; -export default class StyleLoaderManager extends OB { +export class StyleLoaderManager extends OB { _defaultConfig() { return BI.extend(super._defaultConfig(arguments), {}); } From 455a1618766713b1aef3687a559d6b447540cd89 Mon Sep 17 00:00:00 2001 From: "Zhenfei.Li" Date: Wed, 4 Jan 2023 14:05:28 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20refactor:?= =?UTF-8?q?=20func=E4=B8=AD=E7=9A=84=E6=8C=82=E8=BD=BDBI=E6=8C=AA=E8=B5=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/func/index.js | 17 ----------------- src/core/index.js | 3 +++ 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/core/func/index.js b/src/core/func/index.js index 9b24275bf..b04392bdc 100644 --- a/src/core/func/index.js +++ b/src/core/func/index.js @@ -4,20 +4,3 @@ export * from "./date"; export * from "./function"; export * from "./number"; export * from "./string"; - -// need delete -import * as _alias from "./alias"; -import * as _array from "./array"; -import * as _date from "./date"; -import * as _function from "./function"; -import * as _number from "./number"; -import * as _string from "./string"; - -Object.assign(BI, { - ..._alias, - ..._array, - ..._date, - ..._function, - ..._number, - ..._string, -}); diff --git a/src/core/index.js b/src/core/index.js index 397017380..53a8cd755 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -6,6 +6,7 @@ import * as inject from "./5.inject"; import * as action from "./action"; import * as behavior from "./behavior"; import * as controllers from "./controller"; +import * as func from "./func"; import { StyleLoaderManager } from "./loader/loader.style"; import "./h"; import { ShowListener } from "./listener/listener.show"; @@ -18,6 +19,7 @@ export * from "./5.inject"; export * from "./action"; export * from "./behavior"; export * from "./controller"; +export * from "./func"; export { StyleLoaderManager, @@ -34,6 +36,7 @@ Object.assign(BI, { component: inject.shortcut, ...action, ...controllers, + ...func, StyleLoaderManager, ShowListener, });