1 changed files with 45 additions and 0 deletions
@ -0,0 +1,45 @@ |
|||||
|
import { PConst } from '@/platform/PConst'; |
||||
|
import { Environment } from '@/platform/plugin/environment'; |
||||
|
import Axios from 'axios'; |
||||
|
import { JavascriptLoader } from '@/platform/utils'; |
||||
|
|
||||
|
class RemoteEntryManager { |
||||
|
/** |
||||
|
* 动态加载远程组件入口 JS 文件 |
||||
|
* @param callback 加载完成后的回调(当加载成功或失败后都会回调) |
||||
|
*/ |
||||
|
public static loadRemoteEntries(callback) { |
||||
|
if (Environment.isAloneFrontend()) { |
||||
|
const remoteEntries = Environment.getRemoteEntries(); |
||||
|
if (remoteEntries) { |
||||
|
const urls = []; |
||||
|
for (const key in remoteEntries) { |
||||
|
urls.push(Environment.getWebContextPath() + remoteEntries[key]); |
||||
|
} |
||||
|
console.debug('Loading remote entries ...', urls); |
||||
|
const loader = new JavascriptLoader((errorUrl) => { |
||||
|
callback(); |
||||
|
}); |
||||
|
loader.load(urls); |
||||
|
} |
||||
|
} else { |
||||
|
const axios = Axios.create({}); |
||||
|
axios.get(Environment.apiContextPath(PConst.API_REMOTE_ENTRY_URL)).then((response) => { |
||||
|
const remoteEntries = response.data.data; |
||||
|
if (remoteEntries) { |
||||
|
const urls = []; |
||||
|
for (const key in remoteEntries) { |
||||
|
urls.push(remoteEntries[key]); |
||||
|
} |
||||
|
console.debug('Loading remote entries ...', urls); |
||||
|
const loader = new JavascriptLoader((errorUrl) => { |
||||
|
callback(); |
||||
|
}); |
||||
|
loader.load(urls); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export { RemoteEntryManager }; |
Loading…
Reference in new issue