From d7fb4a72791996760173b21b0b5537ca693be964 Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 26 Jul 2021 22:17:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E6=8E=A7=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; + } }); }; };