You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
const pageModules = Object.freeze({
|
|
instances: '/cloud/instances.js',
|
|
detail: '/cloud/detail.js',
|
|
deploy: '/cloud/deploy.js',
|
|
backups: '/cloud/backups.js',
|
|
'cloud-snapshots': '/cloud/cloud-snapshots.js',
|
|
vpcs: '/cloud/vpcs.js',
|
|
isos: '/cloud/iso-images.js',
|
|
keys: '/cloud/ssh-keys.js',
|
|
invoices: '/cloud/invoices.js',
|
|
'invoice-detail': '/cloud/invoice-detail.js',
|
|
reinstall: '/cloud/reinstall.js',
|
|
});
|
|
|
|
const page = document.body.dataset.cloudPage || '';
|
|
const assetVersion = new URL(import.meta.url).searchParams.get('v');
|
|
|
|
function versionedModuleUrl(path) {
|
|
const url = new URL(path, import.meta.url);
|
|
url.search = '';
|
|
if (assetVersion) url.searchParams.set('v', assetVersion);
|
|
return url.href;
|
|
}
|
|
|
|
function showPageError(message) {
|
|
const target = document.getElementById('cloud-page-error');
|
|
if (target) {
|
|
target.textContent = message;
|
|
target.hidden = false;
|
|
}
|
|
}
|
|
|
|
async function initializeCloudApp() {
|
|
const { initializeTaskCenter } = await import(versionedModuleUrl('./task-center.js'));
|
|
initializeTaskCenter();
|
|
|
|
const modulePath = pageModules[page];
|
|
if (!modulePath) {
|
|
showPageError('页面类型无效,请返回实例列表。');
|
|
return;
|
|
}
|
|
|
|
const module = await import(versionedModuleUrl(modulePath));
|
|
module.initialize();
|
|
}
|
|
|
|
initializeCloudApp().catch(error => {
|
|
showPageError(error?.message || '页面加载失败,请刷新后重试。');
|
|
});
|