Browse Source

widget也支持埋点

es6
guy 3 years ago
parent
commit
8f0bd55e82
  1. 99
      src/core/5.inject.js
  2. 98
      src/core/5.shortcut.js
  3. 0
      src/core/plugin.js
  4. 0
      src/core/popper.js
  5. 0
      src/core/worker.js
  6. 2
      webpack/attachments.js

99
src/core/6.inject.js → src/core/5.inject.js

@ -92,7 +92,7 @@
}; };
var configFunctions = {}; var configFunctions = {};
var runConfigFunction = BI.runConfigFunction = function (type) { var runConfigFunction = function (type) {
if (!type || !configFunctions[type]) { if (!type || !configFunctions[type]) {
return false; return false;
} }
@ -371,6 +371,103 @@
} }
}; };
var kv = {};
BI.shortcut = BI.component = BI.shortcut || function (xtype, cls) {
if (kv[xtype] != null) {
_global.console && console.error("组件: [" + xtype + "] 已经注册过了");
}
if (cls) {
cls["xtype"] = xtype;
}
kv[xtype] = cls;
};
// 根据配置属性生成widget
var createWidget = function (config, context, lazy) {
var cls = kv[config.type];
if (!cls) {
throw new Error("组件: [" + config.type + "] 未定义");
}
var pushed = false;
var widget = new cls();
widget._context = BI.Widget.context || context;
if (!BI.Widget.context && context) {
pushed = true;
BI.Widget.pushContext(context);
}
callPoint(widget, config.type);
widget._initProps(config);
widget._initRoot();
widget._constructed();
// if (!lazy || config.element || config.root) {
widget._lazyConstructor();
// }
pushed && BI.Widget.popContext();
return widget;
};
BI.createWidget = BI.createWidget || function (item, options, context, lazy) {
item || (item = {});
if (BI.isWidget(options)) {
context = options;
options = {};
} else {
options || (options = {});
}
var el, w;
if (item.type || options.type) {
el = BI.extend({}, options, item);
} else if (item.el && (item.el.type || options.type)) {
el = BI.extend({}, options, item.el);
}
if (el) {
runConfigFunction(el.type);
}
// 先把准备环境准备好
BI.init();
if (BI.isEmpty(item) && BI.isEmpty(options)) {
return BI.createWidget({
type: "bi.layout"
});
}
if (BI.isWidget(item)) {
return item;
}
if (el) {
w = BI.Plugin.getWidget(el.type, el);
if (w.type === el.type) {
if (BI.Plugin.hasObject(el.type)) {
w.listeners = (w.listeners || []).concat([{
eventName: BI.Events.MOUNT,
action: function () {
BI.Plugin.getObject(el.type, this);
}
}]);
}
return createWidget(w, context, lazy);
}
return BI.createWidget(w, options, context, lazy);
}
if (BI.isWidget(item.el)) {
return item.el;
}
throw new Error("组件:无法根据item创建组件", item);
};
BI._lazyCreateWidget = BI._lazyCreateWidget || function (item, options, context) {
return BI.createWidget(item, options, context, true);
};
BI.createElement = BI.createElement || function () {
var widget = BI.createWidget.apply(this, arguments);
return widget.element;
};
BI.getResource = BI.getResource || function (type, config) { BI.getResource = BI.getResource || function (type, config) {
if (BI.isNotNull(constantInjection[type])) { if (BI.isNotNull(constantInjection[type])) {
return BI.Constants.getConstant(type); return BI.Constants.getConstant(type);

98
src/core/5.shortcut.js

@ -1,98 +0,0 @@
(function () {
var kv = {};
BI.shortcut = BI.component = BI.shortcut || function (xtype, cls) {
if (kv[xtype] != null) {
_global.console && console.error("组件: [" + xtype + "] 已经注册过了");
}
if (cls) {
cls["xtype"] = xtype;
}
kv[xtype] = cls;
};
// 根据配置属性生成widget
var createWidget = function (config, context, lazy) {
var cls = kv[config.type];
if (!cls) {
throw new Error("组件: [" + config.type + "] 未定义");
}
var pushed = false;
var widget = new cls();
widget._context = BI.Widget.context || context;
if (!BI.Widget.context && context) {
pushed = true;
BI.Widget.pushContext(context);
}
widget._initProps(config);
widget._initRoot();
widget._constructed();
// if (!lazy || config.element || config.root) {
widget._lazyConstructor();
// }
pushed && BI.Widget.popContext();
return widget;
};
BI.createWidget = BI.createWidget || function (item, options, context, lazy) {
item || (item = {});
if (BI.isWidget(options)) {
context = options;
options = {};
} else {
options || (options = {});
}
var el, w;
if (item.type || options.type) {
el = BI.extend({}, options, item);
} else if (item.el && (item.el.type || options.type)) {
el = BI.extend({}, options, item.el);
}
if (el) {
BI.runConfigFunction(el.type);
}
// 先把准备环境准备好
BI.init();
if (BI.isEmpty(item) && BI.isEmpty(options)) {
return BI.createWidget({
type: "bi.layout"
});
}
if (BI.isWidget(item)) {
return item;
}
if (el) {
w = BI.Plugin.getWidget(el.type, el);
if (w.type === el.type) {
if (BI.Plugin.hasObject(el.type)) {
w.listeners = (w.listeners || []).concat([{
eventName: BI.Events.MOUNT,
action: function () {
BI.Plugin.getObject(el.type, this);
}
}]);
}
return createWidget(w, context, lazy);
}
return BI.createWidget(w, options, context, lazy);
}
if (BI.isWidget(item.el)) {
return item.el;
}
throw new Error("组件:无法根据item创建组件", item);
};
BI._lazyCreateWidget = BI._lazyCreateWidget || function (item, options, context) {
return BI.createWidget(item, options, context, true);
};
BI.createElement = BI.createElement || function () {
var widget = BI.createWidget.apply(this, arguments);
return widget.element;
};
})();

0
src/core/7.plugin.js → src/core/plugin.js

0
src/core/8.popper.js → src/core/popper.js

0
src/core/9.worker.js → src/core/worker.js

2
webpack/attachments.js

@ -60,7 +60,7 @@ const basicAttachmentMap = {
"src/core/func/**/*.js", "src/core/func/**/*.js",
"src/core/2.base.js", "src/core/2.base.js",
"src/core/3.ob.js", "src/core/3.ob.js",
"src/core/6.inject.js", "src/core/5.inject.js",
"src/core/utils/*.js", "src/core/utils/*.js",
"i18n/i18n.cn.js", "i18n/i18n.cn.js",
"_mobile/date.i18n.cn.js", "_mobile/date.i18n.cn.js",

Loading…
Cancel
Save