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.
56 lines
1.7 KiB
JavaScript
56 lines
1.7 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',
|
|
traffic: '/cloud/traffic.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 modulePath = pageModules[page];
|
|
if (!modulePath) {
|
|
showPageError('页面类型无效,请返回实例列表。');
|
|
return;
|
|
}
|
|
|
|
const module = await import(versionedModuleUrl(modulePath));
|
|
await module.initialize();
|
|
}
|
|
|
|
// The page and task drawer are independent: a slow drawer must not delay the page.
|
|
void import(versionedModuleUrl('./task-center.js')).then(module => {
|
|
module.initializeTaskCenter();
|
|
}).catch(() => {
|
|
const target = document.getElementById('panel-task-state');
|
|
if (target) target.textContent = '任务中心暂时无法加载,请刷新页面重试。';
|
|
});
|
|
|
|
initializeCloudApp().catch(error => {
|
|
showPageError(error?.message || '页面加载失败,请刷新后重试。');
|
|
});
|