Browse Source

Pull request #2050: 无JIRA任务 版本号

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit 'f745626fee5e908c51cbaadd557114300a7dfaeb':
  add
  版本
  add
  版本号控制
es6
guy 3 years ago
parent
commit
285c736b75
  1. 1
      changelog.md
  2. 23
      examples/dev.html
  3. 69
      src/core/6.inject.js
  4. 16
      src/core/system.js

1
changelog.md

@ -1,5 +1,6 @@
# 更新日志 # 更新日志
2.0(2021-07) 2.0(2021-07)
- 增加module定义插件版本号
- bubble使用popper.js实现 - bubble使用popper.js实现
- 优化了日期类型控件标红时的报错提示 - 优化了日期类型控件标红时的报错提示
- 支持虚拟dom - 支持虚拟dom

23
examples/dev.html

@ -8,6 +8,29 @@
</head> </head>
<body> <body>
<div id="wrapper"></div> <div id="wrapper"></div>
<script>
BI.config("demo.parent", function (config){
console.log("123");
return config;
}, {
version: "1.0"
});
BI.module("my.module", {
components: {
"demo.parent": "1.0"
}
})
BI.config("bi.provider.system", function (provider) {
provider.addDependencies({
"my.module": {
min: "2.0",
max: "4.0"
}
})
})
</script>
<script> <script>
var Model = BI.inherit(Fix.Model, { var Model = BI.inherit(Fix.Model, {
state: function () { state: function () {

69
src/core/6.inject.js

@ -1,9 +1,30 @@
(function () { (function () {
var moduleInjection = {}; var moduleInjection = {}, moduleInjectionMap = {
components: {},
constants: {},
stores: {},
services: {},
models: {},
providers: {}
};
BI.module = BI.module || function (xtype, cls) { BI.module = BI.module || function (xtype, cls) {
if (moduleInjection[xtype] != null) { if (moduleInjection[xtype] != null) {
_global.console && console.error("module: [" + xtype + "] 已经注册过了"); _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; moduleInjection[xtype] = cls;
}; };
@ -49,7 +70,9 @@
var configFunctions = {}; var configFunctions = {};
BI.config = BI.config || function (type, configFn, opt) { BI.config = BI.config || function (type, configFn, opt) {
if (BI.initialized) { opt = opt || {};
// 初始化过或者系统配置需要立刻执行
if (BI.initialized || "bi.provider.system" === type) {
if (constantInjection[type]) { if (constantInjection[type]) {
return (constantInjection[type] = configFn(constantInjection[type])); return (constantInjection[type] = configFn(constantInjection[type]));
} }
@ -69,9 +92,40 @@
configFunctions[type] = []; configFunctions[type] = [];
BI.prepares.push(function () { BI.prepares.push(function () {
var queue = configFunctions[type]; 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++) { 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]) { if (constantInjection[type]) {
constantInjection[type] = queue[i](constantInjection[type]); constantInjection[type] = fn(constantInjection[type]);
continue; continue;
} }
if (providerInjection[type]) { if (providerInjection[type]) {
@ -81,15 +135,18 @@
if (providerInstance[type]) { if (providerInstance[type]) {
delete providerInstance[type]; delete providerInstance[type];
} }
queue[i](providers[type]); fn(providers[type]);
continue; continue;
} }
BI.Plugin.configWidget(type, queue[i]); BI.Plugin.configWidget(type, fn);
} }
configFunctions[type] = null; configFunctions[type] = null;
}); });
} }
configFunctions[type].push(configFn); configFunctions[type].push({
fn: configFn,
opt: opt
});
}; };
BI.getReference = BI.getReference || function (type, fn) { BI.getReference = BI.getReference || function (type, fn) {

16
src/core/system.js

@ -6,6 +6,7 @@
// 系统参数常量 // 系统参数常量
!(function () { !(function () {
var system = { var system = {
dependencies: {},
size: { // 尺寸 size: { // 尺寸
TOOL_BAR_HEIGHT: 24, TOOL_BAR_HEIGHT: 24,
LIST_ITEM_HEIGHT: 24, LIST_ITEM_HEIGHT: 24,
@ -21,12 +22,27 @@
BI.deepExtend(system, { size: opt }); 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 () { this.$get = function () {
return BI.inherit(BI.OB, { return BI.inherit(BI.OB, {
getSize: function () { getSize: function () {
return system.size; return system.size;
}, },
getDependencies: function () {
return system.dependencies;
}
}); });
}; };
}; };

Loading…
Cancel
Save