From 3ebfb153fa81dd1cd0e31556552c0a884c1c6204 Mon Sep 17 00:00:00 2001 From: zsmj1994 Date: Thu, 18 Jun 2020 18:26:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0JIRA=20feat:=20BI.Plugin=20=E4=B8=AD?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E7=BB=84=E4=BB=B6=E9=85=8D=E7=BD=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/plugin.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/core/plugin.js b/src/core/plugin.js index 323045a42a..069a1ceacc 100644 --- a/src/core/plugin.js +++ b/src/core/plugin.js @@ -3,13 +3,18 @@ BI.Plugin = BI.Plugin || {}; var _WidgetsPlugin = {}; var _ObjectPlugin = {}; var _ConfigPlugin = {}; - var _GlobalWidgetConfigFn, _GlobalObjectConfigFn; + var _GlobalWidgetConfigFns = []; + var __GlobalObjectConfigFns = []; BI.extend(BI.Plugin, { getWidget: function (type, options) { - if (_GlobalWidgetConfigFn) { - _GlobalWidgetConfigFn(type, options); + if (_GlobalWidgetConfigFns.length > 0) { + var fns = _GlobalWidgetConfigFns.slice(0); + for (var i = fns.length - 1; i >= 0; i--) { + fns[i](type, options); + } } + var res; if (_ConfigPlugin[type]) { for (var i = _ConfigPlugin[type].length - 1; i >= 0; i--) { @@ -30,8 +35,8 @@ BI.Plugin = BI.Plugin || {}; }, config: function (widgetConfigFn, objectConfigFn) { - _GlobalWidgetConfigFn = widgetConfigFn; - _GlobalObjectConfigFn = objectConfigFn; + _GlobalWidgetConfigFns = _GlobalWidgetConfigFns.concat(_.isArray(widgetConfigFn) ? widgetConfigFn : [widgetConfigFn]); + __GlobalObjectConfigFns = __GlobalObjectConfigFns.concat(_.isArray(objectConfigFn) ? objectConfigFn : [objectConfigFn]); }, configWidget: function (type, fn) { @@ -56,15 +61,19 @@ BI.Plugin = BI.Plugin || {}; }, getObject: function (type, object) { - if (_GlobalObjectConfigFn) { - _GlobalObjectConfigFn(type, object); + if (__GlobalObjectConfigFns.length > 0) { + var fns = __GlobalObjectConfigFns.slice(0); + for (var i = fns.length - 1; i >= 0; i--) { + fns[i](type, object); + } } + if (_ObjectPlugin[type]) { var res; for (var i = 0, len = _ObjectPlugin[type].length; i < len; i++) { if (res = _ObjectPlugin[type][i](object)) { object = res; - }; + } } } return res || object; @@ -84,4 +93,4 @@ BI.Plugin = BI.Plugin || {}; delete _ObjectPlugin[type]; } }); -})(); \ No newline at end of file +})();