|
|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
// PHP owns authentication, authorisation, ownership and purchasing. No engine
|
|
|
|
|
// address, token, host credential or unrestricted create API exists in this UI.
|
|
|
|
|
const byId = (id) => document.getElementById(id);
|
|
|
|
|
const state = { csrfToken: '', userId: '', username: '', admin: false, vms: [], plans: [], sshKeys: [], templates: [], resources: null, selectedRegionHostId: '', invoices: [], invoicePaymentMethods: [], selectedInvoice: null, selectedInvoicePaymentMethod: '', invoiceJobProgress: new Map(), invoicePollTimers: new Map(), view: 'list', selectedVmId: null, detailTab: 'operations', metricsRange: '24h', metricsPayload: null, metricsRequest: null, metricsPollTimer: null, metricsResizeTimer: null, trafficDailyPayload: null, trafficDailyVmId: '', trafficDailyRequest: null, trafficDailyResizeTimer: null, trafficDailyLoadedAt: 0, credentialPassword: '', credentialVisible: false, credentialTimer: null, rfb: null, consoleToken: 0, loadingVMs: false, selectedKeys: { create: '', reinstall: '' }, formEpoch: 0, resourceController: null, mutationBusy: false, provisionIdempotency: '', provisionFingerprint: '', rescueActive: false, rescueStaged: false };
|
|
|
|
|
const state = { csrfToken: '', userId: '', username: '', admin: false, vms: [], plans: [], sshKeys: [], templates: [], resources: null, selectedRegionHostId: '', invoices: [], invoicePage: 1, invoicePagination: { page: 1, per_page: 10, total: 0, total_pages: 1, has_previous: false, has_next: false, from: 0, to: 0 }, invoiceLoading: false, invoiceLoadPromise: null, invoicePaymentMethods: [], selectedInvoice: null, selectedInvoicePaymentMethod: '', invoiceJobProgress: new Map(), invoicePollTimers: new Map(), view: 'list', selectedVmId: null, detailTab: 'operations', metricsRange: '24h', metricsPayload: null, metricsRequest: null, metricsPollTimer: null, metricsResizeTimer: null, trafficDailyPayload: null, trafficDailyVmId: '', trafficDailyRequest: null, trafficDailyResizeTimer: null, trafficDailyLoadedAt: 0, credentialPassword: '', credentialVisible: false, credentialTimer: null, rfb: null, consoleToken: 0, loadingVMs: false, selectedKeys: { create: '', reinstall: '' }, formEpoch: 0, resourceController: null, mutationBusy: false, provisionIdempotency: '', provisionFingerprint: '', rescueActive: false, rescueStaged: false };
|
|
|
|
|
// Keep the historical storage key so an interrupted deployment made just
|
|
|
|
|
// before an online update can still reconcile to the same opening invoice.
|
|
|
|
|
const PROVISION_INVOICE_STORAGE_PREFIX = 'virt-cloud:pending-order:';
|
|
|
|
|
@ -10,7 +10,6 @@ const CLOUD_PATHS = Object.freeze({
|
|
|
|
|
instances: '/user/cloud/instances',
|
|
|
|
|
deploy: '/user/cloud/deploy',
|
|
|
|
|
keys: '/user/cloud/ssh-keys',
|
|
|
|
|
isos: '/user/cloud/iso-images',
|
|
|
|
|
invoices: '/user/cloud/invoices',
|
|
|
|
|
});
|
|
|
|
|
const vmPagePath = (id, child = '') => `${CLOUD_PATHS.instances}/${encodeURIComponent(String(id))}${child ? `/${child}` : ''}`;
|
|
|
|
|
@ -175,6 +174,31 @@ async function loadVms() {
|
|
|
|
|
catch (error) { showError('cloud-page-error', error.message); if (!state.vms.length && byId('vm-table-body')) renderVMs(true); }
|
|
|
|
|
finally { state.loadingVMs = false; }
|
|
|
|
|
}
|
|
|
|
|
async function loadVm(apiId = selectedVm()?.api_id || document.body.dataset.vmId, raise = false) {
|
|
|
|
|
const id = String(apiId || '');
|
|
|
|
|
if (!id) {
|
|
|
|
|
const error = new Error('虚拟机标识缺失。');
|
|
|
|
|
showError('cloud-page-error', error.message);
|
|
|
|
|
if (raise) throw error;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (state.loadingVMs) return selectedVm() || null;
|
|
|
|
|
state.loadingVMs = true;
|
|
|
|
|
try {
|
|
|
|
|
const vm = normalizeVm(await api(`/api/v1/vms/${encodeURIComponent(id)}`));
|
|
|
|
|
state.vms = [vm];
|
|
|
|
|
state.selectedVmId = vm.uuid;
|
|
|
|
|
showError('cloud-page-error', '');
|
|
|
|
|
if (state.view === 'detail') renderVmDetail(vm);
|
|
|
|
|
return vm;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
showError('cloud-page-error', error.message);
|
|
|
|
|
if (raise) throw error;
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
state.loadingVMs = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function renderVmDetail(vm) {
|
|
|
|
|
text('vm-detail-name', vm.name); text('vm-detail-state', stateLabel(vm.state)); byId('vm-detail-state').className = `state-pill ${stateCategory(vm.state)}`;
|
|
|
|
|
for (const id of ['vm-detail-region', 'vm-detail-header-region']) text(id, vmRegion(vm));
|
|
|
|
|
@ -227,7 +251,7 @@ function renderVmService(vm) {
|
|
|
|
|
progress.classList.remove('is-exhausted');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
async function powerAction(action, dangerous = false) { const vm = selectedVm(); if (!vm?.can_operate) return toast('实例服务已到期或正在执行策略,日常操作暂不可用。', 'error'); if (state.mutationBusy) return; if (dangerous && !confirm('此操作会强制断电,可能丢失未保存的数据。确认继续?')) return; state.mutationBusy = true; setDetailBusy(true); try { const result = await api(`${vmPath()}/actions`, { method: 'POST', body: { action } }); toast('电源任务已提交,正在执行…'); if (result.job_id) await pollJob('power', result.job_id); toast('电源操作已完成。', 'success'); await loadVms(); } catch (error) { toast(error.message, 'error'); } finally { state.mutationBusy = false; setDetailBusy(false); } }
|
|
|
|
|
async function powerAction(action, dangerous = false) { const vm = selectedVm(); if (!vm?.can_operate) return toast('实例服务已到期或正在执行策略,日常操作暂不可用。', 'error'); if (state.mutationBusy) return; if (dangerous && !confirm('此操作会强制断电,可能丢失未保存的数据。确认继续?')) return; state.mutationBusy = true; setDetailBusy(true); try { const result = await api(`${vmPath()}/actions`, { method: 'POST', body: { action } }); toast('电源任务已提交,正在执行…'); if (result.job_id) await pollJob('power', result.job_id); toast('电源操作已完成。', 'success'); await loadVm(vm.api_id); } catch (error) { toast(error.message, 'error'); } finally { state.mutationBusy = false; setDetailBusy(false); } }
|
|
|
|
|
async function deleteVm() { const vm = selectedVm(); if (!vm?.can_delete) return toast('当前账户无权删除该实例。', 'error'); if (state.mutationBusy) return; const confirmation = prompt(`永久删除“${vm.name}”及面板管理的虚拟磁盘,此操作不可恢复。请输入完整虚拟机名称确认:`); if (confirmation === null) return; if (confirmation !== vm.name) return toast('虚拟机名称不匹配,未执行删除。', 'error'); state.mutationBusy = true; setDetailBusy(true); try { const result = await api(vmPath(vm), { method: 'DELETE', body: { confirmation_name: vm.name, delete_disks: true } }); toast('删除任务已提交,正在执行…'); if (result.job_id) await pollJob('delete', result.job_id); navigate(CLOUD_PATHS.instances); } catch (error) { toast(error.message, 'error'); } finally { state.mutationBusy = false; setDetailBusy(false); } }
|
|
|
|
|
function setDetailBusy(busy) { if (!busy && selectedVm()) renderVmDetail(selectedVm()); else if (busy) document.querySelectorAll('#vm-detail-primary-actions button,#vm-detail-danger-actions button').forEach(button => { button.disabled = true; }); }
|
|
|
|
|
async function credential(copy = false) {
|
|
|
|
|
@ -253,7 +277,6 @@ function renderKeyCards(kind) {
|
|
|
|
|
for (const key of state.sshKeys) { const button = makeElement('button', 'ssh-key-option'); button.type = 'button'; button.setAttribute('aria-pressed', String(state.selectedKeys[kind] === String(key.id))); button.append(makeElement('strong', 'ssh-key-choice-label', key.name)); button.addEventListener('click', () => { state.selectedKeys[kind] = state.selectedKeys[kind] === String(key.id) ? '' : String(key.id); renderKeyCards(kind); }); container.append(button); }
|
|
|
|
|
if (!state.sshKeys.length) container.append(makeElement('p', 'muted', '暂无公钥,可先到“公钥管理”添加。不选公钥也会生成强密码。'));
|
|
|
|
|
}
|
|
|
|
|
function sourceMode() { return byId('create-form')?.querySelector('[name="source"]:checked')?.value || 'cloud'; }
|
|
|
|
|
function flagForCountry(code) {
|
|
|
|
|
const normalized = String(code || '').trim().toUpperCase();
|
|
|
|
|
if (!/^[A-Z]{2}$/.test(normalized)) return '🌐';
|
|
|
|
|
@ -281,20 +304,9 @@ function setDeploymentStepEnabled(id, enabled) {
|
|
|
|
|
function updateCreateAvailability() {
|
|
|
|
|
const plan = state.plans.find(item => String(item.id) === byId('vm-plan')?.value);
|
|
|
|
|
const validHost = plan && String(plan.host_id) === state.selectedRegionHostId;
|
|
|
|
|
const validMedia = sourceMode() === 'cloud' ? Boolean(byId('vm-template')?.value) : Boolean(byId('vm-iso')?.value);
|
|
|
|
|
const validMedia = Boolean(byId('vm-template')?.value);
|
|
|
|
|
if (byId('create-submit')) byId('create-submit').disabled = state.mutationBusy || !validHost || !state.resources || !validMedia;
|
|
|
|
|
}
|
|
|
|
|
function updateSource() {
|
|
|
|
|
if (state.mutationBusy) return;
|
|
|
|
|
const cloud = sourceMode() === 'cloud';
|
|
|
|
|
byId('vm-iso-field').hidden = cloud;
|
|
|
|
|
byId('vm-iso').disabled = cloud || !state.resources;
|
|
|
|
|
byId('vm-template-field').hidden = !cloud;
|
|
|
|
|
byId('vm-template').disabled = !cloud || !state.resources;
|
|
|
|
|
byId('vm-cloud-fields').hidden = !cloud;
|
|
|
|
|
byId('vm-root-password').disabled = !cloud || !state.resources;
|
|
|
|
|
updateCreateAvailability();
|
|
|
|
|
}
|
|
|
|
|
function strongPassword(value) { return !value || (value.length >= 12 && new TextEncoder().encode(value).length <= 256 && /[A-Z]/.test(value) && /[a-z]/.test(value) && /[0-9]/.test(value) && /[^A-Za-z0-9\s]/.test(value) && !/[\r\n\0]/.test(value)); }
|
|
|
|
|
function formatUsd(value) {
|
|
|
|
|
const amount = Number(value);
|
|
|
|
|
@ -322,16 +334,13 @@ function planBillingLabel(plan) {
|
|
|
|
|
const traffic = planTrafficBytes(plan);
|
|
|
|
|
return `${days === null ? '账期未提供' : `${Math.floor(days)} 天/期`} · ${traffic === null ? '每期流量未提供' : `每期流量 ${formatTrafficQuota(traffic)}`}`;
|
|
|
|
|
}
|
|
|
|
|
function resetInstallChoices(message = '请先选择实例规格。') {
|
|
|
|
|
function resetInstallChoices() {
|
|
|
|
|
state.resourceController?.abort();
|
|
|
|
|
state.resourceController = null;
|
|
|
|
|
state.resources = null;
|
|
|
|
|
state.templates = [];
|
|
|
|
|
byId('vm-template').value = '';
|
|
|
|
|
byId('vm-iso').value = '';
|
|
|
|
|
renderTemplateCatalog('vm-template');
|
|
|
|
|
byId('vm-iso-catalog').replaceChildren(makeElement('p', 'template-catalog-empty', message));
|
|
|
|
|
byId('create-form').querySelectorAll('[name="source"]').forEach(radio => { radio.disabled = true; });
|
|
|
|
|
byId('vm-name').disabled = true;
|
|
|
|
|
byId('vm-root-password').disabled = true;
|
|
|
|
|
setDeploymentStepEnabled('vm-source-step', false);
|
|
|
|
|
@ -386,37 +395,6 @@ function renderPlanPicker() {
|
|
|
|
|
});
|
|
|
|
|
container.replaceChildren(header, ...rows);
|
|
|
|
|
}
|
|
|
|
|
function renderUserIsoCatalog(records) {
|
|
|
|
|
const input = byId('vm-iso');
|
|
|
|
|
const container = byId('vm-iso-catalog');
|
|
|
|
|
const isos = Array.isArray(records) ? records.filter(item => item && /^[0-9a-f]{32}$/.test(String(item.id || ''))) : [];
|
|
|
|
|
if (!isos.some(item => String(item.id) === input.value)) input.value = '';
|
|
|
|
|
const cards = isos.map(record => {
|
|
|
|
|
const id = String(record.id);
|
|
|
|
|
const button = makeElement('button', 'user-iso-option');
|
|
|
|
|
button.type = 'button';
|
|
|
|
|
button.dataset.isoId = id;
|
|
|
|
|
button.setAttribute('aria-pressed', String(input.value === id));
|
|
|
|
|
button.setAttribute('aria-label', `选择 ISO ${record.name || id}`);
|
|
|
|
|
button.append(makeElement('span', 'user-iso-symbol', '◉'), makeElement('strong', '', record.name || '未命名 ISO'), makeElement('small', '', formatBytes(firstNumber(record.size_bytes))));
|
|
|
|
|
button.addEventListener('click', () => {
|
|
|
|
|
input.value = id;
|
|
|
|
|
container.querySelectorAll('.user-iso-option').forEach(option => option.setAttribute('aria-pressed', String(option.dataset.isoId === id)));
|
|
|
|
|
showError('create-error', '');
|
|
|
|
|
updateCreateAvailability();
|
|
|
|
|
});
|
|
|
|
|
return button;
|
|
|
|
|
});
|
|
|
|
|
if (!cards.length) {
|
|
|
|
|
const empty = makeElement('div', 'template-catalog-empty user-iso-empty');
|
|
|
|
|
empty.append(makeElement('span', '', '你的全局个人库还没有 ISO。'));
|
|
|
|
|
const link = makeElement('a', 'ssh-key-picker-manage', '前往 ISO 上传');
|
|
|
|
|
link.href = CLOUD_PATHS.isos;
|
|
|
|
|
empty.append(link);
|
|
|
|
|
cards.push(empty);
|
|
|
|
|
}
|
|
|
|
|
container.replaceChildren(...cards);
|
|
|
|
|
}
|
|
|
|
|
async function selectRegion(hostId) {
|
|
|
|
|
if (state.mutationBusy) return;
|
|
|
|
|
const normalized = String(hostId || '');
|
|
|
|
|
@ -428,7 +406,7 @@ async function selectRegion(hostId) {
|
|
|
|
|
renderRegionPicker();
|
|
|
|
|
renderPlanPicker();
|
|
|
|
|
setDeploymentStepEnabled('vm-plan-step', true);
|
|
|
|
|
resetInstallChoices('请选择实例规格后加载你的全局个人 ISO。');
|
|
|
|
|
resetInstallChoices();
|
|
|
|
|
showError('create-error', '');
|
|
|
|
|
}
|
|
|
|
|
async function selectPlan(planId) {
|
|
|
|
|
@ -454,7 +432,7 @@ async function loadPlanResources() {
|
|
|
|
|
const planId = byId('vm-plan').value;
|
|
|
|
|
const plan = state.plans.find(item => String(item.id) === planId && String(item.host_id) === state.selectedRegionHostId);
|
|
|
|
|
const epoch = ++state.formEpoch;
|
|
|
|
|
resetInstallChoices('正在加载全局个人 ISO…');
|
|
|
|
|
resetInstallChoices();
|
|
|
|
|
state.resourceController = new AbortController();
|
|
|
|
|
if (!plan) return;
|
|
|
|
|
try {
|
|
|
|
|
@ -463,12 +441,12 @@ async function loadPlanResources() {
|
|
|
|
|
state.resources = resources;
|
|
|
|
|
state.templates = items(resources.templates || resources.cloud_templates);
|
|
|
|
|
renderTemplateCatalog('vm-template');
|
|
|
|
|
renderUserIsoCatalog(items(resources.user_isos));
|
|
|
|
|
byId('create-form').querySelectorAll('[name="source"]').forEach(radio => { radio.disabled = false; });
|
|
|
|
|
byId('vm-template').disabled = false;
|
|
|
|
|
byId('vm-name').disabled = false;
|
|
|
|
|
byId('vm-root-password').disabled = false;
|
|
|
|
|
setDeploymentStepEnabled('vm-source-step', true);
|
|
|
|
|
setDeploymentStepEnabled('vm-config-step', true);
|
|
|
|
|
updateSource();
|
|
|
|
|
updateCreateAvailability();
|
|
|
|
|
} catch (error) { if (epoch === state.formEpoch && error.name !== 'AbortError') showError('create-error', error.message); }
|
|
|
|
|
}
|
|
|
|
|
function provisionInvoiceStorageKey() { return `${PROVISION_INVOICE_STORAGE_PREFIX}${state.userId || 'unknown'}`; }
|
|
|
|
|
@ -525,10 +503,9 @@ async function existingProvisionInvoice(key) {
|
|
|
|
|
}
|
|
|
|
|
async function buy(event) {
|
|
|
|
|
event.preventDefault(); if (state.mutationBusy) return;
|
|
|
|
|
const cloud = sourceMode() === 'cloud'; const password = byId('vm-root-password').value;
|
|
|
|
|
if (cloud && !strongPassword(password)) return showError('create-error', '密码需至少 12 个字符,包含大写、小写、数字和符号。');
|
|
|
|
|
if (cloud && !byId('vm-template').value) return showError('create-error', '请选择系统镜像版本。');
|
|
|
|
|
if (!cloud && !/^[0-9a-f]{32}$/.test(byId('vm-iso').value)) return showError('create-error', '请选择自己上传的安装 ISO。');
|
|
|
|
|
const password = byId('vm-root-password').value;
|
|
|
|
|
if (!strongPassword(password)) return showError('create-error', '密码需至少 12 个字符,包含大写、小写、数字和符号。');
|
|
|
|
|
if (!byId('vm-template').value) return showError('create-error', '请选择系统镜像版本。');
|
|
|
|
|
if (!byId('vm-plan').value || !state.resources) return showError('create-error', '请先选择可用套餐。');
|
|
|
|
|
const selectedPlan = state.plans.find(plan => String(plan.id) === byId('vm-plan').value);
|
|
|
|
|
if (!selectedPlan || String(selectedPlan.host_id) !== state.selectedRegionHostId) return showError('create-error', '地区与实例规格不匹配,请重新选择。');
|
|
|
|
|
@ -538,8 +515,9 @@ async function buy(event) {
|
|
|
|
|
const formBody = byId('create-form')?.querySelector('.workspace-form-body');
|
|
|
|
|
if (formBody) { formBody.inert = true; formBody.setAttribute('aria-busy', 'true'); }
|
|
|
|
|
byId('create-submit').disabled = true; showError('create-error', '');
|
|
|
|
|
const body = { plan_id: Number(byId('vm-plan').value), name: byId('vm-name').value.trim(), source: sourceMode() };
|
|
|
|
|
if (cloud) { body.template_id = byId('vm-template').value; if (state.selectedKeys.create) body.guest_ssh_key_id = state.selectedKeys.create; if (password) body.root_password = password; } else body.iso_id = byId('vm-iso').value;
|
|
|
|
|
const body = { plan_id: Number(byId('vm-plan').value), name: byId('vm-name').value.trim(), source: 'cloud', template_id: byId('vm-template').value };
|
|
|
|
|
if (state.selectedKeys.create) body.guest_ssh_key_id = state.selectedKeys.create;
|
|
|
|
|
if (password) body.root_password = password;
|
|
|
|
|
try {
|
|
|
|
|
const fingerprint = await provisionInvoiceFingerprint(body);
|
|
|
|
|
const invoiceIdempotency = await pendingProvisionInvoiceKey(fingerprint);
|
|
|
|
|
@ -888,6 +866,26 @@ function renderInvoices() {
|
|
|
|
|
row.append(detail, actions, amount); container.append(row);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function renderInvoicePagination() {
|
|
|
|
|
const navigation = byId('invoices-pagination');
|
|
|
|
|
if (!navigation) return;
|
|
|
|
|
const pagination = state.invoicePagination || {};
|
|
|
|
|
const page = Math.max(1, Number(pagination.page) || 1);
|
|
|
|
|
const totalPages = Math.max(1, Number(pagination.total_pages) || 1);
|
|
|
|
|
const total = Math.max(0, Number(pagination.total) || 0);
|
|
|
|
|
navigation.hidden = total === 0;
|
|
|
|
|
navigation.setAttribute('aria-busy', String(state.invoiceLoading));
|
|
|
|
|
text('invoices-page-label', `第 ${page} / ${totalPages} 页 · 共 ${total} 条`);
|
|
|
|
|
const previous = byId('invoices-previous');
|
|
|
|
|
const next = byId('invoices-next');
|
|
|
|
|
if (previous) previous.disabled = state.invoiceLoading || !pagination.has_previous;
|
|
|
|
|
if (next) next.disabled = state.invoiceLoading || !pagination.has_next;
|
|
|
|
|
const refresh = byId('invoices-refresh');
|
|
|
|
|
if (refresh) {
|
|
|
|
|
refresh.disabled = state.invoiceLoading;
|
|
|
|
|
refresh.setAttribute('aria-busy', String(state.invoiceLoading));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function renderInvoiceSpecification(invoice) {
|
|
|
|
|
const panel = byId('invoice-specification-panel');
|
|
|
|
|
const container = byId('invoice-specification');
|
|
|
|
|
@ -1029,15 +1027,48 @@ async function loadInvoiceDetail(invoiceId = document.body.dataset.invoiceId) {
|
|
|
|
|
renderInvoiceDetail(payload.invoice, payload); showError('cloud-page-error', ''); return payload.invoice;
|
|
|
|
|
} catch (error) { showError('cloud-page-error', error.message); throw error; }
|
|
|
|
|
}
|
|
|
|
|
async function loadInvoices() {
|
|
|
|
|
async function loadInvoices(page = state.invoicePage) {
|
|
|
|
|
if (state.invoiceLoading) return state.invoiceLoadPromise;
|
|
|
|
|
const requestedPage = Math.max(1, Math.trunc(Number(page) || state.invoicePage || 1));
|
|
|
|
|
state.invoiceLoading = true;
|
|
|
|
|
renderInvoicePagination();
|
|
|
|
|
const request = (async () => {
|
|
|
|
|
try {
|
|
|
|
|
const payload = await api(`/api/v1/invoices?page=${encodeURIComponent(requestedPage)}`);
|
|
|
|
|
const pagination = payload?.pagination && typeof payload.pagination === 'object'
|
|
|
|
|
? payload.pagination : {};
|
|
|
|
|
const actualPage = Math.max(1, Math.trunc(Number(pagination.page) || requestedPage));
|
|
|
|
|
const totalPages = Math.max(1, Math.trunc(Number(pagination.total_pages) || 1));
|
|
|
|
|
const total = Math.max(0, Math.trunc(Number(pagination.total) || 0));
|
|
|
|
|
state.invoicePage = actualPage;
|
|
|
|
|
state.invoicePagination = {
|
|
|
|
|
page: actualPage,
|
|
|
|
|
per_page: Math.max(1, Math.trunc(Number(pagination.per_page) || 10)),
|
|
|
|
|
total,
|
|
|
|
|
total_pages: totalPages,
|
|
|
|
|
has_previous: pagination.has_previous === true || actualPage > 1,
|
|
|
|
|
has_next: pagination.has_next === true || actualPage < totalPages,
|
|
|
|
|
from: Math.max(0, Math.trunc(Number(pagination.from) || 0)),
|
|
|
|
|
to: Math.max(0, Math.trunc(Number(pagination.to) || 0)),
|
|
|
|
|
};
|
|
|
|
|
state.invoices = Array.isArray(payload.invoices) ? payload.invoices : [];
|
|
|
|
|
text('invoices-balance', formatUsd(payload.balance));
|
|
|
|
|
renderInvoices();
|
|
|
|
|
showError('cloud-page-error', '');
|
|
|
|
|
return payload;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
showError('cloud-page-error', error.message);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
state.invoiceLoadPromise = request;
|
|
|
|
|
try {
|
|
|
|
|
const payload = await api('/api/v1/invoices');
|
|
|
|
|
state.invoices = (Array.isArray(payload.invoices) ? payload.invoices : []).slice()
|
|
|
|
|
.sort((left, right) => Number(right.created_at || 0) - Number(left.created_at || 0)
|
|
|
|
|
|| Number(right.id || 0) - Number(left.id || 0));
|
|
|
|
|
state.invoicePaymentMethods = Array.isArray(payload.payment_methods) ? payload.payment_methods : [];
|
|
|
|
|
text('invoices-balance', formatUsd(payload.balance)); renderInvoices(); showError('cloud-page-error', '');
|
|
|
|
|
} catch (error) { showError('cloud-page-error', error.message); }
|
|
|
|
|
return await request;
|
|
|
|
|
} finally {
|
|
|
|
|
state.invoiceLoading = false;
|
|
|
|
|
state.invoiceLoadPromise = null;
|
|
|
|
|
renderInvoicePagination();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
async function openReinstall(vm) {
|
|
|
|
|
if (!vm?.can_operate) return toast('实例服务已到期或正在执行策略,日常操作暂不可用。', 'error');
|
|
|
|
|
@ -1824,10 +1855,8 @@ async function initializeSession(view) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function selectVmByApiId(apiId) {
|
|
|
|
|
await loadVms();
|
|
|
|
|
const vm = state.vms.find(item => item.api_id === String(apiId));
|
|
|
|
|
const vm = await loadVm(apiId, true);
|
|
|
|
|
if (!vm) throw new Error('虚拟机不存在或当前账户无权访问。');
|
|
|
|
|
state.selectedVmId = vm.uuid;
|
|
|
|
|
return vm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -1847,9 +1876,9 @@ export {
|
|
|
|
|
clearVmMetrics, clearVmTrafficDaily, closeConsole, copyText, credential,
|
|
|
|
|
drawVmTrafficDaily, initializeSession, invoicePagePath,
|
|
|
|
|
loadInvoiceDetail, loadInvoices, loadKeys, loadPlanResources, loadVmMetrics, loadVmTrafficDaily,
|
|
|
|
|
loadVms, navigate, openCreate, openReinstall, openRescue, reinstall,
|
|
|
|
|
loadVm, loadVms, navigate, openCreate, openReinstall, openRescue, reinstall,
|
|
|
|
|
renderVMs, renderVmDetail, renderVmMetrics, rescueAction, selectVmByApiId, selectedVm,
|
|
|
|
|
scheduleInvoicePoll, setVmDetailTab, showError, state, stopInvoicePoll, stopVmMetrics,
|
|
|
|
|
stopVmTrafficDaily, toast, trafficDailyViewVisible, updateSource, vmIp,
|
|
|
|
|
stopVmTrafficDaily, toast, trafficDailyViewVisible, vmIp,
|
|
|
|
|
vmPagePath,
|
|
|
|
|
};
|
|
|
|
|
|