diff --git a/web/app/Controllers/CloudPageController.php b/web/app/Controllers/CloudPageController.php index 561aba39..f691a0af 100644 --- a/web/app/Controllers/CloudPageController.php +++ b/web/app/Controllers/CloudPageController.php @@ -13,6 +13,8 @@ use App\Services\Cloud\CloudInstancePageService; use App\Services\Cloud\CloudInvoiceDetailPageService; use App\Services\Cloud\CloudInvoicePageService; use App\Services\Cloud\CloudUserIsoFeature; +use App\Services\Cloud\CloudUserIsoService; +use App\Services\Cloud\CloudUserPageView; use App\Services\Cloud\CloudVpcFeature; use App\Services\Cloud\CloudVpcService; use App\Services\UserDrawerService; @@ -136,11 +138,13 @@ final class CloudPageController } $defaultLineId = $defaultLineId ?: $firstLineId; $defaultOfferId = 0; + $defaultOffer = null; foreach ($offers as $offer) { if ((int) $offer['region_id'] === $defaultRegionId && (int) $offer['line_id'] === $defaultLineId && $offer['sellable'] === true) { $defaultOfferId = (int) $offer['id']; + $defaultOffer = $offer; break; } } @@ -169,6 +173,11 @@ final class CloudPageController 'cloud_deploy_default_region_id' => $defaultRegionId, 'cloud_deploy_default_line_id' => $defaultLineId, 'cloud_deploy_default_offer_id' => $defaultOfferId, + 'cloud_deploy_price' => $defaultOffer === null ? '' + : '$' . number_format((float) $defaultOffer['price'], 2, '.', '') . ' USD', + 'cloud_deploy_backup_price' => $defaultOffer === null ? '' + : '$' . number_format((float) $defaultOffer['backup_price'], 2, '.', '') . ' USD', + 'cloud_deploy_snapshot' => $cloudSnapshot, 'cloud_deploy_catalog_unavailable' => $catalogUnavailable, 'cloud_deploy_bootstrap_json' => $this->safeJson($payload), ]); @@ -188,6 +197,7 @@ final class CloudPageController $payload['user'] = $this->userBootstrap($user, $actor); return $this->render($response, 'backups', '云备份', '', '', [ + 'cloud_backup_view' => CloudUserPageView::backups($payload), 'cloud_backup_bootstrap_json' => $this->safeJson($payload), ]); } @@ -211,7 +221,8 @@ final class CloudPageController '云快照', '', '', - ['cloud_snapshot_bootstrap_json' => $this->safeJson($payload)] + ['cloud_snapshot_bootstrap_json' => $this->safeJson($payload), + 'cloud_snapshot_view' => CloudUserPageView::cloudSnapshots($payload)] ); } @@ -223,8 +234,11 @@ final class CloudPageController )->withStatus(302); } $actor = CloudAccess::actor(false); + $user = $request->getAttribute('auth_user') ?? Auth::getUser(); $payload = CloudVpcService::library($actor); + $payload['user'] = $this->userBootstrap($user, $actor); return $this->render($response, 'vpcs', 'VPC 私网', '', '', [ + 'cloud_vpc_view' => CloudUserPageView::vpcs($payload, $request->getQueryParams()), 'cloud_vpc_bootstrap_json' => $this->safeJson($payload), ]); } @@ -234,7 +248,15 @@ final class CloudPageController if (!CloudUserIsoFeature::enabled()) { return $response->withHeader('Location', '/user/cloud/instances')->withStatus(302); } - return $this->render($response, 'isos', 'ISO 镜像'); + $actor = CloudAccess::actor(false); + $user = $request->getAttribute('auth_user') ?? Auth::getUser(); + $payload = CloudUserIsoService::listing((int) $actor['user_id']); + $payload['can_import'] = (int) $user->enable === 1; + $payload['user'] = $this->userBootstrap($user, $actor); + return $this->render($response, 'isos', 'ISO 镜像', '', '', [ + 'cloud_iso_view' => CloudUserPageView::isos($payload), + 'cloud_iso_bootstrap_json' => $this->safeJson($payload), + ]); } public function sshKeys($request, $response, $args) @@ -354,6 +376,16 @@ final class CloudPageController { $smarty = View::getSmarty('venix'); $smarty->assign('cloud_page', $page); + $smarty->assign('cloud_page_module', [ + 'instances' => 'instances', 'detail' => 'detail', 'deploy' => 'deploy', + 'backups' => 'backups', 'cloud-snapshots' => 'cloud-snapshots', + 'vpcs' => 'vpcs', 'isos' => 'iso-images', 'keys' => 'ssh-keys', + 'invoices' => 'invoices', 'invoice-detail' => 'invoice-detail', + 'reinstall' => 'reinstall', + ][$page] ?? ''); + $smarty->assign('cloud_uses_runtime', in_array($page, [ + 'detail', 'deploy', 'backups', 'cloud-snapshots', 'vpcs', 'isos', 'reinstall', + ], true)); $smarty->assign('cloud_title', $title); $smarty->assign('cloud_vm_id', $vmId); $smarty->assign('cloud_invoice_id', $invoiceId); @@ -391,11 +423,19 @@ final class CloudPageController $smarty->assign('cloud_deploy_default_region_id', 0); $smarty->assign('cloud_deploy_default_line_id', 0); $smarty->assign('cloud_deploy_default_offer_id', 0); + $smarty->assign('cloud_deploy_price', ''); + $smarty->assign('cloud_deploy_backup_price', ''); + $smarty->assign('cloud_deploy_snapshot', null); $smarty->assign('cloud_deploy_catalog_unavailable', false); $smarty->assign('cloud_deploy_bootstrap_json', '{}'); $smarty->assign('cloud_backup_bootstrap_json', '{}'); + $smarty->assign('cloud_backup_view', CloudUserPageView::backups([])); $smarty->assign('cloud_snapshot_bootstrap_json', '{}'); + $smarty->assign('cloud_snapshot_view', CloudUserPageView::cloudSnapshots([])); $smarty->assign('cloud_vpc_bootstrap_json', '{}'); + $smarty->assign('cloud_vpc_view', CloudUserPageView::vpcs([], [])); + $smarty->assign('cloud_iso_bootstrap_json', '{}'); + $smarty->assign('cloud_iso_view', CloudUserPageView::isos([])); $smarty->assign('cloud_ssh_keys', []); $smarty->assign('cloud_ssh_keys_bootstrap_json', '{}'); $smarty->assign('cloud_reinstall_vm', []); @@ -902,6 +942,7 @@ final class CloudPageController 'password_label' => $passwordAvailable ? '********' : '未记录', 'password_available' => $passwordAvailable, 'can_operate' => (bool) ($vm['can_operate'] ?? false), + 'is_owner' => (bool) ($vm['is_owner'] ?? false), 'can_settings' => (bool) ($vm['is_owner'] ?? false) && (bool) ($vm['can_operate'] ?? false) && (string) ($vm['os_source'] ?? '') === 'cloud_template', diff --git a/web/app/Services/Cloud/CloudUserPageView.php b/web/app/Services/Cloud/CloudUserPageView.php new file mode 100644 index 00000000..392485ee --- /dev/null +++ b/web/app/Services/Cloud/CloudUserPageView.php @@ -0,0 +1,198 @@ + ['可用', 'running'], 'creating' => ['正在备份', 'warning'], + 'queued' => ['等待备份', 'warning'], 'failed' => ['备份失败', 'stopped'], + 'uncertain' => ['等待核对', 'warning'], 'deleting' => ['正在删除', 'warning'], + 'delete_uncertain' => ['删除待核对', 'warning'], + 'delete_attention' => ['清理需人工处理', 'stopped'], + ]); + $source = $backup['source_instance'] ?? []; + $sourceId = (string) ($source['id'] ?? ''); + $deleted = ($source['deleted'] ?? false) === true + || in_array($source['status'] ?? '', ['deleted', 'missing'], true); + $snapshot = $backup['cloud_snapshot'] ?? []; + $snapshotKey = (string) ($snapshot['snapshot_key'] ?? $snapshot['key'] ?? ''); + $items[] = [ + 'id' => $id, 'name' => self::text($backup['name'] ?? '', '云备份 #' . $id), + 'source_label' => $deleted ? '源实例已删除' + : '来源:' . self::text($source['name'] ?? '', $sourceId !== '' ? '实例 #' . $sourceId : '实例未记录'), + 'state_label' => $label, 'state_class' => $class, + 'date_display' => self::date($backup['ready_at'] ?? $backup['created_at'] ?? null), + 'consistency_display' => ($backup['consistency'] ?? '') === 'filesystem' ? '文件系统一致' : '崩溃一致', + 'object_display' => self::bytes($backup['object_size_bytes'] ?? null), + 'disk_display' => self::bytes($backup['virtual_size_bytes'] ?? null), + 'restore_href' => !$deleted && ($backup['can_restore_original'] ?? false) === true + && preg_match('/^[1-9][0-9]*$/D', $sourceId) === 1 + ? '/user/cloud/instances/' . $sourceId . '?tab=settings&setting=automatic_backup' : '', + 'snapshot_href' => preg_match('/^[a-f0-9]{32}$/D', $snapshotKey) === 1 + ? '/user/cloud/cloud-snapshots#cloud-snapshot-' . $snapshotKey : '', + 'can_promote' => ($backup['can_promote'] ?? false) === true, + ]; + } + return ['items' => $items, 'pagination' => self::pagination($payload)]; + } + + public static function cloudSnapshots(array $payload): array + { + $items = []; + foreach ($payload['items'] ?? [] as $snapshot) { + $key = (string) ($snapshot['snapshot_key'] ?? ''); + [$label, $class] = self::state((string) ($snapshot['state'] ?? ''), [ + 'ready' => ['可用', 'running'], 'promoting' => ['正在保存', 'warning'], + 'deleting' => ['正在删除', 'warning'], 'delete_uncertain' => ['删除待核对', 'warning'], + 'failed' => ['保存失败', 'stopped'], + ]); + $source = $snapshot['source_instance'] ?? []; + $sourceName = self::text($source['name'] ?? '', !empty($source['id']) ? '实例 #' . $source['id'] : '来源实例未记录'); + $pending = max(0, (int) ($snapshot['active_invoice_count'] ?? 0)); + $items[] = [ + 'key' => $key, 'name' => self::text($snapshot['name'] ?? '', '云快照 ' . substr($key, 0, 8)), + 'source_label' => '来源:' . $sourceName . ($pending > 0 ? ' · ' . $pending . ' 张待支付账单' : ''), + 'state_label' => $label, 'state_class' => $class, + 'date_display' => self::date($snapshot['ready_at'] ?? $snapshot['created_at'] ?? null), + 'os_display' => self::text($snapshot['os_name'] ?? '', '系统未记录'), + 'object_display' => self::bytes($snapshot['object_size_bytes'] ?? null), + 'disk_display' => self::bytes($snapshot['virtual_size_bytes'] ?? null), + 'create_href' => ($snapshot['can_create_instance'] ?? false) === true + && preg_match('/^[a-f0-9]{32}$/D', $key) === 1 ? '/user/cloud/deploy?cloud_snapshot=' . $key : '', + 'delete_title' => ($snapshot['can_delete'] ?? false) === true ? '' + : ($pending > 0 ? '存在待支付账单,请先支付或等待账单失效后再删除。' : '云快照当前状态不允许删除。'), + ]; + } + return ['items' => $items, 'pagination' => self::pagination($payload)]; + } + + public static function vpcs(array $payload, array $query): array + { + $networks = []; + $current = null; + $key = is_string($query['vpc'] ?? null) ? $query['vpc'] : ''; + $view = is_string($query['view'] ?? null) ? $query['view'] : ''; + $page = $key !== '' ? 'members' : ($view === 'create' ? 'create' : 'home'); + if ((isset($query['vpc']) && preg_match('/^[a-f0-9]{32}$/D', $key) !== 1) + || (isset($query['view']) && !in_array($view, ['create', 'members', 'join'], true)) + || ($key === '' && in_array($view, ['members', 'join'], true))) { + $page = 'missing'; + } + $batches = $payload['membership_batches'] ?? []; + foreach ($payload['items'] ?? [] as $network) { + $networkKey = (string) ($network['vpc_key'] ?? ''); + $batch = null; + foreach ($batches as $candidate) { + if (($candidate['vpc_key'] ?? '') === $networkKey) { $batch = $candidate; break; } + } + [$label, $class] = ($network['state'] ?? '') === 'active' + ? ['运行正常', 'running'] : [self::text($network['state'] ?? '', '状态未知'), 'other']; + $network['state_label'] = $batch !== null ? '变更中' : $label; + $network['state_class'] = $batch !== null ? 'other' : $class; + $network['members_href'] = '/user/cloud/vpcs?vpc=' . rawurlencode($networkKey); + $network['join_href'] = $network['members_href'] . '&view=join'; + $network['batch'] = $batch; + $networks[] = $network; + if ($networkKey === $key) { + $current = $network; + $current['state_label'] = $label; + $current['state_class'] = $class; + } + } + if ($page === 'members' && $current === null) $page = 'missing'; + $members = []; + $candidates = []; + foreach ($payload['instances'] ?? [] as $instance) { + if ($current === null) break; + $port = $instance['port'] ?? null; + $joined = is_array($port) && ($port['vpc_key'] ?? '') === $key; + $candidate = $port === null && (int) ($instance['region_id'] ?? 0) === (int) $current['region_id']; + if (!$joined && !$candidate) continue; + [$label, $class] = $candidate + ? (($instance['can_attach'] ?? false) === true ? ['可加入', 'running'] : ['暂不可加入', 'other']) + : self::state((string) ($port['state'] ?? ''), [ + 'preparing' => ['正在连接', 'other'], 'attached' => ['已连接', 'running'], + 'detaching' => ['正在断开', 'other'], 'release_pending' => ['等待清理', 'other'], + 'released' => ['已断开', 'other'], 'migrating' => ['正在迁移', 'other'], + ]); + foreach ($current['batch']['items'] ?? [] as $batchItem) { + if ((string) ($batchItem['instance_id'] ?? '') !== (string) $instance['id']) continue; + [$label, $class] = self::state((string) ($batchItem['state'] ?? ''), [ + 'waiting_route' => ['等待中', 'other'], 'queued' => ['执行中', 'other'], + 'succeeded' => ['已完成', 'running'], 'failed' => ['失败', 'failed'], 'unknown' => ['失败', 'failed'], + ]); + break; + } + $instance['state_label'] = $label; + $instance['state_class'] = $class; + $instance['public_ipv4'] = self::text($instance['public_ipv4'] ?? '', '未分配'); + if ($joined) $members[] = $instance; else $candidates[] = $instance; + } + return [ + 'page' => $page, 'joining' => $view === 'join', 'networks' => $networks, + 'regions' => $payload['regions'] ?? [], 'current' => $current, + 'members' => $view === 'join' ? $candidates : $members, + 'member_count' => count($members), + 'joinable_count' => count(array_filter($candidates, static fn (array $item): bool => ($item['can_attach'] ?? false) === true)), + 'used' => max(0, (int) ($payload['used'] ?? count($networks))), + 'maximum' => max(1, (int) ($payload['maximum'] ?? 16)), + ]; + } + + public static function isos(array $payload): array + { + $items = []; + foreach ($payload['isos'] ?? [] as $iso) { + $iso['size_display'] = self::bytes($iso['size_bytes'] ?? null); + $iso['fingerprint_display'] = !empty($iso['sha256']) ? ' · SHA-256 ' . substr((string) $iso['sha256'], 0, 12) . '…' : ''; + $items[] = $iso; + } + return ['items' => $items, 'can_import' => ($payload['can_import'] ?? false) === true, + 'import_active' => ($payload['active_import_job']['completed'] ?? true) === false]; + } + + private static function pagination(array $payload): array + { + $value = $payload['pagination'] ?? []; + $page = max(1, (int) ($value['page'] ?? 1)); + $pages = max(1, (int) ($value['total_pages'] ?? 1)); + return ['page' => $page, 'total_pages' => $pages, + 'total' => max(0, (int) ($value['total'] ?? count($payload['items'] ?? []))), + 'has_previous' => $page > 1, 'has_next' => $page < $pages]; + } + + private static function text($value, string $fallback): string + { + $text = trim((string) $value); + return $text !== '' ? $text : $fallback; + } + + private static function state(string $value, array $labels): array + { + return $labels[$value] ?? [self::text($value, '状态未知'), 'other']; + } + + private static function date($value): string + { + return is_numeric($value) && (float) $value > 0 + ? date('Y/m/d H:i:s', (int) ((float) $value >= 1e12 ? (float) $value / 1000 : $value)) : '时间未记录'; + } + + private static function bytes($value): string + { + if (!is_numeric($value) || (float) $value < 0) return '等待完成'; + $amount = (float) $value; + $units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']; + $index = 0; + while ($amount >= 1024 && $index < count($units) - 1) { $amount /= 1024; ++$index; } + $precision = $index === 0 ? 0 : ($amount >= 100 ? 0 : ($amount >= 10 ? 1 : 2)); + return number_format($amount, $precision, '.', '') . ' ' . $units[$index]; + } +} diff --git a/web/public/cloud/app.js b/web/public/cloud/app.js index 430ec214..ee0c15a9 100644 --- a/web/public/cloud/app.js +++ b/web/public/cloud/app.js @@ -31,9 +31,6 @@ function showPageError(message) { } async function initializeCloudApp() { - const { initializeTaskCenter } = await import(versionedModuleUrl('./task-center.js')); - initializeTaskCenter(); - const modulePath = pageModules[page]; if (!modulePath) { showPageError('页面类型无效,请返回实例列表。'); @@ -41,9 +38,17 @@ async function initializeCloudApp() { } const module = await import(versionedModuleUrl(modulePath)); - module.initialize(); + 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 || '页面加载失败,请刷新后重试。'); }); diff --git a/web/public/cloud/iso-images.js b/web/public/cloud/iso-images.js index fd3caa46..3682ce26 100644 --- a/web/public/cloud/iso-images.js +++ b/web/public/cloud/iso-images.js @@ -16,7 +16,7 @@ const { taskSucceededWithoutRecovery, } = taskObserver; const { - api, bindPageCleanup, byId, initializeSession, showError, state, toast, + api, bindPageCleanup, byId, initializeSession, readBootstrap, showError, state, toast, } = runtime; const requestUserConfirmation = options => window.VenixDialog?.confirm?.(options) ?? Promise.resolve(false); @@ -164,27 +164,7 @@ async function loadIsos({ observeActive = true } = {}) { signal: pageState.loadController.signal, }); if (epoch !== pageState.loadEpoch || pageState.stopped) return; - pageState.isos = Array.isArray(result?.isos) ? result.isos : []; - pageState.canImport = result?.can_import !== false; - renderIsos(); - const job = result?.active_import_job; - const activeJobId = String(job?.task_id || '').trim(); - const resumedReceipt = { - task_id: activeJobId, - status_url: `/api/v1/tasks/${encodeURIComponent(activeJobId)}`, - }; - const jobId = job?.completed === false && !Object.prototype.hasOwnProperty.call(job, 'status') - && taskUrl(resumedReceipt) ? activeJobId : ''; - if (jobId) { - pageState.activeStatusUrl = jobId; - setImportStatus(job?.phase || '正在远程下载并校验 ISO…'); - updateImportAvailability(); - if (observeActive) watchImport(resumedReceipt, false); - } else if (!pageState.importObserver) { - pageState.activeStatusUrl = ''; - setImportStatus(''); - updateImportAvailability(); - } + applyIsoPayload(result, observeActive); return true; } catch (error) { if (epoch === pageState.loadEpoch && error.name !== 'AbortError') { @@ -194,6 +174,30 @@ async function loadIsos({ observeActive = true } = {}) { } } +function applyIsoPayload(result, observeActive = true) { + pageState.isos = Array.isArray(result?.isos) ? result.isos : []; + pageState.canImport = result?.can_import !== false; + renderIsos(); + const job = result?.active_import_job; + const activeJobId = String(job?.task_id || '').trim(); + const resumedReceipt = { + task_id: activeJobId, + status_url: `/api/v1/tasks/${encodeURIComponent(activeJobId)}`, + }; + const jobId = job?.completed === false && !Object.prototype.hasOwnProperty.call(job, 'status') + && taskUrl(resumedReceipt) ? activeJobId : ''; + if (jobId) { + pageState.activeStatusUrl = jobId; + setImportStatus(job?.phase || '正在远程下载并校验 ISO…'); + updateImportAvailability(); + if (observeActive) watchImport(resumedReceipt, false); + } else if (!pageState.importObserver) { + pageState.activeStatusUrl = ''; + setImportStatus(''); + updateImportAvailability(); + } +} + function taskFailureMessage(task, fallback) { const message = task?.error || fallback; const recoveryNotice = recoveryTaskFailureNotice(task); @@ -291,7 +295,8 @@ async function importIso(event) { export async function initialize() { try { - if (!await initializeSession('isos')) return; + const bootstrap = readBootstrap('user-isos-bootstrap'); + if (!await initializeSession('isos', bootstrap?.user)) return; bindPageCleanup(); window.addEventListener('pagehide', () => { pageState.stopped = true; @@ -306,6 +311,7 @@ export async function initialize() { void loadIsos(); }); byId('user-iso-form')?.addEventListener('submit', importIso); - await loadIsos(); + if (Array.isArray(bootstrap?.isos)) applyIsoPayload(bootstrap); + else await loadIsos(); } catch (error) { showError('cloud-page-error', error.message); } } diff --git a/web/public/cloud/runtime.js b/web/public/cloud/runtime.js index fe420932..57af710d 100644 --- a/web/public/cloud/runtime.js +++ b/web/public/cloud/runtime.js @@ -866,10 +866,10 @@ async function selectOffer(offerId) { async function openCreate(bootstrap = null) { state.view = 'create'; state.selectedVmId = null; showError('create-error', ''); byId('vm-offer').value = String(bootstrap?.default_offer_id || ''); - initializeDeploymentOptions(bootstrap); if (bootstrap && Array.isArray(bootstrap.offers) && Array.isArray(bootstrap.regions) && Array.isArray(bootstrap.lines) && Array.isArray(bootstrap.templates)) { applySaleCatalog(bootstrap); + initializeDeploymentOptions(bootstrap); state.templates = bootstrapItems(bootstrap, 'templates', 'cloud_templates'); state.templateCatalogUnavailable = bootstrap.catalog_unavailable === true; state.sshKeys = bootstrapItems(bootstrap, 'ssh_keys', 'keys'); @@ -891,6 +891,7 @@ async function openCreate(bootstrap = null) { updateCreateAvailability(); return; } + initializeDeploymentOptions(bootstrap); state.regions = []; state.lines = []; state.offers = []; state.linesEnabled = false; state.selectedRegionId = ''; state.selectedLineId = ''; byId('vm-region').value = ''; byId('vm-line').value = ''; diff --git a/web/public/cloud/vpcs.js b/web/public/cloud/vpcs.js index e28bd900..9ce513d4 100644 --- a/web/public/cloud/vpcs.js +++ b/web/public/cloud/vpcs.js @@ -199,7 +199,18 @@ function instanceMatchesMemberQuery(instance, query) { function pageRoute() { const hash = window.location.hash; - if (!hash || hash === '#' || hash === '#/') return { page: 'home' }; + if (!hash || hash === '#') { + const query = new URL(window.location.href).searchParams; + const key = query.getAll('vpc').at(-1) ?? null; + const view = query.getAll('view').at(-1) ?? null; + if ((key !== null && !/^[a-f0-9]{32}$/.test(key)) + || [...query.keys()].some(name => /^(?:vpc|view)\[/.test(name)) + || (view !== null && !['create', 'members', 'join'].includes(view)) + || (!key && ['members', 'join'].includes(view))) return { page: 'missing' }; + if (key) return { page: 'members', key, joining: view === 'join' }; + return { page: view === 'create' ? 'create' : 'home' }; + } + if (hash === '#/') return { page: 'home' }; if (hash === '#/create') return { page: 'create' }; const match = /^#\/([a-f0-9]{32})\/instances(\/join)?$/.exec(hash); return match ? { page: 'members', key: match[1], joining: Boolean(match[2]) } @@ -207,7 +218,7 @@ function pageRoute() { } function membersHref(vpc, joining = false) { - return `#/${vpcKey(vpc)}/instances${joining ? '/join' : ''}`; + return `/user/cloud/vpcs?vpc=${encodeURIComponent(vpcKey(vpc))}${joining ? '&view=join' : ''}`; } function currentVpc() { @@ -348,7 +359,7 @@ function renderHome() { list.replaceChildren(); if (!state.items.length) { list.append(emptyState('还没有 VPC', '选择一个地区,建立你的第一张私有网络。', - '#/create', '创建 VPC')); + '/user/cloud/vpcs?view=create', '创建 VPC')); return; } const table = element('table', 'cloud-vpc-table cloud-vpc-network-table'); @@ -903,7 +914,7 @@ async function submitMembershipBatch(vpc, action, instances) { selectionForVpc(vpc, action).clear(); observeBatch(batch, true); if (currentVpc() && vpcKey(currentVpc()) === key) { - window.location.hash = membersHref(vpc); + window.location.href = new URL(membersHref(vpc), window.location.href).href; } setPageStatus(`已接收 ${ids.length} 台实例;任务将在服务端并发处理。`); toast('VPC 批量任务已接收。', 'success'); @@ -1058,7 +1069,7 @@ async function createVpc(event) { state.used += 1; } // Keep the confirmed creation visible even if the following refresh fails. - if (pageRoute().page === 'create') window.location.hash = membersHref(created, true); + if (pageRoute().page === 'create') window.location.href = new URL(membersHref(created, true), window.location.href).href; } await load(true); toast('VPC 已创建,可选择需要加入的实例。', 'success'); @@ -1089,7 +1100,7 @@ async function removeVpc(vpc) { }); state.items = state.items.filter(item => vpcKey(item) !== key); state.used = Math.max(0, state.used - 1); - if (pageRoute().key === key) window.location.hash = '#/'; + if (pageRoute().key === key) window.location.href = new URL('/user/cloud/vpcs', window.location.href).href; await load(true); toast('VPC 已删除。', 'success'); } catch (error) { diff --git a/web/resources/views/venix/cloud/page.tpl b/web/resources/views/venix/cloud/page.tpl index 00ecdd62..027dce66 100644 --- a/web/resources/views/venix/cloud/page.tpl +++ b/web/resources/views/venix/cloud/page.tpl @@ -5,6 +5,8 @@ {$config["appName"]|escape:"html"} · {$cloud_title|escape:"html"} + {if !empty($cloud_page_module)}{/if} + {if !empty($cloud_uses_runtime)}{/if} diff --git a/web/resources/views/venix/cloud/pages/backups.tpl b/web/resources/views/venix/cloud/pages/backups.tpl index 6bb8d026..b17ebead 100644 --- a/web/resources/views/venix/cloud/pages/backups.tpl +++ b/web/resources/views/venix/cloud/pages/backups.tpl @@ -5,15 +5,26 @@
备份用途说明云备份用于恢复原实例,也可保存为长期保留的云快照;创建新实例请前往“云快照”。
-

全部备份

只显示属于当前账户的普通云备份,不包含管理员维护迁移的临时数据。

0 个
-

正在读取云备份…

-
+

全部备份

只显示属于当前账户的普通云备份,不包含管理员维护迁移的临时数据。

{$cloud_backup_view.pagination.total|default:0|escape:'html'} 个
+ +
+ {foreach $cloud_backup_view.items|default:[] as $backup} +
+
☁
{$backup.name|escape:'html'}{$backup.source_label|escape:'html'}
{$backup.state_label|escape:'html'}
+
创建时间
{$backup.date_display|escape:'html'}
一致性
{$backup.consistency_display|escape:'html'}
对象大小
{$backup.object_display|escape:'html'}
磁盘容量
{$backup.disk_display|escape:'html'}
+
+ {if $backup.restore_href != ''}恢复原实例{/if} + {if $backup.snapshot_href != ''}查看云快照{elseif $backup.can_promote}{/if} +
+
+ {foreachelse}
还没有云备份购买自动备份后,可在实例详情中设置备份计划。
{/foreach} +
- + diff --git a/web/resources/views/venix/cloud/pages/cloud-snapshots.tpl b/web/resources/views/venix/cloud/pages/cloud-snapshots.tpl index 7ae45203..46e78eff 100644 --- a/web/resources/views/venix/cloud/pages/cloud-snapshots.tpl +++ b/web/resources/views/venix/cloud/pages/cloud-snapshots.tpl @@ -4,15 +4,23 @@
与在线快照不同云快照独立存放在对象存储中,不随源实例或自动备份轮换删除;只有手动删除后才会释放其存储对象。
-

全部云快照

从云快照创建的新实例会使用新的 UUID、网络标识和公网 IP。

0 个
-

正在读取云快照…

-
+

全部云快照

从云快照创建的新实例会使用新的 UUID、网络标识和公网 IP。

{$cloud_snapshot_view.pagination.total|default:0|escape:'html'} 个
+ +
+ {foreach $cloud_snapshot_view.items|default:[] as $snapshot} +
+
◆
{$snapshot.name|escape:'html'}{$snapshot.source_label|escape:'html'}
{$snapshot.state_label|escape:'html'}
+
保存时间
{$snapshot.date_display|escape:'html'}
操作系统
{$snapshot.os_display|escape:'html'}
对象大小
{$snapshot.object_display|escape:'html'}
磁盘容量
{$snapshot.disk_display|escape:'html'}
+
{if $snapshot.create_href != ''}创建实例{/if}
+
+ {foreachelse}
还没有云快照可前往“云备份”将一份可用备份保存为云快照。
{/foreach} +
- + diff --git a/web/resources/views/venix/cloud/pages/deploy.tpl b/web/resources/views/venix/cloud/pages/deploy.tpl index 49eb6699..2a07e078 100644 --- a/web/resources/views/venix/cloud/pages/deploy.tpl +++ b/web/resources/views/venix/cloud/pages/deploy.tpl @@ -59,14 +59,14 @@
-
{if !empty($cloud_deploy_lines_enabled)}4{else}3{/if}

选择系统镜像(必选)

- -
{if !empty($cloud_deploy_lines_enabled)}6{else}5{/if}

自动备份

-
{if !empty($cloud_deploy_lines_enabled)}7{else}6{/if}

确认费用

-

选择实例规格后显示本次最终金额。

-
diff --git a/web/resources/views/venix/cloud/pages/detail.tpl b/web/resources/views/venix/cloud/pages/detail.tpl index 31501a51..3c68c6b6 100644 --- a/web/resources/views/venix/cloud/pages/detail.tpl +++ b/web/resources/views/venix/cloud/pages/detail.tpl @@ -24,8 +24,8 @@
-

日常操作

在这里管理这台虚拟机的电源和控制台。

正在读取实时状态…

-

维护与危险操作

救援会先预挂载 ISO,再尝试正常关机并开机;强制断电可能丢失未保存的数据,重装或删除会清除数据。

实时状态确认后才会启用操作。

+

日常操作

在这里管理这台虚拟机的电源和控制台。

{if $cloud_vm_view.can_operate|default:false}{else}

{if $cloud_vm_view.is_owner|default:false || $cloud_vm_view.can_delete|default:false}实例服务已到期或正在执行策略;日常操作暂不可用。{else}这是其他用户的实例;当前管理员账户只有查看权限。{/if}

{/if}
+

维护与危险操作

救援会先预挂载 ISO,再尝试正常关机并开机;强制断电可能丢失未保存的数据,重装或删除会清除数据。

{if $cloud_vm_view.can_operate|default:false}{/if}{if $cloud_vm_view.can_delete|default:false}{/if}
diff --git a/web/resources/views/venix/cloud/pages/isos.tpl b/web/resources/views/venix/cloud/pages/isos.tpl index 0cd3221a..ef1bb3fd 100644 --- a/web/resources/views/venix/cloud/pages/isos.tpl +++ b/web/resources/views/venix/cloud/pages/isos.tpl @@ -9,16 +9,19 @@ 仅支持无需登录、不会跳转的公网 HTTPS 直链,URL 路径的文件名必须以 .iso 结尾;每个用户最多保存 5 个,个人 ISO 库累计和单文件均不得超过 10 GiB。超出限额会停止下载并提示,离开页面不会取消后台任务。 - +

{if !empty($cloud_iso_view.import_active)}已有 ISO 下载任务正在执行,完成前不能再次导入。{elseif empty($cloud_iso_view.can_import)}账户的套餐购买及 ISO 上传服务已被管理员停用。{/if}

- +
◉

我的 ISO

这里只显示当前账户的全局 ISO,其他用户无法查看或使用。

-

正在加载…

+
+ {foreach $cloud_iso_view.items|default:[] as $iso}
{$iso.name|escape:'html'}{$iso.size_display|escape:'html'}{$iso.fingerprint_display|escape:'html'}
{foreachelse}

还没有个人 ISO 镜像。

{/foreach} +
+ diff --git a/web/resources/views/venix/cloud/pages/vpcs.tpl b/web/resources/views/venix/cloud/pages/vpcs.tpl index da3def9f..25e7727f 100644 --- a/web/resources/views/venix/cloud/pages/vpcs.tpl +++ b/web/resources/views/venix/cloud/pages/vpcs.tpl @@ -1,46 +1,79 @@
- + 返回 VPC 列表 -
+

VPC 私网

管理同地区实例之间的私有网络。

- + 创建 VPC + + 创建 VPC +
+

我的网络

{$cloud_vpc_view.used|default:0|escape:'html'} / {$cloud_vpc_view.maximum|default:16|escape:'html'} 个
+
+ {if !empty($cloud_vpc_view.networks)} + + + {foreach $cloud_vpc_view.networks as $network} + + + + + + {/foreach} +
网络名称 / 地区私网网段实例状态管理
{$network.name|escape:'html'}{$network.region_name|escape:'html'}{$network.cidr|escape:'html'}{$network.port_count|default:0|escape:'html'} 台{$network.state_label|escape:'html'}管理实例 →
+ {else}
还没有 VPC

选择一个地区,建立你的第一张私有网络。

创建 VPC
{/if}
-

我的网络

0 / 16 个
-

同一 VPC 内默认互通,实例公网配置保持独立。

-