diff --git a/packages/fineui/src/core/platform/web/load.js b/packages/fineui/src/core/platform/web/load.js index 6dd203ea1..d010bdb54 100644 --- a/packages/fineui/src/core/platform/web/load.js +++ b/packages/fineui/src/core/platform/web/load.js @@ -81,25 +81,34 @@ export function syncLoadScript(uri) { return false; } + +const promises = {}; + /** * 默认的异步加载javascript方法 * @param uri * @returns {Promise|Promise} */ 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]); } /** diff --git a/packages/fineui/typescript/core/base.ts b/packages/fineui/typescript/core/base.ts index abdd7ba80..5b4a86af3 100644 --- a/packages/fineui/typescript/core/base.ts +++ b/packages/fineui/typescript/core/base.ts @@ -266,7 +266,7 @@ export declare function isNull(obj: any): obj is (undefined | null); export declare function isEmptyArray(arr: T[] | U): arr is T[] & { length: 0 }; -export declare function isNotEmptyArray(arr: T[] | U): arr is [T, ...T[]]; +export declare function isNotEmptyArray(arr: T[]): arr is NonNullable[]; export declare function isEmptyObject(obj: any): boolean; diff --git a/packages/fineui/typescript/core/platform/web/load.ts b/packages/fineui/typescript/core/platform/web/load.ts index 144150ff5..cef294db8 100644 --- a/packages/fineui/typescript/core/platform/web/load.ts +++ b/packages/fineui/typescript/core/platform/web/load.ts @@ -1 +1,3 @@ export declare function $import(src: string, ext?: string, must?: boolean): void + +export declare function loadResource(opt: { src: string, extension?: string, async?: boolean }): Promise