jssdk 改成私有模块化加载器

This commit is contained in:
2betop 2020-06-28 11:50:09 +08:00
parent 8eb0e26e4e
commit 2724063947
2 changed files with 218 additions and 245 deletions

View File

@ -1,20 +1,14 @@
/**
* @file: mod.js
* @author fis
* ver: 1.0.13
* update: 2016/01/27
* https://github.com/fex-team/mod
* @file mod-sandbox.js.
*/
var require;
/* eslint-disable no-unused-vars */
var define;
/* eslint-disable */
(function (global) {
var require, define;
var amis = window.amis || {};
// 避免重复加载而导致已定义模块丢失
if (require) {
if (amis.require) {
return;
}
@ -27,7 +21,6 @@ var define;
var pkgMap = {};
var createScripts = function (queues, onerror) {
var docFrag = document.createDocumentFragment();
for (var i = 0, len = queues.length; i < len; i++) {
@ -58,10 +51,12 @@ var define;
if ('onload' in script) {
script.onload = onload;
}
else {
} else {
script.onreadystatechange = function () {
if (this.readyState === 'loaded' || this.readyState === 'complete') {
if (
this.readyState === 'loaded' ||
this.readyState === 'complete'
) {
onload();
}
};
@ -93,8 +88,7 @@ var define;
if (pkg) {
url = pkgMap[pkg].url || pkgMap[pkg].uri;
}
else {
} else {
url = res.url || res.uri || id;
}
@ -121,7 +115,6 @@ var define;
};
require = function (id) {
// compatible with require([dep, dep2...]) syntax.
if (id && id.splice) {
return require.async.apply(this, arguments);
@ -149,7 +142,10 @@ var define;
//
// factory: function OR value
//
var ret = (typeof factory === 'function') ? factory.apply(mod, [require, mod.exports, mod]) : factory;
var ret =
typeof factory === 'function'
? factory.apply(mod, [require, mod.exports, mod])
: factory;
if (ret) {
mod.exports = ret;
@ -256,29 +252,6 @@ var define;
head.appendChild(script);
};
require.loadCss = function (cfg) {
if (cfg.content) {
var sty = document.createElement('style');
sty.type = 'text/css';
if (sty.styleSheet) { // IE
sty.styleSheet.cssText = cfg.content;
}
else {
sty.innerHTML = cfg.content;
}
head.appendChild(sty);
}
else if (cfg.url) {
var link = document.createElement('link');
link.href = cfg.url;
link.rel = 'stylesheet';
link.type = 'text/css';
head.appendChild(link);
}
};
require.alias = function (id) {
return id.replace(/\.js$/i, '');
};
@ -288,5 +261,5 @@ var define;
amis.require = require;
amis.define = define;
window.amis = amis;
// window.require = window.require || require;
})(this);

View File

@ -7,7 +7,7 @@ export interface ApiObject {
withCredentials?: boolean;
cancelExecutor?: (cancel: Function) => void;
};
autoRefresh: boolean; // 是否自动刷新,当 url 中的取值结果变化时,自动刷新数据。
autoRefresh?: boolean; // 是否自动刷新,当 url 中的取值结果变化时,自动刷新数据。
reload?: string;
sendOn?: string;
adaptor?: (payload: object, response: fetcherResult, api: ApiObject) => any;