|
|
|
@ -81,25 +81,34 @@ export function syncLoadScript(uri) {
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const promises = {}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 默认的异步加载javascript方法 |
|
|
|
|
* @param uri |
|
|
|
|
* @returns {Promise<boolean>|Promise<unknown>} |
|
|
|
|
*/ |
|
|
|
|
export function loadScript(uri) { |
|
|
|
|
if (_LOADED[uri]) { |
|
|
|
|
return Promise.resolve(true); |
|
|
|
|
if (promises[uri]) { |
|
|
|
|
return Promise.all(promises[uri]); |
|
|
|
|
} |
|
|
|
|
return new Promise(resolve => { |
|
|
|
|
|
|
|
|
|
const promise = new Promise(resolve => { |
|
|
|
|
const script = document.createElement("script"); |
|
|
|
|
script.type = "application/javascript"; |
|
|
|
|
script.src = uri; |
|
|
|
|
script.onload = function() { |
|
|
|
|
_LOADED[uri] = true; |
|
|
|
|
resolve(true); |
|
|
|
|
}; |
|
|
|
|
script.src = uri; |
|
|
|
|
document.head.appendChild(script); |
|
|
|
|
_LOADED[uri] = true; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
promises[uri] ??= []; |
|
|
|
|
promises[uri].push(promise); |
|
|
|
|
|
|
|
|
|
return Promise.all(promises[uri]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|