|
|
@ -1,5 +1,8 @@ |
|
|
|
(function () { |
|
|
|
import { isFunction, isNull, isNotNull, isArray, each, isWidget, extend, init, isEmpty, remove } from "./2.base"; |
|
|
|
var moduleInjection = {}, moduleInjectionMap = { |
|
|
|
import OB from "./3.ob"; |
|
|
|
|
|
|
|
import Widget from "./4.widget" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let moduleInjection = {}, moduleInjectionMap = { |
|
|
|
components: {}, |
|
|
|
components: {}, |
|
|
|
constants: {}, |
|
|
|
constants: {}, |
|
|
|
stores: {}, |
|
|
|
stores: {}, |
|
|
@ -7,16 +10,17 @@ |
|
|
|
models: {}, |
|
|
|
models: {}, |
|
|
|
providers: {} |
|
|
|
providers: {} |
|
|
|
}; |
|
|
|
}; |
|
|
|
BI.module = BI.module || function (xtype, cls) { |
|
|
|
|
|
|
|
|
|
|
|
export function module(xtype, cls) { |
|
|
|
if (moduleInjection[xtype] != null) { |
|
|
|
if (moduleInjection[xtype] != null) { |
|
|
|
_global.console && console.error("module: [" + xtype + "] 已经注册过了"); |
|
|
|
_global.console && console.error("module: [" + xtype + "] 已经注册过了"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (BI.isFunction(cls)) { |
|
|
|
if (isFunction(cls)) { |
|
|
|
cls = cls(); |
|
|
|
cls = cls(); |
|
|
|
} |
|
|
|
} |
|
|
|
for (var k in moduleInjectionMap) { |
|
|
|
for (const k in moduleInjectionMap) { |
|
|
|
if (cls[k]) { |
|
|
|
if (cls[k]) { |
|
|
|
for (var key in cls[k]) { |
|
|
|
for (const key in cls[k]) { |
|
|
|
if (!moduleInjectionMap[k]) { |
|
|
|
if (!moduleInjectionMap[k]) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
@ -33,112 +37,103 @@ |
|
|
|
moduleInjection[xtype] = cls; |
|
|
|
moduleInjection[xtype] = cls; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return function () { |
|
|
|
return () => Modules.getModule(xtype); |
|
|
|
return BI.Modules.getModule(xtype); |
|
|
|
} |
|
|
|
}; |
|
|
|
BI.module = BI.module || module; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var constantInjection = {}; |
|
|
|
let constantInjection = {}; |
|
|
|
BI.constant = BI.constant || function (xtype, cls) { |
|
|
|
export function constant(xtype, cls) { |
|
|
|
if (constantInjection[xtype] != null) { |
|
|
|
if (constantInjection[xtype] != null) { |
|
|
|
_global.console && console.error("constant: [" + xtype + "]已经注册过了"); |
|
|
|
_global.console && console.error("constant: [" + xtype + "]已经注册过了"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
constantInjection[xtype] = cls; |
|
|
|
constantInjection[xtype] = cls; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return function () { |
|
|
|
return () => Constants.getConstant(xtype); |
|
|
|
return BI.Constants.getConstant(xtype); |
|
|
|
} |
|
|
|
}; |
|
|
|
BI.constant = BI.constant || constant; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var modelInjection = {}; |
|
|
|
let modelInjection = {}; |
|
|
|
BI.model = BI.model || function (xtype, cls) { |
|
|
|
export function model(xtype, cls) { |
|
|
|
if (modelInjection[xtype] != null) { |
|
|
|
if (modelInjection[xtype] != null) { |
|
|
|
_global.console && console.error("model: [" + xtype + "] 已经注册过了"); |
|
|
|
_global.console && console.error("model: [" + xtype + "] 已经注册过了"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
modelInjection[xtype] = cls; |
|
|
|
modelInjection[xtype] = cls; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return function (config) { |
|
|
|
return (config) => Models.getModel(xtype, config); |
|
|
|
return BI.Models.getModel(xtype, config); |
|
|
|
} |
|
|
|
}; |
|
|
|
BI.model = BI.model || model; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var storeInjection = {}; |
|
|
|
let storeInjection = {}; |
|
|
|
BI.store = BI.store || function (xtype, cls) { |
|
|
|
export function store(xtype, cls) { |
|
|
|
if (storeInjection[xtype] != null) { |
|
|
|
if (storeInjection[xtype] != null) { |
|
|
|
_global.console && console.error("store: [" + xtype + "] 已经注册过了"); |
|
|
|
_global.console && console.error("store: [" + xtype + "] 已经注册过了"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
storeInjection[xtype] = cls; |
|
|
|
storeInjection[xtype] = cls; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return function (config) { |
|
|
|
return (config) => Stores.getStore(xtype, config); |
|
|
|
return BI.Stores.getStore(xtype, config); |
|
|
|
} |
|
|
|
}; |
|
|
|
BI.store = BI.store || store; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var serviceInjection = {}; |
|
|
|
let serviceInjection = {}; |
|
|
|
BI.service = BI.service || function (xtype, cls) { |
|
|
|
export function service(xtype, cls) { |
|
|
|
if (serviceInjection[xtype] != null) { |
|
|
|
if (serviceInjection[xtype] != null) { |
|
|
|
_global.console && console.error("service: [" + xtype + "] 已经注册过了"); |
|
|
|
_global.console && console.error("service: [" + xtype + "] 已经注册过了"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
serviceInjection[xtype] = cls; |
|
|
|
serviceInjection[xtype] = cls; |
|
|
|
|
|
|
|
|
|
|
|
return function (config) { |
|
|
|
return (config) => Services.getService(xtype, config); |
|
|
|
return BI.Services.getService(xtype, config); |
|
|
|
} |
|
|
|
}; |
|
|
|
BI.service = BI.service || service; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var providerInjection = {}; |
|
|
|
let providerInjection = {}; |
|
|
|
BI.provider = BI.provider || function (xtype, cls) { |
|
|
|
export function provider(xtype, cls) { |
|
|
|
if (providerInjection[xtype] != null) { |
|
|
|
if (providerInjection[xtype] != null) { |
|
|
|
_global.console && console.error("provider: [" + xtype + "] 已经注册过了"); |
|
|
|
_global.console && console.error("provider: [" + xtype + "] 已经注册过了"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
providerInjection[xtype] = cls; |
|
|
|
providerInjection[xtype] = cls; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return function (config) { |
|
|
|
return (config) => Providers.getProvider(xtype, config); |
|
|
|
return BI.Providers.getProvider(xtype, config); |
|
|
|
} |
|
|
|
}; |
|
|
|
BI.provider = BI.provider || provider; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var configFunctions = BI.OB.configFunctions = {}; |
|
|
|
let configFunctions = OB.configFunctions = {}; |
|
|
|
var runConfigFunction = function (type, configFn) { |
|
|
|
const runConfigFunction = function (type, configFn) { |
|
|
|
if (!type || !configFunctions[type]) { |
|
|
|
if (!type || !configFunctions[type]) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var queue = []; |
|
|
|
let queue = []; |
|
|
|
if (configFn) { |
|
|
|
if (configFn) { |
|
|
|
queue = configFunctions[type].filter(function (conf) { |
|
|
|
queue = configFunctions[type].filter((conf) => conf.fn === configFn); |
|
|
|
return conf.fn === configFn; |
|
|
|
configFunctions[type] = configFunctions[type].filter((conf) => conf.fn !== configFn); |
|
|
|
}); |
|
|
|
|
|
|
|
configFunctions[type] = configFunctions[type].filter(function (conf) { |
|
|
|
|
|
|
|
return conf.fn !== configFn; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
queue = configFunctions[type]; |
|
|
|
queue = configFunctions[type]; |
|
|
|
delete configFunctions[type]; |
|
|
|
delete configFunctions[type]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var dependencies = BI.Providers.getProvider("bi.provider.system").getDependencies(); |
|
|
|
const dependencies = Providers.getProvider("bi.provider.system").getDependencies(); |
|
|
|
var modules = moduleInjectionMap.components[type] |
|
|
|
const modules = moduleInjectionMap.components[type] |
|
|
|
|| moduleInjectionMap.constants[type] |
|
|
|
|| moduleInjectionMap.constants[type] |
|
|
|
|| moduleInjectionMap.services[type] |
|
|
|
|| moduleInjectionMap.services[type] |
|
|
|
|| moduleInjectionMap.stores[type] |
|
|
|
|| moduleInjectionMap.stores[type] |
|
|
|
|| moduleInjectionMap.models[type] |
|
|
|
|| moduleInjectionMap.models[type] |
|
|
|
|| moduleInjectionMap.providers[type]; |
|
|
|
|| moduleInjectionMap.providers[type]; |
|
|
|
for (var i = 0; i < queue.length; i++) { |
|
|
|
for (let i = 0; i < queue.length; i++) { |
|
|
|
var conf = queue[i]; |
|
|
|
const conf = queue[i]; |
|
|
|
var version = conf.opt.version; |
|
|
|
const version = conf.opt.version; |
|
|
|
var fn = conf.fn; |
|
|
|
const fn = conf.fn; |
|
|
|
if (modules && version) { |
|
|
|
if (modules && version) { |
|
|
|
var findVersion = false; |
|
|
|
let findVersion = false; |
|
|
|
for (var j = 0; j < modules.length; j++) { |
|
|
|
let module; |
|
|
|
var module = modules[j]; |
|
|
|
for (let j = 0; j < modules.length; j++) { |
|
|
|
|
|
|
|
module = modules[j]; |
|
|
|
if (module && dependencies[module.moduleId] && module.version === version) { |
|
|
|
if (module && dependencies[module.moduleId] && module.version === version) { |
|
|
|
var minVersion = dependencies[module.moduleId].minVersion, |
|
|
|
const minVersion = dependencies[module.moduleId].minVersion, |
|
|
|
maxVersion = dependencies[module.moduleId].maxVersion; |
|
|
|
maxVersion = dependencies[module.moduleId].maxVersion; |
|
|
|
if (minVersion && (moduleInjection[module.moduleId].version || version) < minVersion) { |
|
|
|
if (minVersion && (moduleInjection[module.moduleId].version || version) < minVersion) { |
|
|
|
findVersion = true; |
|
|
|
findVersion = true; |
|
|
@ -172,8 +167,9 @@ |
|
|
|
BI.Plugin.configWidget(type, fn, conf.opt); |
|
|
|
BI.Plugin.configWidget(type, fn, conf.opt); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
BI.config = BI.config || function (type, configFn, opt) { |
|
|
|
|
|
|
|
if (BI.isFunction(type)) { |
|
|
|
export function config(type, configFn, opt) { |
|
|
|
|
|
|
|
if (isFunction(type)) { |
|
|
|
opt = configFn; |
|
|
|
opt = configFn; |
|
|
|
configFn = type; |
|
|
|
configFn = type; |
|
|
|
type = "bi.provider.system"; |
|
|
|
type = "bi.provider.system"; |
|
|
@ -203,39 +199,38 @@ |
|
|
|
if (opt.immediately) { |
|
|
|
if (opt.immediately) { |
|
|
|
return runConfigFunction(type, configFn); |
|
|
|
return runConfigFunction(type, configFn); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI.config = BI.config || config; |
|
|
|
|
|
|
|
|
|
|
|
BI.getReference = BI.getReference || function (type, fn) { |
|
|
|
export function getReference(type, fn) { |
|
|
|
return BI.Plugin.registerObject(type, fn); |
|
|
|
return BI.Plugin.registerObject(type, fn); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI.getReference = BI.getReference || getReference; |
|
|
|
|
|
|
|
|
|
|
|
var actions = {}; |
|
|
|
let actions = {}; |
|
|
|
var globalAction = []; |
|
|
|
let globalAction = []; |
|
|
|
BI.action = BI.action || function (type, actionFn) { |
|
|
|
export function action(type, actionFn) { |
|
|
|
if (BI.isFunction(type)) { |
|
|
|
if (isFunction(type)) { |
|
|
|
globalAction.push(type); |
|
|
|
globalAction.push(type); |
|
|
|
return function () { |
|
|
|
return () => { |
|
|
|
BI.remove(globalAction, function (idx) { |
|
|
|
remove(globalAction, (idx) => globalAction.indexOf(actionFn) === idx); |
|
|
|
return globalAction.indexOf(actionFn) === idx; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!actions[type]) { |
|
|
|
if (!actions[type]) { |
|
|
|
actions[type] = []; |
|
|
|
actions[type] = []; |
|
|
|
} |
|
|
|
} |
|
|
|
actions[type].push(actionFn); |
|
|
|
actions[type].push(actionFn); |
|
|
|
return function () { |
|
|
|
return () => { |
|
|
|
BI.remove(actions[type], function (idx) { |
|
|
|
remove(actions[type], (idx) => actions[type].indexOf(actionFn) === idx); |
|
|
|
return actions[type].indexOf(actionFn) === idx; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (actions[type].length === 0) { |
|
|
|
if (actions[type].length === 0) { |
|
|
|
delete actions[type]; |
|
|
|
delete actions[type]; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI.action = BI.action || action; |
|
|
|
|
|
|
|
|
|
|
|
var points = {}; |
|
|
|
let points = {}; |
|
|
|
BI.point = BI.point || function (type, action, pointFn, after) { |
|
|
|
export function point(type, action, pointFn, after) { |
|
|
|
if (!points[type]) { |
|
|
|
if (!points[type]) { |
|
|
|
points[type] = {}; |
|
|
|
points[type] = {}; |
|
|
|
} |
|
|
|
} |
|
|
@ -246,9 +241,10 @@ |
|
|
|
points[type][action][after ? "after" : "before"] = []; |
|
|
|
points[type][action][after ? "after" : "before"] = []; |
|
|
|
} |
|
|
|
} |
|
|
|
points[type][action][after ? "after" : "before"].push(pointFn); |
|
|
|
points[type][action][after ? "after" : "before"].push(pointFn); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI.point = BI.point || point; |
|
|
|
|
|
|
|
|
|
|
|
BI.Modules = BI.Modules || { |
|
|
|
export const Modules = { |
|
|
|
getModule: function (type) { |
|
|
|
getModule: function (type) { |
|
|
|
if (!moduleInjection[type]) { |
|
|
|
if (!moduleInjection[type]) { |
|
|
|
_global.console && console.error("module: [" + type + "] 未定义"); |
|
|
|
_global.console && console.error("module: [" + type + "] 未定义"); |
|
|
@ -258,28 +254,30 @@ |
|
|
|
getAllModules: function () { |
|
|
|
getAllModules: function () { |
|
|
|
return moduleInjection; |
|
|
|
return moduleInjection; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI.Modules = BI.Modules || Modules; |
|
|
|
|
|
|
|
|
|
|
|
BI.Constants = BI.Constants || { |
|
|
|
export const Constants = { |
|
|
|
getConstant: function (type) { |
|
|
|
getConstant: function (type) { |
|
|
|
if (BI.isNull(constantInjection[type])) { |
|
|
|
if (isNull(constantInjection[type])) { |
|
|
|
_global.console && console.error("constant: [" + type + "] 未定义"); |
|
|
|
_global.console && console.error("constant: [" + type + "] 未定义"); |
|
|
|
} |
|
|
|
} |
|
|
|
runConfigFunction(type); |
|
|
|
runConfigFunction(type); |
|
|
|
return BI.isFunction(constantInjection[type]) ? constantInjection[type]() : constantInjection[type]; |
|
|
|
return isFunction(constantInjection[type]) ? constantInjection[type]() : constantInjection[type]; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI.Constants = BI.Constants || Constants; |
|
|
|
|
|
|
|
|
|
|
|
var callPoint = function (inst, types) { |
|
|
|
const callPoint = function (inst, types) { |
|
|
|
types = BI.isArray(types) ? types : [types]; |
|
|
|
types = isArray(types) ? types : [types]; |
|
|
|
BI.each(types, function (idx, type) { |
|
|
|
each(types, (idx, type) => { |
|
|
|
if (points[type]) { |
|
|
|
if (points[type]) { |
|
|
|
for (var action in points[type]) { |
|
|
|
for (const action in points[type]) { |
|
|
|
var bfns = points[type][action].before; |
|
|
|
let bfns = points[type][action].before; |
|
|
|
if (bfns) { |
|
|
|
if (bfns) { |
|
|
|
BI.aspect.before(inst, action, function (bfns) { |
|
|
|
BI.aspect.before(inst, action, function (bfns) { |
|
|
|
return function () { |
|
|
|
return function () { |
|
|
|
for (var i = 0, len = bfns.length; i < len; i++) { |
|
|
|
for (let i = 0, len = bfns.length; i < len; i++) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
bfns[i].apply(inst, arguments); |
|
|
|
bfns[i].apply(inst, arguments); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
@ -289,11 +287,11 @@ |
|
|
|
}; |
|
|
|
}; |
|
|
|
}(bfns)); |
|
|
|
}(bfns)); |
|
|
|
} |
|
|
|
} |
|
|
|
var afns = points[type][action].after; |
|
|
|
let afns = points[type][action].after; |
|
|
|
if (afns) { |
|
|
|
if (afns) { |
|
|
|
BI.aspect.after(inst, action, function (afns) { |
|
|
|
BI.aspect.after(inst, action, function (afns) { |
|
|
|
return function () { |
|
|
|
return function () { |
|
|
|
for (var i = 0, len = afns.length; i < len; i++) { |
|
|
|
for (let i = 0, len = afns.length; i < len; i++) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
afns[i].apply(inst, arguments); |
|
|
|
afns[i].apply(inst, arguments); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
@ -308,7 +306,7 @@ |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
BI.Models = BI.Models || { |
|
|
|
export const Models = { |
|
|
|
getModel: function (type, config) { |
|
|
|
getModel: function (type, config) { |
|
|
|
if (!modelInjection[type]) { |
|
|
|
if (!modelInjection[type]) { |
|
|
|
_global.console && console.error("model: [" + type + "] 未定义"); |
|
|
|
_global.console && console.error("model: [" + type + "] 未定义"); |
|
|
@ -320,11 +318,11 @@ |
|
|
|
callPoint(inst, type); |
|
|
|
callPoint(inst, type); |
|
|
|
return inst; |
|
|
|
return inst; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI.Models = BI.Models || Models; |
|
|
|
var stores = {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BI.Stores = BI.Stores || { |
|
|
|
let stores = {}; |
|
|
|
|
|
|
|
export const Stores = { |
|
|
|
getStore: function (type, config) { |
|
|
|
getStore: function (type, config) { |
|
|
|
if (!storeInjection[type]) { |
|
|
|
if (!storeInjection[type]) { |
|
|
|
_global.console && console.error("store: [" + type + "] 未定义"); |
|
|
|
_global.console && console.error("store: [" + type + "] 未定义"); |
|
|
@ -332,19 +330,19 @@ |
|
|
|
if (stores[type]) { |
|
|
|
if (stores[type]) { |
|
|
|
return stores[type]; |
|
|
|
return stores[type]; |
|
|
|
} |
|
|
|
} |
|
|
|
var inst = stores[type] = new storeInjection[type](config); |
|
|
|
const inst = stores[type] = new storeInjection[type](config); |
|
|
|
inst._constructor && inst._constructor(config, function () { |
|
|
|
inst._constructor && inst._constructor(config, function () { |
|
|
|
delete stores[type]; |
|
|
|
delete stores[type]; |
|
|
|
}); |
|
|
|
}); |
|
|
|
callPoint(inst, type); |
|
|
|
callPoint(inst, type); |
|
|
|
return inst; |
|
|
|
return inst; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI.Stores = BI.Stores || Stores; |
|
|
|
var services = {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BI.Services = BI.Services || { |
|
|
|
let services = {}; |
|
|
|
getService: function (type, config) { |
|
|
|
export const Services = { |
|
|
|
|
|
|
|
getService: (type, config) => { |
|
|
|
if (!serviceInjection[type]) { |
|
|
|
if (!serviceInjection[type]) { |
|
|
|
_global.console && console.error("service: [" + type + "] 未定义"); |
|
|
|
_global.console && console.error("service: [" + type + "] 未定义"); |
|
|
|
} |
|
|
|
} |
|
|
@ -355,13 +353,13 @@ |
|
|
|
callPoint(services[type], type); |
|
|
|
callPoint(services[type], type); |
|
|
|
return services[type]; |
|
|
|
return services[type]; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI.Services = BI.Services || Services; |
|
|
|
|
|
|
|
|
|
|
|
var providers = {}, |
|
|
|
let providers = {}, |
|
|
|
providerInstance = {}; |
|
|
|
providerInstance = {}; |
|
|
|
|
|
|
|
export const Providers = { |
|
|
|
BI.Providers = BI.Providers || { |
|
|
|
getProvider: (type, config) => { |
|
|
|
getProvider: function (type, config) { |
|
|
|
|
|
|
|
if (!providerInjection[type]) { |
|
|
|
if (!providerInjection[type]) { |
|
|
|
_global.console && console.error("provider: [" + type + "] 未定义"); |
|
|
|
_global.console && console.error("provider: [" + type + "] 未定义"); |
|
|
|
} |
|
|
|
} |
|
|
@ -374,11 +372,12 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
return providerInstance[type]; |
|
|
|
return providerInstance[type]; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI.Providers = BI.Providers || Providers; |
|
|
|
|
|
|
|
|
|
|
|
BI.Actions = BI.Actions || { |
|
|
|
export const Actions = { |
|
|
|
runAction: function (type, event, config) { |
|
|
|
runAction: function (type, event, config) { |
|
|
|
BI.each(actions[type], function (i, act) { |
|
|
|
each(actions[type], (i, act) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
act(event, config); |
|
|
|
act(event, config); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
@ -388,7 +387,7 @@ |
|
|
|
}, |
|
|
|
}, |
|
|
|
runGlobalAction: function () { |
|
|
|
runGlobalAction: function () { |
|
|
|
var args = [].slice.call(arguments); |
|
|
|
var args = [].slice.call(arguments); |
|
|
|
BI.each(globalAction, function (i, act) { |
|
|
|
each(globalAction, (i, act) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
act.apply(null, args); |
|
|
|
act.apply(null, args); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
@ -396,10 +395,11 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI.Actions = BI.Actions || Actions; |
|
|
|
|
|
|
|
|
|
|
|
var kv = {}; |
|
|
|
let kv = {}; |
|
|
|
BI.shortcut = BI.component = BI.shortcut || function (xtype, cls) { |
|
|
|
export function shortcut(xtype, cls) { |
|
|
|
if (kv[xtype] != null) { |
|
|
|
if (kv[xtype] != null) { |
|
|
|
_global.console && console.error("组件: [" + xtype + "] 已经注册过了"); |
|
|
|
_global.console && console.error("组件: [" + xtype + "] 已经注册过了"); |
|
|
|
} |
|
|
|
} |
|
|
@ -407,21 +407,22 @@ |
|
|
|
cls["xtype"] = xtype; |
|
|
|
cls["xtype"] = xtype; |
|
|
|
} |
|
|
|
} |
|
|
|
kv[xtype] = cls; |
|
|
|
kv[xtype] = cls; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI.shortcut = BI.component = BI.shortcut || shortcut; |
|
|
|
|
|
|
|
|
|
|
|
// 根据配置属性生成widget
|
|
|
|
// 根据配置属性生成widget
|
|
|
|
var createWidget = function (config, context, lazy) { |
|
|
|
const createRealWidget = function (config, context, lazy) { |
|
|
|
var cls = BI.isFunction(config.type) ? config.type : kv[config.type]; |
|
|
|
const cls = isFunction(config.type) ? config.type : kv[config.type]; |
|
|
|
|
|
|
|
|
|
|
|
if (!cls) { |
|
|
|
if (!cls) { |
|
|
|
throw new Error("组件: [" + config.type + "] 未定义"); |
|
|
|
throw new Error("组件: [" + config.type + "] 未定义"); |
|
|
|
} |
|
|
|
} |
|
|
|
var pushed = false; |
|
|
|
let pushed = false; |
|
|
|
var widget = new cls(); |
|
|
|
const widget = new cls(); |
|
|
|
widget._context = BI.Widget.context || context; |
|
|
|
widget._context = Widget.context || context; |
|
|
|
if (!BI.Widget.context && context) { |
|
|
|
if (!Widget.context && context) { |
|
|
|
pushed = true; |
|
|
|
pushed = true; |
|
|
|
BI.Widget.pushContext(context); |
|
|
|
Widget.pushContext(context); |
|
|
|
} |
|
|
|
} |
|
|
|
callPoint(widget, config.type); |
|
|
|
callPoint(widget, config.type); |
|
|
|
widget._initProps(config); |
|
|
|
widget._initProps(config); |
|
|
@ -430,13 +431,13 @@ |
|
|
|
// if (!lazy || config.element || config.root) {
|
|
|
|
// if (!lazy || config.element || config.root) {
|
|
|
|
widget._lazyConstructor(); |
|
|
|
widget._lazyConstructor(); |
|
|
|
// }
|
|
|
|
// }
|
|
|
|
pushed && BI.Widget.popContext(); |
|
|
|
pushed && Widget.popContext(); |
|
|
|
return widget; |
|
|
|
return widget; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
BI.createWidget = BI.createWidget || function (item, options, context, lazy) { |
|
|
|
export function createWidget(item, options, context, lazy) { |
|
|
|
item || (item = {}); |
|
|
|
item || (item = {}); |
|
|
|
if (BI.isWidget(options)) { |
|
|
|
if (isWidget(options)) { |
|
|
|
context = options; |
|
|
|
context = options; |
|
|
|
options = {}; |
|
|
|
options = {}; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -445,9 +446,9 @@ |
|
|
|
|
|
|
|
|
|
|
|
var el, w; |
|
|
|
var el, w; |
|
|
|
if (item.type || options.type) { |
|
|
|
if (item.type || options.type) { |
|
|
|
el = BI.extend({}, options, item); |
|
|
|
el = extend({}, options, item); |
|
|
|
} else if (item.el && (item.el.type || options.type)) { |
|
|
|
} else if (item.el && (item.el.type || options.type)) { |
|
|
|
el = BI.extend({}, options, item.el); |
|
|
|
el = extend({}, options, item.el); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (el) { |
|
|
|
if (el) { |
|
|
@ -456,14 +457,14 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 先把准备环境准备好
|
|
|
|
// 先把准备环境准备好
|
|
|
|
BI.init(); |
|
|
|
init(); |
|
|
|
|
|
|
|
|
|
|
|
if (BI.isEmpty(item) && BI.isEmpty(options)) { |
|
|
|
if (isEmpty(item) && isEmpty(options)) { |
|
|
|
return BI.createWidget({ |
|
|
|
return createWidget({ |
|
|
|
type: "bi.layout" |
|
|
|
type: "bi.layout" |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
if (BI.isWidget(item)) { |
|
|
|
if (isWidget(item)) { |
|
|
|
return item; |
|
|
|
return item; |
|
|
|
} |
|
|
|
} |
|
|
|
if (el) { |
|
|
|
if (el) { |
|
|
@ -471,56 +472,59 @@ |
|
|
|
var wType = (w.type && w.type.xtype) || w.type; |
|
|
|
var wType = (w.type && w.type.xtype) || w.type; |
|
|
|
if (wType === elType) { |
|
|
|
if (wType === elType) { |
|
|
|
if (BI.Plugin.hasObject(elType)) { |
|
|
|
if (BI.Plugin.hasObject(elType)) { |
|
|
|
if (!w.listeners || BI.isArray(w.listeners)) { |
|
|
|
if (!w.listeners || isArray(w.listeners)) { |
|
|
|
w.listeners = (w.listeners || []).concat([{ |
|
|
|
w.listeners = (w.listeners || []).concat([{ |
|
|
|
eventName: BI.Events.MOUNT, |
|
|
|
eventName: BI.Events.MOUNT, |
|
|
|
action: function () { |
|
|
|
action: () => { |
|
|
|
BI.Plugin.getObject(elType, this); |
|
|
|
BI.Plugin.getObject(elType, this); |
|
|
|
} |
|
|
|
} |
|
|
|
}]); |
|
|
|
}]); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
w.listeners[BI.Events.MOUNT] = [ |
|
|
|
w.listeners[BI.Events.MOUNT] = [ |
|
|
|
function () { |
|
|
|
() => { |
|
|
|
BI.Plugin.getObject(elType, this); |
|
|
|
BI.Plugin.getObject(elType, this); |
|
|
|
} |
|
|
|
} |
|
|
|
].concat(w.listeners[BI.Events.MOUNT] || []); |
|
|
|
].concat(w.listeners[BI.Events.MOUNT] || []); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return createWidget(w, context, lazy); |
|
|
|
return createRealWidget(w, context, lazy); |
|
|
|
} |
|
|
|
} |
|
|
|
return BI.createWidget(w, options, context, lazy); |
|
|
|
return createWidget(w, options, context, lazy); |
|
|
|
} |
|
|
|
} |
|
|
|
if (BI.isWidget(item.el)) { |
|
|
|
if (isWidget(item.el)) { |
|
|
|
return item.el; |
|
|
|
return item.el; |
|
|
|
} |
|
|
|
} |
|
|
|
throw new Error("组件:无法根据item创建组件", item); |
|
|
|
throw new Error("组件:无法根据item创建组件", item); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI.createWidget = BI.createWidget || createWidget; |
|
|
|
|
|
|
|
|
|
|
|
BI._lazyCreateWidget = BI._lazyCreateWidget || function (item, options, context) { |
|
|
|
export function _lazyCreateWidget (item, options, context) { |
|
|
|
return BI.createWidget(item, options, context, true); |
|
|
|
return createWidget(item, options, context, true); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI._lazyCreateWidget = BI._lazyCreateWidget || _lazyCreateWidget; |
|
|
|
|
|
|
|
|
|
|
|
BI.createElement = BI.createElement || function () { |
|
|
|
export function createElement() { |
|
|
|
var widget = BI.createWidget.apply(this, arguments); |
|
|
|
const widget = createWidget.apply(this, arguments); |
|
|
|
return widget.element; |
|
|
|
return widget.element; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
BI.createElement = BI.createElement || createElement; |
|
|
|
|
|
|
|
|
|
|
|
BI.getResource = BI.getResource || function (type, config) { |
|
|
|
export function getResource(type, config) { |
|
|
|
if (BI.isNotNull(constantInjection[type])) { |
|
|
|
if (isNotNull(constantInjection[type])) { |
|
|
|
return BI.Constants.getConstant(type); |
|
|
|
return Constants.getConstant(type); |
|
|
|
} |
|
|
|
} |
|
|
|
if (modelInjection[type]) { |
|
|
|
if (modelInjection[type]) { |
|
|
|
return BI.Models.getModel(type, config); |
|
|
|
return Models.getModel(type, config); |
|
|
|
} |
|
|
|
} |
|
|
|
if (storeInjection[type]) { |
|
|
|
if (storeInjection[type]) { |
|
|
|
return BI.Stores.getStore(type, config); |
|
|
|
return Stores.getStore(type, config); |
|
|
|
} |
|
|
|
} |
|
|
|
if (serviceInjection[type]) { |
|
|
|
if (serviceInjection[type]) { |
|
|
|
return BI.Services.getService(type, config); |
|
|
|
return Services.getService(type, config); |
|
|
|
} |
|
|
|
} |
|
|
|
if (providerInjection[type]) { |
|
|
|
if (providerInjection[type]) { |
|
|
|
return BI.Providers.getProvider(type, config); |
|
|
|
return Providers.getProvider(type, config); |
|
|
|
} |
|
|
|
} |
|
|
|
throw new Error("未知类型: [" + type + "] 未定义"); |
|
|
|
throw new Error("未知类型: [" + type + "] 未定义"); |
|
|
|
}; |
|
|
|
} |
|
|
|
})(); |
|
|
|
BI.getResource = BI.getResource || getResource; |
|
|
|