|
|
|
@ -1,9 +1,30 @@
|
|
|
|
|
(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 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 |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
moduleInjection[xtype] = cls; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -49,7 +70,9 @@
|
|
|
|
|
|
|
|
|
|
var configFunctions = {}; |
|
|
|
|
BI.config = BI.config || function (type, configFn, opt) { |
|
|
|
|
if (BI.initialized) { |
|
|
|
|
opt = opt || {}; |
|
|
|
|
// 初始化过或者系统配置需要立刻执行
|
|
|
|
|
if (BI.initialized || "bi.provider.system" === type) { |
|
|
|
|
if (constantInjection[type]) { |
|
|
|
|
return (constantInjection[type] = configFn(constantInjection[type])); |
|
|
|
|
} |
|
|
|
@ -69,9 +92,40 @@
|
|
|
|
|
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++) { |
|
|
|
|
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] && 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(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]) { |
|
|
|
@ -81,15 +135,18 @@
|
|
|
|
|
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; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
configFunctions[type].push(configFn); |
|
|
|
|
configFunctions[type].push({ |
|
|
|
|
fn: configFn, |
|
|
|
|
opt: opt |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
BI.getReference = BI.getReference || function (type, fn) { |
|
|
|
|