From d7fb4a72791996760173b21b0b5537ca693be964 Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 26 Jul 2021 22:17:30 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/6.inject.js | 91 +++++++++++++++++++++++++++++++++++++++++++- src/core/system.js | 16 ++++++++ 2 files changed, 105 insertions(+), 2 deletions(-) diff --git a/src/core/6.inject.js b/src/core/6.inject.js index 90c7fcc5e..46029e316 100644 --- a/src/core/6.inject.js +++ b/src/core/6.inject.js @@ -1,9 +1,68 @@ (function () { - var moduleInjection = {}; + var moduleInjection = {}, moduleInjectionMap = { + components: {}, + constants: {}, + stores: {}, + services: {}, + models: {}, + providers: {} + }; BI.module = BI.module || function (xtype, cls) { if (moduleInjection[xtype] != null) { _global.console && console.error("module: [" + xtype + "] 已经注册过了"); } + var i, len, value = { + version: cls.version, + moduleId: xtype + }; + if (cls.components) { + for (i = 0, len = cls.components.length; i < len; i++) { + if (!moduleInjectionMap.components[cls.components[i]]) { + moduleInjectionMap.components[cls.components[i]] = []; + } + moduleInjectionMap.components[cls.components[i]].push(value); + } + } + if (cls.constants) { + for (i = 0, len = cls.constants.length; i < len; i++) { + if (!moduleInjectionMap.constants[cls.constants[i]]) { + moduleInjectionMap.constants[cls.constants[i]] = []; + } + moduleInjectionMap.constants[cls.constants[i]].push(value); + } + } + if (cls.stores) { + for (i = 0, len = cls.stores.length; i < len; i++) { + if (!moduleInjectionMap.stores[cls.stores[i]]) { + moduleInjectionMap.stores[cls.stores[i]] = []; + } + moduleInjectionMap.stores[cls.stores[i]].push(value); + } + } + if (cls.services) { + for (i = 0, len = cls.services.length; i < len; i++) { + if (!moduleInjectionMap.services[cls.services[i]]) { + moduleInjectionMap.services[cls.services[i]] = []; + } + moduleInjectionMap.services[cls.services[i]].push(value); + } + } + if (cls.models) { + for (i = 0, len = cls.models.length; i < len; i++) { + if (!moduleInjectionMap.models[cls.models[i]]) { + moduleInjectionMap.models[cls.models[i]] = []; + } + moduleInjectionMap.models[cls.models[i]].push(value); + } + } + if (cls.providers) { + for (i = 0, len = cls.providers.length; i < len; i++) { + if (!moduleInjectionMap.providers[cls.providers[i]]) { + moduleInjectionMap.providers[cls.providers[i]] = []; + } + moduleInjectionMap.providers[cls.providers[i]].push(value); + } + } moduleInjection[xtype] = cls; }; @@ -49,6 +108,7 @@ var configFunctions = {}; BI.config = BI.config || function (type, configFn, opt) { + opt = opt || {}; if (BI.initialized) { if (constantInjection[type]) { return (constantInjection[type] = configFn(constantInjection[type])); @@ -69,7 +129,31 @@ configFunctions[type] = []; BI.prepares.push(function () { var queue = configFunctions[type]; + var dependencies = BI.Providers.getProvider("bi.provider.system").getDependencies(); + var modules = moduleInjectionMap.components[type] + || moduleInjectionMap.constants[type] + || moduleInjectionMap.services[type] + || moduleInjectionMap.stores[type] + || moduleInjectionMap.models[type] + || moduleInjectionMap.providers[type]; for (var i = 0; i < queue.length; i++) { + if(modules) { + for (var j = 0; j < modules.length; j++) { + var module = modules[i]; + if (module && dependencies[module.moduleId]) { + if (module.version < dependencies[module.moduleId].min || module.version > dependencies[module.moduleId].max) { + _global.console && console.error("module: [" + type + "] 版本: [" + module.version + "] 已过期"); + continue; + } + } + } + } + if (module && dependencies[module.moduleId]) { + if (module.version < dependencies[module.moduleId].min || module.version > dependencies[module.moduleId].max) { + _global.console && console.error("module: [" + type + "] 版本: [" + module.version + "] 已过期"); + continue; + } + } if (constantInjection[type]) { constantInjection[type] = queue[i](constantInjection[type]); continue; @@ -89,7 +173,10 @@ configFunctions[type] = null; }); } - configFunctions[type].push(configFn); + configFunctions[type].push({ + fn: configFn, + opt: opt + }); }; BI.getReference = BI.getReference || function (type, fn) { diff --git a/src/core/system.js b/src/core/system.js index 40dc78c5d..54e60e8d8 100644 --- a/src/core/system.js +++ b/src/core/system.js @@ -6,6 +6,7 @@ // 系统参数常量 !(function () { var system = { + dependencies: {}, size: { // 尺寸 TOOL_BAR_HEIGHT: 24, LIST_ITEM_HEIGHT: 24, @@ -21,12 +22,27 @@ BI.deepExtend(system, { size: opt }); }; + this.addDependency = function (moduleId, minVersion, maxVersion) { + system.dependencies[moduleId] = { + min: minVersion, + max: maxVersion + }; + }; + + this.addDependencies = function (moduleConfig) { + BI.extend(system.dependencies, moduleConfig); + }; + this.$get = function () { return BI.inherit(BI.OB, { getSize: function () { return system.size; }, + + getDependencies: function () { + return system.dependencies; + } }); }; }; From 638e428d41e42aea1183c407e2be263cf649d4aa Mon Sep 17 00:00:00 2001 From: git Date: Mon, 26 Jul 2021 22:49:06 +0800 Subject: [PATCH 2/4] add --- src/core/6.inject.js | 89 +++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 60 deletions(-) diff --git a/src/core/6.inject.js b/src/core/6.inject.js index 46029e316..f6db51f8f 100644 --- a/src/core/6.inject.js +++ b/src/core/6.inject.js @@ -11,56 +11,18 @@ if (moduleInjection[xtype] != null) { _global.console && console.error("module: [" + xtype + "] 已经注册过了"); } - var i, len, value = { - version: cls.version, - moduleId: xtype - }; - if (cls.components) { - for (i = 0, len = cls.components.length; i < len; i++) { - if (!moduleInjectionMap.components[cls.components[i]]) { - moduleInjectionMap.components[cls.components[i]] = []; - } - moduleInjectionMap.components[cls.components[i]].push(value); - } - } - if (cls.constants) { - for (i = 0, len = cls.constants.length; i < len; i++) { - if (!moduleInjectionMap.constants[cls.constants[i]]) { - moduleInjectionMap.constants[cls.constants[i]] = []; - } - moduleInjectionMap.constants[cls.constants[i]].push(value); - } - } - if (cls.stores) { - for (i = 0, len = cls.stores.length; i < len; i++) { - if (!moduleInjectionMap.stores[cls.stores[i]]) { - moduleInjectionMap.stores[cls.stores[i]] = []; - } - moduleInjectionMap.stores[cls.stores[i]].push(value); - } - } - if (cls.services) { - for (i = 0, len = cls.services.length; i < len; i++) { - if (!moduleInjectionMap.services[cls.services[i]]) { - moduleInjectionMap.services[cls.services[i]] = []; - } - moduleInjectionMap.services[cls.services[i]].push(value); - } - } - if (cls.models) { - for (i = 0, len = cls.models.length; i < len; i++) { - if (!moduleInjectionMap.models[cls.models[i]]) { - moduleInjectionMap.models[cls.models[i]] = []; - } - moduleInjectionMap.models[cls.models[i]].push(value); - } - } - if (cls.providers) { - for (i = 0, len = cls.providers.length; i < len; i++) { - if (!moduleInjectionMap.providers[cls.providers[i]]) { - moduleInjectionMap.providers[cls.providers[i]] = []; + var key; + for (var k in moduleInjectionMap) { + if(cls[k]){ + for (key in cls[k]) { + if (!moduleInjectionMap[k][key]) { + moduleInjectionMap[k][key] = []; + } + moduleInjectionMap[k][key].push({ + version: cls[k][key], + moduleId: xtype + }); } - moduleInjectionMap.providers[cls.providers[i]].push(value); } } moduleInjection[xtype] = cls; @@ -137,25 +99,32 @@ || moduleInjectionMap.models[type] || moduleInjectionMap.providers[type]; for (var i = 0; i < queue.length; i++) { - if(modules) { + var conf = queue[i]; + var version = conf.opt.version; + var fn = conf.fn; + if(modules && version) { + var findVersion = false; for (var j = 0; j < modules.length; j++) { var module = modules[i]; - if (module && dependencies[module.moduleId]) { - if (module.version < dependencies[module.moduleId].min || module.version > dependencies[module.moduleId].max) { - _global.console && console.error("module: [" + type + "] 版本: [" + module.version + "] 已过期"); - continue; + if (module && dependencies[module.moduleId] && module.version === version) { + var min = dependencies[module.moduleId].min, max = dependencies[module.moduleId].max; + if (min && module.version < min){ + findVersion = true; + break; + } + if(max && module.version > max){ + findVersion = true; + break; } } } - } - if (module && dependencies[module.moduleId]) { - if (module.version < dependencies[module.moduleId].min || module.version > dependencies[module.moduleId].max) { + if(findVersion === true){ _global.console && console.error("module: [" + type + "] 版本: [" + module.version + "] 已过期"); continue; } } if (constantInjection[type]) { - constantInjection[type] = queue[i](constantInjection[type]); + constantInjection[type] = fn(constantInjection[type]); continue; } if (providerInjection[type]) { @@ -165,10 +134,10 @@ if (providerInstance[type]) { delete providerInstance[type]; } - queue[i](providers[type]); + fn(providers[type]); continue; } - BI.Plugin.configWidget(type, queue[i]); + BI.Plugin.configWidget(type, fn); } configFunctions[type] = null; }); From 9f82d4574b61eba79bd7fc621ddb8c703402d838 Mon Sep 17 00:00:00 2001 From: git Date: Mon, 26 Jul 2021 23:05:35 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/dev.html | 23 +++++++++++++++++++++++ src/core/6.inject.js | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/examples/dev.html b/examples/dev.html index 143fbbeb5..89b4fbdec 100644 --- a/examples/dev.html +++ b/examples/dev.html @@ -8,6 +8,29 @@
+