feat(admin-vpc): 重构概览和网络目录

go
codex 3 weeks ago
parent f86af4979c
commit e839e82f67

@ -72,12 +72,17 @@ final class CloudPageController extends AdminController
return $response->withStatus(403)
->withHeader('Cache-Control', 'private, no-store');
}
$query = $request->getQueryParams();
$view = (string) ($query['view'] ?? 'overview');
if (!in_array($view, ['overview', 'networks', 'pools'], true)) {
$view = 'overview';
}
$payload = null;
$error = '';
$status = 200;
try {
$payload = CloudAdminVpcControlService::page(
$actor, $request->getQueryParams()
$actor, $query
);
} catch (CloudError $exception) {
$error = $exception->getMessage();
@ -96,6 +101,7 @@ final class CloudPageController extends AdminController
'admin_vpc_page' => $payload,
'admin_vpc_error' => $error,
'admin_vpc_bootstrap_json' => $json,
'admin_vpc_view' => $view,
]);
$response->getBody()->write($smarty->fetch('admin/cloud/vpc.tpl'));
return $response->withStatus($status)

@ -0,0 +1,507 @@
.admin-vpc-control {
padding-bottom: 28px;
}
.admin-vpc-control [hidden] {
display: none !important;
}
.admin-vpc-feature,
.admin-vpc-state {
display: inline-flex;
align-items: center;
gap: 6px;
width: fit-content;
border-radius: 999px;
font-weight: 750;
line-height: 1.2;
}
.admin-vpc-feature {
min-height: 38px;
padding: 8px 13px;
font-size: 13px;
}
.admin-vpc-feature.is-enabled,
.admin-vpc-state.is-success {
color: #08785b;
background: #e3f8ef;
}
.admin-vpc-feature.is-disabled,
.admin-vpc-state.is-warning {
color: #8a5700;
background: #fff3d5;
}
.admin-vpc-state.is-danger {
color: #b42318;
background: #ffebee;
}
.admin-vpc-state {
padding: 6px 10px;
font-size: 12px;
}
.admin-vpc-control > .admin-config-status {
width: 100%;
margin: 0 0 14px;
padding: 9px 12px;
border-radius: 9px;
}
.admin-vpc-tabs {
display: flex;
gap: 8px;
margin: 0 0 16px;
padding: 6px;
border: 1px solid #e2e8f0;
border-radius: 12px;
background: #f8fafc;
overflow-x: auto;
}
.admin-vpc-tabs .btn {
flex: 0 0 auto;
min-width: 128px;
}
.admin-vpc-panel {
display: grid;
gap: 16px;
}
.admin-vpc-summary {
display: grid;
grid-template-columns: repeat(6, minmax(0, 1fr));
gap: 12px;
}
.admin-vpc-summary-card {
min-width: 0;
min-height: 136px;
margin: 0;
padding: 18px;
border: 1px solid #e4eaf1;
text-align: left;
color: #1d2939;
background: #fff;
}
button.admin-vpc-summary-card {
cursor: pointer;
transition: transform .16s ease, border-color .16s ease,
box-shadow .16s ease;
}
button.admin-vpc-summary-card:hover,
button.admin-vpc-summary-card:focus-visible {
transform: translateY(-2px);
border-color: #9edfd4;
box-shadow: 0 12px 24px rgba(17, 94, 89, .09);
}
.admin-vpc-summary-card span {
color: #64748b;
font-size: 13px;
font-weight: 700;
}
.admin-vpc-summary-card strong {
display: block;
margin: 12px 0 8px;
color: #0f172a;
font-size: 30px;
line-height: 1;
}
.admin-vpc-summary-card small {
display: block;
color: #8a99ab;
font-size: 12px;
line-height: 1.45;
}
.admin-vpc-summary-card.is-success {
border-top: 3px solid #22a77a;
}
.admin-vpc-summary-card.is-warning {
border-top: 3px solid #e5a500;
}
.admin-vpc-summary-card.is-danger {
border-top: 3px solid #e24755;
}
.admin-vpc-section {
overflow: hidden;
}
.admin-vpc-section-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 20px 22px;
border-bottom: 1px solid #e5ebf2;
}
.admin-vpc-section-head h2 {
margin: 0 0 4px;
color: #0f172a;
font-size: 18px;
font-weight: 750;
}
.admin-vpc-section-head p:last-child {
margin: 0;
color: #7d8a9c;
font-size: 13px;
}
.admin-vpc-region-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 14px;
padding: 20px 22px;
}
.admin-vpc-region {
min-width: 0;
padding: 17px;
border: 1px solid #dfe7ef;
border-radius: 12px;
background: #fbfcfe;
}
.admin-vpc-region.is-ready {
border-color: #b8e8d9;
background: #f7fdfa;
}
.admin-vpc-region.is-blocked {
border-color: #f1d6d9;
background: #fffafb;
}
.admin-vpc-region > header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
}
.admin-vpc-region h3 {
margin: 0 0 3px;
color: #172033;
font-size: 16px;
}
.admin-vpc-region header p {
margin: 0;
color: #8a99ab;
font-size: 12px;
text-transform: uppercase;
}
.admin-vpc-region header > span {
flex: 0 0 auto;
padding: 5px 8px;
border-radius: 999px;
color: #08785b;
background: #e3f8ef;
font-size: 11px;
font-weight: 750;
}
.admin-vpc-region.is-blocked header > span {
color: #b42318;
background: #ffebee;
}
.admin-vpc-region dl {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
margin: 16px 0 0;
}
.admin-vpc-region dl > div {
min-width: 0;
padding: 10px;
border-radius: 9px;
background: #fff;
}
.admin-vpc-region dt {
color: #8a99ab;
font-size: 11px;
font-weight: 650;
}
.admin-vpc-region dd {
margin: 5px 0 0;
color: #26354a;
font-size: 14px;
font-weight: 750;
}
.admin-vpc-region ul {
display: grid;
gap: 5px;
margin: 14px 0 0;
padding: 0;
color: #a23a45;
font-size: 12px;
list-style: none;
}
.admin-vpc-region ul li::before {
content: "•";
margin-right: 6px;
}
.admin-vpc-region-ok {
display: flex;
align-items: center;
gap: 6px;
margin: 14px 0 0;
color: #08785b;
font-size: 12px;
font-weight: 650;
}
.admin-vpc-empty {
margin: 0;
padding: 28px;
color: #7d8a9c;
text-align: center;
grid-column: 1 / -1;
}
.admin-vpc-filter {
display: grid;
grid-template-columns: minmax(220px, 1.5fr) repeat(3, minmax(150px, .7fr));
gap: 12px;
padding: 18px 22px;
border-bottom: 1px solid #e5ebf2;
background: #fbfcfe;
}
.admin-vpc-filter label {
min-width: 0;
}
.admin-vpc-filter .form-label {
display: block;
margin-bottom: 6px;
}
.admin-vpc-filter-actions {
display: flex;
align-items: flex-end;
gap: 8px;
grid-column: 1 / -1;
}
.admin-vpc-table th {
padding: 13px 14px;
color: #7a889b;
background: #f8fafc;
font-size: 12px;
font-weight: 750;
white-space: nowrap;
}
.admin-vpc-table td {
padding: 15px 14px;
vertical-align: middle;
}
.admin-vpc-table td > strong,
.admin-vpc-table td > a,
.admin-vpc-table td > small,
.admin-vpc-table td > time {
display: block;
}
.admin-vpc-table td > strong,
.admin-vpc-table td > a {
color: #26354a;
font-weight: 750;
}
.admin-vpc-table td > small,
.admin-vpc-table td > time {
margin-top: 4px;
color: #8a99ab;
font-size: 11px;
overflow-wrap: anywhere;
}
.admin-vpc-pagination {
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
padding: 17px 22px;
border-top: 1px solid #e5ebf2;
color: #6f7f92;
font-size: 13px;
}
@media (max-width: 1399.98px) {
.admin-vpc-summary {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.admin-vpc-region-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 991.98px) {
.admin-vpc-filter {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 767.98px) {
.admin-vpc-control .cloud-admin-page-head {
align-items: stretch !important;
}
.admin-vpc-control .cloud-admin-actions,
.admin-vpc-control .cloud-admin-actions .btn,
.admin-vpc-feature {
width: 100%;
}
.admin-vpc-feature,
.admin-vpc-control .cloud-admin-actions .btn {
justify-content: center;
}
.admin-vpc-tabs .btn {
flex: 1 0 118px;
}
.admin-vpc-summary {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.admin-vpc-summary-card {
min-height: 120px;
padding: 15px;
}
.admin-vpc-summary-card strong {
font-size: 26px;
}
.admin-vpc-region-grid,
.admin-vpc-filter {
grid-template-columns: minmax(0, 1fr);
padding: 16px;
}
.admin-vpc-section-head {
align-items: flex-start;
flex-direction: column;
padding: 17px 16px;
}
.admin-vpc-section-head .btn,
.admin-vpc-filter-actions,
.admin-vpc-filter-actions .btn {
width: 100%;
}
.admin-vpc-filter-actions {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.admin-vpc-section .table-responsive {
overflow: visible;
}
.admin-vpc-table thead {
display: none;
}
.admin-vpc-table,
.admin-vpc-table tbody,
.admin-vpc-table tr,
.admin-vpc-table td {
display: block;
width: 100%;
}
.admin-vpc-table tbody {
display: grid;
gap: 12px;
padding: 14px;
}
.admin-vpc-table tr {
padding: 4px 13px;
border: 1px solid #e1e8f0;
border-radius: 12px;
background: #fff;
}
.admin-vpc-table td {
display: grid;
grid-template-columns: minmax(92px, .42fr) minmax(0, 1fr);
gap: 10px;
padding: 10px 0;
border: 0;
border-bottom: 1px solid #eef2f6;
text-align: left;
}
.admin-vpc-table td:last-child {
border-bottom: 0;
}
.admin-vpc-table td::before {
content: attr(data-label);
color: #8a99ab;
font-size: 11px;
font-weight: 700;
}
.admin-vpc-table td[colspan] {
display: block;
padding: 24px 8px;
}
.admin-vpc-table td[colspan]::before {
content: none;
}
.admin-vpc-pagination {
align-items: stretch;
flex-direction: column;
text-align: center;
}
.admin-vpc-pagination .btn {
width: 100%;
}
}
@media (max-width: 419.98px) {
.admin-vpc-summary {
grid-template-columns: minmax(0, 1fr);
}
.admin-vpc-region dl,
.admin-vpc-filter-actions {
grid-template-columns: minmax(0, 1fr);
}
}

@ -1,66 +1,552 @@
const root = document.querySelector('[data-admin-vpc]');
const byId = id => document.getElementById(id);
const canManage = root?.dataset.canManage === '1';
const state = { csrf: window.ADMIN_CSRF_TOKEN || '', regions: [], items: [], featureEnabled: false, busy: false, requestKey: '' };
const allowedViews = new Set(['overview', 'networks', 'pools']);
const state = {
csrf: window.ADMIN_CSRF_TOKEN || '',
page: null,
view: allowedViews.has(root?.dataset.vpcView) ? root.dataset.vpcView : 'overview',
busy: false,
poolEditingId: '',
requestKey: '',
};
function notice(message, error = false) {
const box = byId('admin-vpc-status'); box.textContent = message; box.className = `alert ${error ? 'alert-danger' : 'alert-info'} cloud-admin-notice`;
function readBootstrap() {
try {
const payload = JSON.parse(byId('admin-vpc-bootstrap')?.textContent || 'null');
if (payload && payload.overview && payload.networks && payload.pools) return payload;
} catch {}
return {
overview: { feature: { enabled: false, settings_url: '/admin/config' },
summary: {}, regions: [], attention: [] },
networks: { items: [], filters: { q: '', state: '', region_id: 0 },
pagination: { page: 1, per_page: 20, total: 0, total_pages: 1 } },
pools: { regions: [], items: [], feature_enabled: false },
};
}
function errorMessage(payload, status) { return String(payload?.detail || payload?.error || `请求失败 (${status})`); }
function notice(message, tone = 'success') {
const box = byId('admin-vpc-status');
if (!box) return;
box.textContent = message;
box.className = `admin-config-status is-${tone}`;
}
function errorMessage(payload, status) {
return String(payload?.detail || payload?.error || `请求失败 (${status})`);
}
async function api(path, options = {}) {
const method = (options.method || 'GET').toUpperCase(); const headers = new Headers({ Accept: 'application/json' });
if (!['GET', 'HEAD'].includes(method)) { headers.set('Content-Type', 'application/json'); headers.set('X-CSRF-Token', state.csrf); }
const response = await fetch(path, { method, headers, credentials: 'same-origin', cache: 'no-store', body: options.body === undefined ? undefined : JSON.stringify(options.body) });
let payload; try { payload = await response.json(); } catch { throw new Error('服务返回非 JSON 响应。'); }
if (response.status === 401) { location.assign('/auth/login'); throw new Error('登录已过期。'); }
if (!response.ok) throw new Error(errorMessage(payload, response.status)); return payload;
const method = (options.method || 'GET').toUpperCase();
const headers = new Headers({ Accept: 'application/json' });
if (!['GET', 'HEAD'].includes(method)) {
headers.set('Content-Type', 'application/json');
headers.set('X-CSRF-Token', state.csrf);
}
const response = await fetch(path, {
method, headers, credentials: 'same-origin', cache: 'no-store',
signal: options.signal,
body: options.body === undefined ? undefined : JSON.stringify(options.body),
});
let payload;
try { payload = await response.json(); } catch { throw new Error('服务返回非 JSON 响应。'); }
if (response.status === 401) {
location.assign('/auth/login');
throw new Error('登录已过期。');
}
if (!response.ok) throw new Error(errorMessage(payload, response.status));
return payload;
}
function create(tag, className = '', text = '') {
const node = document.createElement(tag);
if (className) node.className = className;
if (text !== '') node.textContent = String(text);
return node;
}
function appendTextCell(row, label, primary, secondary = '', options = {}) {
const cell = create('td');
cell.dataset.label = label;
let main;
if (options.href) {
main = create('a', '', primary || '未记录');
main.href = options.href;
} else {
main = create('strong', '', primary || '未记录');
}
cell.append(main);
if (secondary) cell.append(create('small', options.mono ? 'admin-mono' : '', secondary));
row.append(cell);
return cell;
}
function formatTime(epoch) {
const value = Number(epoch);
if (!Number.isFinite(value) || value <= 0) return '未记录';
return new Intl.DateTimeFormat('zh-CN', {
year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit', hour12: false,
}).format(new Date(value * 1000));
}
function statePill(network) {
return create('span', `admin-vpc-state is-${network.display?.tone || 'warning'}`,
network.display?.label || '状态未知');
}
function networkRow(network, attention = false) {
const row = create('tr');
appendTextCell(row, 'VPC', network.name, network.vpc_key);
appendTextCell(row, attention ? '用户' : '所有者',
network.owner_name || '未记录', `ID ${network.user_id}`,
{ href: network.owner_url || '' });
appendTextCell(row, '地区与网段', network.region_name, network.cidr,
{ mono: true });
if (!attention) appendTextCell(row, '实例', network.port_count, '已连接端口');
appendTextCell(row, '宿主机投影',
`${network.host_summary?.ready || 0} / ${network.host_summary?.total || 0}`,
attention ? `${network.port_count || 0} 个实例端口` : '已收敛 / 全部');
const statusCell = create('td');
statusCell.dataset.label = '状态';
statusCell.append(statePill(network));
if (network.active_batch) {
statusCell.append(create('small', '', `任务 #${network.active_batch.job_id}`));
}
row.append(statusCell);
if (!attention) appendTextCell(row, '最近变化', formatTime(network.updated_at));
const action = create('td');
action.dataset.label = '操作';
const button = create('button', `btn ${attention ? 'btn-light' : 'btn-primary'} btn-sm`,
attention ? '定位网络' : '查看详情');
button.type = 'button';
if (attention) button.dataset.vpcNetworkFocus = network.vpc_key;
else button.dataset.vpcDetail = String(network.id);
action.append(button);
row.append(action);
return row;
}
function emptyRow(columns, text) {
const row = create('tr');
const cell = create('td', 'text-center text-muted py-4', text);
cell.colSpan = columns;
row.append(cell);
return row;
}
function renderSummary() {
const summary = state.page.overview.summary || {};
for (const key of ['total', 'active', 'changing', 'degraded', 'ports', 'batches']) {
const source = key === 'batches' ? 'active_batches' : key;
const node = byId(`admin-vpc-summary-${key}`);
if (node) node.textContent = String(summary[source] || 0);
}
const feature = state.page.overview.feature || {};
const featureNode = byId('admin-vpc-feature');
if (featureNode) {
featureNode.className = `admin-vpc-feature ${feature.enabled ? 'is-enabled' : 'is-disabled'}`;
featureNode.replaceChildren();
const icon = create('i', `mdi ${feature.enabled ? 'mdi-check-circle-outline' : 'mdi-pause-circle-outline'}`);
icon.setAttribute('aria-hidden', 'true');
featureNode.append(icon, document.createTextNode(feature.enabled
? '用户 VPC 已开启' : '用户 VPC 已关闭'));
}
}
function renderRegions() {
const box = byId('admin-vpc-regions');
box.replaceChildren();
const regions = Array.isArray(state.page.overview.regions)
? state.page.overview.regions : [];
if (!regions.length) {
box.append(create('p', 'admin-vpc-empty', '尚未建立地区和 VPC 承载配置。'));
return;
}
for (const region of regions) {
const card = create('article', `admin-vpc-region ${region.ready ? 'is-ready' : 'is-blocked'}`);
const header = create('header');
const heading = create('div');
heading.append(create('h3', '', region.name),
create('p', '', `${region.code} · ${region.country_code}`));
header.append(heading, create('span', '', region.ready ? '可创建' : '暂不可用'));
const details = create('dl');
for (const [label, value] of [
['地址空间', `${region.used} / ${region.capacity}`],
['可用子网', region.available],
['就绪节点', `${region.hosts_ready} / ${region.hosts_total}`],
]) {
const item = create('div');
item.append(create('dt', '', label), create('dd', '', value));
details.append(item);
}
card.append(header, details);
if (Array.isArray(region.blockers) && region.blockers.length) {
const list = create('ul');
for (const blocker of region.blockers) list.append(create('li', '', blocker.label));
card.append(list);
} else {
const okay = create('p', 'admin-vpc-region-ok');
const icon = create('i', 'mdi mdi-check-circle-outline');
icon.setAttribute('aria-hidden', 'true');
okay.append(icon, document.createTextNode('新建 VPC 的基础条件已满足'));
card.append(okay);
}
box.append(card);
}
}
function renderAttention() {
const body = byId('admin-vpc-attention-body');
body.replaceChildren();
const items = Array.isArray(state.page.overview.attention)
? state.page.overview.attention : [];
if (!items.length) {
body.append(emptyRow(6, '当前没有需要人工处理的 VPC。'));
return;
}
for (const network of items) body.append(networkRow(network, true));
}
function renderNetworks() {
const data = state.page.networks;
const body = byId('admin-vpc-network-body');
body.replaceChildren();
for (const network of data.items || []) body.append(networkRow(network));
if (!data.items?.length) body.append(emptyRow(8, '没有符合条件的 VPC。'));
const page = data.pagination || {};
byId('admin-vpc-network-count').textContent = `共 ${page.total || 0} 个`;
byId('admin-vpc-page-label').textContent =
`第 ${page.page || 1} / ${page.total_pages || 1} 页 · 共 ${page.total || 0} 个`;
byId('admin-vpc-previous').disabled = (page.page || 1) <= 1;
byId('admin-vpc-next').disabled = (page.page || 1) >= (page.total_pages || 1);
}
function renderAll() {
renderSummary();
renderRegions();
renderAttention();
renderNetworks();
renderPools();
}
function setView(view, updateHistory = true) {
if (!allowedViews.has(view)) view = 'overview';
state.view = view;
root.dataset.vpcView = view;
for (const button of root.querySelectorAll('[data-vpc-view]')) {
const active = button.dataset.vpcView === view;
button.setAttribute('aria-selected', String(active));
button.classList.toggle('btn-primary', active);
button.classList.toggle('btn-light', !active);
}
for (const name of allowedViews) {
byId(`admin-vpc-panel-${name}`).hidden = name !== view;
}
if (updateHistory) {
const url = new URL(location.href);
url.searchParams.set('view', view);
history.replaceState(history.state, '', url);
}
}
function filterParams(pageOverride = null) {
const form = byId('admin-vpc-filter');
const params = new URLSearchParams();
for (const name of ['q', 'region_id', 'state', 'per_page']) {
const value = form.elements.namedItem(name)?.value.trim() || '';
if (value && !(name === 'region_id' && value === '0')) params.set(name, value);
}
const page = pageOverride ?? state.page.networks.pagination?.page ?? 1;
if (Number(page) > 1) params.set('page', String(page));
return params;
}
function writeNetworkUrl(params) {
const url = new URL(location.href);
url.search = '';
url.searchParams.set('view', 'networks');
for (const [key, value] of params) url.searchParams.set(key, value);
history.replaceState(history.state, '', url);
}
async function loadNetworks(params = filterParams(1), announce = true) {
if (state.busy) return;
state.busy = true;
const query = params.toString();
try {
const payload = await api(`/api/v1/admin/vpc-control/vpcs${query ? `?${query}` : ''}`);
state.page.networks = payload;
renderNetworks();
writeNetworkUrl(params);
if (announce) notice('VPC 网络目录已更新。');
} catch (error) {
notice(error.message, 'error');
} finally {
state.busy = false;
}
}
async function refreshControl() {
const params = filterParams();
const query = params.toString();
try {
const payload = await api(`/api/v1/admin/vpc-control${query ? `?${query}` : ''}`);
state.page = payload;
renderAll();
notice('VPC 控制面已同步。');
} catch (error) {
notice(`首屏数据仍可查看;后台同步失败:${error.message}`, 'warning');
}
}
function openNetworkState(value) {
const form = byId('admin-vpc-filter');
form.elements.namedItem('state').value = value;
form.elements.namedItem('q').value = '';
setView('networks');
void loadNetworks(filterParams(1));
}
function focusNetwork(key) {
const form = byId('admin-vpc-filter');
form.elements.namedItem('q').value = key;
form.elements.namedItem('state').value = '';
form.elements.namedItem('region_id').value = '0';
setView('networks');
void loadNetworks(filterParams(1));
}
function detailField(list, label, value) {
list.append(create('dt', '', label), create('dd', '', value || '未记录'));
}
async function openDetail(id) {
const dialog = byId('admin-vpc-detail');
const body = byId('admin-vpc-detail-body');
const message = byId('admin-vpc-detail-notice');
body.replaceChildren();
message.hidden = false;
message.className = 'alert alert-info';
message.textContent = '正在读取 VPC 详情…';
window.VenixDrawerMotion?.openDrawerWithMotion(dialog) || dialog.showModal();
try {
const payload = await api(`/api/v1/admin/vpc-control/vpcs/${encodeURIComponent(id)}`);
const network = payload.vpc;
byId('admin-vpc-detail-title').textContent = network.name;
const details = create('dl', 'admin-instance-details');
detailField(details, '所有者', `${network.owner_name || '未记录'} · ID ${network.user_id}`);
detailField(details, '地区', network.region_name);
detailField(details, '私网网段', network.cidr);
detailField(details, '默认网关', network.gateway);
detailField(details, '实例端口', String(network.port_count));
detailField(details, '宿主机投影',
`${network.host_summary.ready} / ${network.host_summary.total} 已收敛`);
body.append(details);
message.hidden = true;
} catch (error) {
message.className = 'alert alert-danger';
message.textContent = error.message;
}
}
async function closeDetail() {
const dialog = byId('admin-vpc-detail');
if (window.VenixDrawerMotion) await window.VenixDrawerMotion.closeDrawerWithMotion(dialog);
else dialog.close();
}
function newRequestKey() {
if (!globalThis.crypto?.getRandomValues) throw new Error('浏览器无法生成安全创建标识,请升级浏览器。');
const bytes = new Uint8Array(16); globalThis.crypto.getRandomValues(bytes); return Array.from(bytes, value => value.toString(16).padStart(2, '0')).join('');
if (!globalThis.crypto?.getRandomValues) {
throw new Error('浏览器无法生成安全创建标识,请升级浏览器。');
}
const bytes = new Uint8Array(16);
globalThis.crypto.getRandomValues(bytes);
return Array.from(bytes, value => value.toString(16).padStart(2, '0')).join('');
}
function renderRegions(selected = '') {
const select = byId('admin-vpc-pool-region'); select.replaceChildren();
const empty = document.createElement('option'); empty.value = ''; empty.textContent = state.regions.length ? '请选择地区' : '请先创建地区'; select.append(empty);
for (const region of state.regions) { const option = document.createElement('option'); option.value = String(region.id); option.textContent = `${region.name} · ${region.country_code}${region.status === 'active' ? '' : '(停用)'}`; option.selected = String(region.id) === String(selected); select.append(option); }
function poolRegions(selected = '') {
const select = byId('admin-vpc-pool-region');
select.replaceChildren();
const regions = state.page.pools.regions || [];
const empty = create('option', '', regions.length ? '请选择地区' : '请先创建地区');
empty.value = '';
select.append(empty);
for (const region of regions) {
const option = create('option', '',
`${region.name} · ${region.country_code}${region.status === 'active' ? '' : '(停用)'}`);
option.value = String(region.id);
option.selected = String(region.id) === String(selected);
select.append(option);
}
}
function lockAddressFields(editing) {
function lockPoolFields(editing) {
byId('admin-vpc-pool-region').disabled = !canManage || editing;
byId('admin-vpc-pool-cidr').disabled = !canManage || (editing && byId('admin-vpc-pool-cidr').dataset.locked === '1');
byId('admin-vpc-pool-prefix').disabled = !canManage || (editing && byId('admin-vpc-pool-prefix').dataset.locked === '1');
byId('admin-vpc-pool-cidr').disabled = !canManage
|| (editing && byId('admin-vpc-pool-cidr').dataset.locked === '1');
byId('admin-vpc-pool-prefix').disabled = !canManage
|| (editing && byId('admin-vpc-pool-prefix').dataset.locked === '1');
}
function resetForm() {
byId('admin-vpc-pool-form').reset(); byId('admin-vpc-pool-id').value = ''; byId('admin-vpc-pool-revision').value = '0'; byId('admin-vpc-pool-prefix').value = '24'; byId('admin-vpc-pool-state').value = 'active'; byId('admin-vpc-pool-title').textContent = '添加 VPC 地址池'; byId('admin-vpc-pool-capacity').textContent = '保存后显示可分配子网数量。'; delete byId('admin-vpc-pool-cidr').dataset.locked; delete byId('admin-vpc-pool-prefix').dataset.locked; state.requestKey = newRequestKey(); renderRegions(); lockAddressFields(false);
function resetPoolForm() {
const form = byId('admin-vpc-pool-form');
form.reset();
state.poolEditingId = '';
byId('admin-vpc-pool-id').value = '';
byId('admin-vpc-pool-revision').value = '0';
byId('admin-vpc-pool-prefix').value = '24';
byId('admin-vpc-pool-state').value = 'active';
byId('admin-vpc-pool-title').textContent = '添加 VPC 地址池';
byId('admin-vpc-pool-capacity').textContent = '保存后显示可分配子网数量。';
delete byId('admin-vpc-pool-cidr').dataset.locked;
delete byId('admin-vpc-pool-prefix').dataset.locked;
state.requestKey = newRequestKey();
poolRegions();
lockPoolFields(false);
}
function editPool(pool) {
byId('admin-vpc-pool-id').value = pool.id; byId('admin-vpc-pool-revision').value = pool.revision; byId('admin-vpc-pool-title').textContent = `编辑地址池 · ${pool.name}`; renderRegions(pool.region_id); byId('admin-vpc-pool-name').value = pool.name; byId('admin-vpc-pool-cidr').value = pool.cidr; byId('admin-vpc-pool-prefix').value = pool.allocation_prefix; byId('admin-vpc-pool-state').value = pool.state; byId('admin-vpc-pool-cidr').dataset.locked = pool.address_locked ? '1' : '0'; byId('admin-vpc-pool-prefix').dataset.locked = pool.address_locked ? '1' : '0'; byId('admin-vpc-pool-capacity').textContent = `${pool.used} 个已占用 · ${pool.available} 个可用 · 共 ${pool.capacity} 个 /${pool.allocation_prefix} 子网${pool.address_locked ? ';地址边界已锁定' : ''}`; lockAddressFields(true);
}
function renderList() {
const list = byId('admin-vpc-pool-list'); list.replaceChildren();
if (!state.items.length) { const empty = document.createElement('p'); empty.className = 'text-muted'; empty.textContent = '暂无 VPC 地址池。'; list.append(empty); return; }
for (const pool of state.items) { const button = document.createElement('button'); button.type = 'button'; button.className = 'btn btn-light cloud-admin-host'; const strong = document.createElement('strong'); strong.textContent = pool.name; const detail = document.createElement('div'); detail.className = 'text-muted'; detail.textContent = `${pool.region_name} · ${pool.cidr} → /${pool.allocation_prefix} · ${pool.used}/${pool.capacity} · ${pool.state === 'active' ? '启用' : '停用'}`; button.append(strong, detail); button.addEventListener('click', () => editPool(pool)); list.append(button); }
state.poolEditingId = String(pool.id);
byId('admin-vpc-pool-id').value = pool.id;
byId('admin-vpc-pool-revision').value = pool.revision;
byId('admin-vpc-pool-title').textContent = `编辑地址池 · ${pool.name}`;
poolRegions(pool.region_id);
byId('admin-vpc-pool-name').value = pool.name;
byId('admin-vpc-pool-cidr').value = pool.cidr;
byId('admin-vpc-pool-prefix').value = pool.allocation_prefix;
byId('admin-vpc-pool-state').value = pool.state;
byId('admin-vpc-pool-cidr').dataset.locked = pool.address_locked ? '1' : '0';
byId('admin-vpc-pool-prefix').dataset.locked = pool.address_locked ? '1' : '0';
byId('admin-vpc-pool-capacity').textContent =
`${pool.used} 个已占用 · ${pool.available} 个可用 · 共 ${pool.capacity} 个 /${pool.allocation_prefix} 子网${pool.address_locked ? ';地址边界已锁定' : ''}`;
lockPoolFields(true);
}
async function load() {
const payload = await api('/api/v1/admin/vpc-cidr-pools'); state.regions = Array.isArray(payload.regions) ? payload.regions : []; state.items = Array.isArray(payload.items) ? payload.items : []; state.featureEnabled = payload.feature_enabled === true; renderList();
function renderPools() {
const list = byId('admin-vpc-pool-list');
list.replaceChildren();
const items = state.page.pools.items || [];
if (!items.length) {
list.append(create('p', 'text-muted', '暂无 VPC 地址池。'));
return;
}
for (const pool of items) {
const button = create('button', 'btn btn-light cloud-admin-host');
button.type = 'button';
button.dataset.poolId = String(pool.id);
button.append(create('strong', '', pool.name),
create('div', 'text-muted',
`${pool.region_name} · ${pool.cidr} → /${pool.allocation_prefix} · ${pool.used}/${pool.capacity} · ${pool.state === 'active' ? '启用' : '停用'}`));
list.append(button);
}
}
function requestBody() {
const regionId = Number(byId('admin-vpc-pool-region').value); const prefix = Number(byId('admin-vpc-pool-prefix').value); const id = byId('admin-vpc-pool-id').value;
function poolRequestBody() {
const regionId = Number(byId('admin-vpc-pool-region').value);
const prefix = Number(byId('admin-vpc-pool-prefix').value);
const id = byId('admin-vpc-pool-id').value;
if (!Number.isInteger(regionId) || regionId < 1) throw new Error('请选择所属地区。');
if (!Number.isInteger(prefix) || prefix < 16 || prefix > 28) throw new Error('VPC 分配前缀必须是 16 至 28 的整数。');
const result = { region_id: regionId, name: byId('admin-vpc-pool-name').value.trim(), cidr: byId('admin-vpc-pool-cidr').value.trim(), allocation_prefix: prefix, state: byId('admin-vpc-pool-state').value };
if (id) result.expected_revision = Number(byId('admin-vpc-pool-revision').value); else result.request_key = state.requestKey;
if (!Number.isInteger(prefix) || prefix < 16 || prefix > 28) {
throw new Error('VPC 分配前缀必须是 16 至 28 的整数。');
}
const result = {
region_id: regionId,
name: byId('admin-vpc-pool-name').value.trim(),
cidr: byId('admin-vpc-pool-cidr').value.trim(),
allocation_prefix: prefix,
state: byId('admin-vpc-pool-state').value,
};
if (id) result.expected_revision = Number(byId('admin-vpc-pool-revision').value);
else result.request_key = state.requestKey;
return result;
}
async function save(event) {
event.preventDefault(); if (!canManage || state.busy) return; let payload; try { payload = requestBody(); } catch (error) { notice(error.message, true); return; }
const id = byId('admin-vpc-pool-id').value; state.busy = true; byId('admin-vpc-pool-save').disabled = true; notice('正在保存 VPC 地址池…');
try { const result = await api(`/api/v1/admin/vpc-cidr-pools${id ? '/' + encodeURIComponent(id) : ''}`, { method: id ? 'PATCH' : 'POST', body: payload }); await load(); editPool(result.item); notice(id ? 'VPC 地址池已更新。' : 'VPC 地址池已创建。'); }
catch (error) { try { await load(); } catch {} notice(error.message, true); }
finally { state.busy = false; byId('admin-vpc-pool-save').disabled = !canManage; }
async function savePool(event) {
event.preventDefault();
if (!canManage || state.busy) return;
let payload;
try { payload = poolRequestBody(); } catch (error) {
notice(error.message, 'error');
return;
}
const id = byId('admin-vpc-pool-id').value;
state.busy = true;
byId('admin-vpc-pool-save').disabled = true;
notice('正在保存 VPC 地址池…', 'warning');
try {
const result = await api(`/api/v1/admin/vpc-cidr-pools${id ? `/${encodeURIComponent(id)}` : ''}`, {
method: id ? 'PATCH' : 'POST', body: payload,
});
const refreshed = await api('/api/v1/admin/vpc-control');
state.page = refreshed;
renderAll();
editPool(result.item);
notice(id ? 'VPC 地址池已更新。' : 'VPC 地址池已创建。');
} catch (error) {
notice(error.message, 'error');
} finally {
state.busy = false;
byId('admin-vpc-pool-save').disabled = !canManage;
}
}
async function initialize() {
function bind() {
for (const button of root.querySelectorAll('[data-vpc-view]')) {
button.addEventListener('click', () => setView(button.dataset.vpcView));
}
for (const button of root.querySelectorAll('[data-vpc-summary-state]')) {
button.addEventListener('click', () => openNetworkState(button.dataset.vpcSummaryState));
}
root.addEventListener('click', event => {
const focus = event.target.closest('[data-vpc-network-focus]');
if (focus) focusNetwork(focus.dataset.vpcNetworkFocus);
const detail = event.target.closest('[data-vpc-detail]');
if (detail) void openDetail(detail.dataset.vpcDetail);
const pool = event.target.closest('[data-pool-id]');
if (pool) {
const item = state.page.pools.items.find(row => String(row.id) === pool.dataset.poolId);
if (item) editPool(item);
}
});
byId('admin-vpc-filter').addEventListener('submit', event => {
event.preventDefault();
void loadNetworks(filterParams(1));
});
byId('admin-vpc-filter-reset').addEventListener('click', () => {
const form = byId('admin-vpc-filter');
form.reset();
form.elements.namedItem('region_id').value = '0';
form.elements.namedItem('state').value = '';
form.elements.namedItem('q').value = '';
void loadNetworks(filterParams(1));
});
byId('admin-vpc-previous').addEventListener('click', () => {
void loadNetworks(filterParams((state.page.networks.pagination?.page || 1) - 1));
});
byId('admin-vpc-next').addEventListener('click', () => {
void loadNetworks(filterParams((state.page.networks.pagination?.page || 1) + 1));
});
for (const button of root.querySelectorAll('[data-vpc-open-state]')) {
button.addEventListener('click', () => openNetworkState(button.dataset.vpcOpenState));
}
byId('admin-vpc-pool-new').addEventListener('click', resetPoolForm);
byId('admin-vpc-pool-form').addEventListener('submit', savePool);
byId('admin-vpc-detail-close').addEventListener('click', closeDetail);
byId('admin-vpc-detail').addEventListener('cancel', event => {
event.preventDefault();
void closeDetail();
});
}
function initialize() {
if (!root) return;
try { const session = await api('/api/v1/session'); state.csrf = session.csrf_token || state.csrf; if (!session.admin || !state.csrf) throw new Error('管理员会话无效,请重新登录。'); await load(); resetForm(); byId('admin-vpc-pool-new').addEventListener('click', resetForm); byId('admin-vpc-pool-form').addEventListener('submit', save); notice(state.featureEnabled ? 'VPC 地址池目录已读取。用户 VPC 功能已开启。' : 'VPC 地址池目录已读取。用户 VPC 功能已关闭,可在“站点设置 → 云功能开关”中启用。'); }
catch (error) { notice(error.message, true); }
state.page = readBootstrap();
renderAll();
resetPoolForm();
setView(state.view, false);
bind();
void refreshControl();
}
void initialize();
initialize();

@ -2,58 +2,80 @@
{assign var=admin_active value='vpc'}
{include file='admin/static_header.tpl'}
<link rel="stylesheet" href="/cloud/admin.css?v={$venix_asset_version}">
<section class="cloud-admin" data-admin-vpc data-can-manage="{if $admin_can_manage|default:false}1{else}0{/if}">
<link rel="stylesheet" href="/cloud/admin-vpc.css?v={$venix_asset_version}">
{if !$admin_vpc_page}
{assign var=admin_vpc_page value=['overview'=>['feature'=>['enabled'=>false,'settings_url'=>'/admin/config'],'summary'=>['total'=>0,'active'=>0,'changing'=>0,'degraded'=>0,'ports'=>0,'active_batches'=>0],'regions'=>[],'attention'=>[],'updated_at'=>0],'networks'=>['items'=>[],'filters'=>['q'=>'','state'=>'','region_id'=>0,'page'=>1,'per_page'=>20],'pagination'=>['page'=>1,'per_page'=>20,'total'=>0,'total_pages'=>1,'from'=>0,'to'=>0]],'pools'=>['regions'=>[],'items'=>[],'feature_enabled'=>false]]}
{/if}
{assign var=vpc_overview value=$admin_vpc_page.overview}
{assign var=vpc_networks value=$admin_vpc_page.networks}
{assign var=vpc_pools value=$admin_vpc_page.pools}
{assign var=vpc_view value=$admin_vpc_view|default:'overview'}
<main class="cloud-admin admin-vpc-control" data-admin-vpc data-can-manage="{if $admin_can_manage|default:false}1{else}0{/if}" data-vpc-view="{$vpc_view|escape}">
<div class="py-3 d-flex align-items-sm-center flex-sm-row flex-column cloud-admin-page-head">
<div class="flex-grow-1">
<p class="admin-eyebrow mb-1">Private Networking</p>
<h4 class="fs-20 fw-semibold mb-1">VPC 私网</h4>
<p class="text-muted mb-0">按地区维护互不重叠的 RFC1918 地址池;每个用户 VPC 从所属地区取得一个独立子网。</p>
<p class="admin-eyebrow mb-1">Private Network Control</p>
<h1 class="fs-20 fw-semibold mb-1">VPC 私网</h1>
<p class="text-muted mb-0">集中查看地区承载能力、用户私网、宿主机路由投影与异常任务;恢复操作仍由任务中心统一校验。</p>
</div>
<div class="text-sm-end mt-3 mt-sm-0 cloud-admin-actions">
<span id="admin-vpc-feature" class="admin-vpc-feature {if $vpc_overview.feature.enabled}is-enabled{else}is-disabled{/if}"><i class="mdi {if $vpc_overview.feature.enabled}mdi-check-circle-outline{else}mdi-pause-circle-outline{/if}" aria-hidden="true"></i>{if $vpc_overview.feature.enabled}用户 VPC 已开启{else}用户 VPC 已关闭{/if}</span>
<a class="btn btn-outline-primary" href="{$vpc_overview.feature.settings_url|default:'/admin/config'|escape}"><i class="mdi mdi-cog-outline me-1" aria-hidden="true"></i>站点设置</a>
</div>
<div class="text-sm-end mt-3 mt-sm-0 cloud-admin-actions"><p id="admin-vpc-status" class="alert alert-info cloud-admin-notice" role="status" aria-live="polite">正在加载…</p></div>
</div>
<div class="alert alert-warning cloud-admin-guidance" role="note">
<i class="mdi mdi-shield-lock-outline"></i>
<span>用户功能开关应在同地区节点完成 Agent v3、路由、实例网卡、断网恢复和维护迁移验收后,再到<a href="/admin/config#configCloudFeatures">站点设置 → 云功能开关</a>启用。停用地址池只停止新建 VPC,不会删除已有网络。</span>
</div>
<p id="admin-vpc-status" class="admin-config-status {if $admin_vpc_error}is-error{else}is-success{/if}" role="status" aria-live="polite">{if $admin_vpc_error}{$admin_vpc_error|escape}{else}VPC 控制面已读取{/if}</p>
<div class="cloud-admin-grid cloud-admin-host-layout">
<aside class="card cloud-admin-side">
<div class="card-body">
<div class="cloud-admin-card-head cloud-admin-card-head-compact">
<div><p class="admin-eyebrow mb-1">CIDR Pools</p><h5 class="mb-0">地区地址池</h5></div>
<button id="admin-vpc-pool-new" class="btn btn-primary" type="button" {if !$admin_can_manage|default:false}disabled{/if}><i class="mdi mdi-plus me-1"></i>添加</button>
</div>
<div id="admin-vpc-pool-list" class="cloud-admin-host-list"></div>
</div>
</aside>
<form id="admin-vpc-pool-form" class="card cloud-admin-form-card">
<div class="card-body">
<div class="cloud-admin-card-head">
<div><p class="admin-eyebrow mb-1">Allocation Boundary</p><h5 id="admin-vpc-pool-title" class="mb-1">添加 VPC 地址池</h5><p class="text-muted mb-0">同一地区地址池不可重叠;已有 VPC 占用时 CIDR 与分配前缀自动锁定。</p></div>
<span class="cloud-admin-card-icon"><i class="mdi mdi-ip-network-outline"></i></span>
</div>
<input id="admin-vpc-pool-id" type="hidden">
<input id="admin-vpc-pool-revision" type="hidden" value="0">
<section class="cloud-admin-form-section">
<div class="cloud-admin-form-grid">
<div><label for="admin-vpc-pool-region" class="form-label">所属地区</label><select id="admin-vpc-pool-region" class="form-select" required {if !$admin_can_manage|default:false}disabled{/if}></select></div>
<div><label for="admin-vpc-pool-state" class="form-label">运行状态</label><select id="admin-vpc-pool-state" class="form-select" required {if !$admin_can_manage|default:false}disabled{/if}><option value="active">启用分配</option><option value="disabled">停用</option></select></div>
<div class="cloud-admin-full"><label for="admin-vpc-pool-name" class="form-label">地址池名称</label><input id="admin-vpc-pool-name" class="form-control" maxlength="80" required {if !$admin_can_manage|default:false}disabled{/if}></div>
<div><label for="admin-vpc-pool-cidr" class="form-label">RFC1918 CIDR</label><input id="admin-vpc-pool-cidr" class="form-control admin-mono" placeholder="例如 10.64.0.0/12" required {if !$admin_can_manage|default:false}disabled{/if}></div>
<div><label for="admin-vpc-pool-prefix" class="form-label">每个 VPC 的前缀</label><input id="admin-vpc-pool-prefix" class="form-control" type="number" min="16" max="28" value="24" required {if !$admin_can_manage|default:false}disabled{/if}></div>
<div id="admin-vpc-pool-capacity" class="cloud-admin-full form-text">保存后显示可分配子网数量。</div>
</div>
</section>
<div class="cloud-admin-form-footer">
<span class="text-muted">仅接受 10.0.0.0/8、172.16.0.0/12、192.168.0.0/16 内的规范网络地址。</span>
<button id="admin-vpc-pool-save" class="btn btn-primary" type="submit" {if !$admin_can_manage|default:false}disabled{/if}><i class="mdi mdi-content-save-outline me-1"></i>保存地址池</button>
</div>
<nav class="admin-vpc-tabs" aria-label="VPC 管理视图" role="tablist">
<button type="button" data-vpc-view="overview" role="tab" aria-controls="admin-vpc-panel-overview" aria-selected="{if $vpc_view == 'overview'}true{else}false{/if}" class="btn {if $vpc_view == 'overview'}btn-primary{else}btn-light{/if}"><i class="mdi mdi-view-dashboard-outline me-1" aria-hidden="true"></i>概览</button>
<button type="button" data-vpc-view="networks" role="tab" aria-controls="admin-vpc-panel-networks" aria-selected="{if $vpc_view == 'networks'}true{else}false{/if}" class="btn {if $vpc_view == 'networks'}btn-primary{else}btn-light{/if}"><i class="mdi mdi-lan me-1" aria-hidden="true"></i>VPC 网络</button>
<button type="button" data-vpc-view="pools" role="tab" aria-controls="admin-vpc-panel-pools" aria-selected="{if $vpc_view == 'pools'}true{else}false{/if}" class="btn {if $vpc_view == 'pools'}btn-primary{else}btn-light{/if}"><i class="mdi mdi-ip-network-outline me-1" aria-hidden="true"></i>地址池</button>
</nav>
<section id="admin-vpc-panel-overview" class="admin-vpc-panel" role="tabpanel" {if $vpc_view != 'overview'}hidden{/if}>
<section class="admin-vpc-summary" aria-label="VPC 运行摘要">
<button class="card admin-vpc-summary-card" type="button" data-vpc-summary-state=""><span>全部 VPC</span><strong id="admin-vpc-summary-total">{$vpc_overview.summary.total|default:0|escape}</strong><small>当前有效网络</small></button>
<button class="card admin-vpc-summary-card is-success" type="button" data-vpc-summary-state="active"><span>运行正常</span><strong id="admin-vpc-summary-active">{$vpc_overview.summary.active|default:0|escape}</strong><small>投影已经收敛</small></button>
<button class="card admin-vpc-summary-card is-warning" type="button" data-vpc-summary-state="changing"><span>变更中</span><strong id="admin-vpc-summary-changing">{$vpc_overview.summary.changing|default:0|escape}</strong><small>正在加入、移出或清理</small></button>
<button class="card admin-vpc-summary-card is-danger" type="button" data-vpc-summary-state="degraded"><span>需要处理</span><strong id="admin-vpc-summary-degraded">{$vpc_overview.summary.degraded|default:0|escape}</strong><small>失败或效果尚未确认</small></button>
<article class="card admin-vpc-summary-card"><span>已连接实例</span><strong id="admin-vpc-summary-ports">{$vpc_overview.summary.ports|default:0|escape}</strong><small>有效 VPC 端口</small></article>
<article class="card admin-vpc-summary-card"><span>批量操作</span><strong id="admin-vpc-summary-batches">{$vpc_overview.summary.active_batches|default:0|escape}</strong><small>当前活动批次</small></article>
</section>
<section class="card admin-vpc-section" aria-labelledby="admin-vpc-regions-title">
<header class="admin-vpc-section-head"><div><p class="admin-eyebrow mb-1">Regional Readiness</p><h2 id="admin-vpc-regions-title">地区承载能力</h2><p>地区必须同时具备可用地址池、可调度节点和已验证的 VPC 传输配置。</p></div><a class="btn btn-light btn-sm" href="/admin/hosts">查看计算节点</a></header>
<div id="admin-vpc-regions" class="admin-vpc-region-grid">
{foreach $vpc_overview.regions as $region}
<article class="admin-vpc-region {if $region.ready}is-ready{else}is-blocked{/if}"><header><div><h3>{$region.name|escape}</h3><p>{$region.code|escape} · {$region.country_code|escape}</p></div><span>{if $region.ready}可创建{else}暂不可用{/if}</span></header><dl><div><dt>地址空间</dt><dd>{$region.used|escape} / {$region.capacity|escape}</dd></div><div><dt>可用子网</dt><dd>{$region.available|escape}</dd></div><div><dt>就绪节点</dt><dd>{$region.hosts_ready|escape} / {$region.hosts_total|escape}</dd></div></dl>{if $region.blockers}<ul>{foreach $region.blockers as $blocker}<li>{$blocker.label|escape}</li>{/foreach}</ul>{else}<p class="admin-vpc-region-ok"><i class="mdi mdi-check-circle-outline" aria-hidden="true"></i>新建 VPC 的基础条件已满足</p>{/if}</article>
{foreachelse}<p class="admin-vpc-empty">尚未建立地区和 VPC 承载配置。</p>{/foreach}
</div>
</form>
</div>
</section>
</section>
<section class="card admin-vpc-section" aria-labelledby="admin-vpc-attention-title">
<header class="admin-vpc-section-head"><div><p class="admin-eyebrow mb-1">Attention</p><h2 id="admin-vpc-attention-title">需要处理</h2><p>只显示失败、效果未知或投影不一致的 VPC;页面不会自动重复派发任务。</p></div><button class="btn btn-light btn-sm" type="button" data-vpc-open-state="degraded">查看全部</button></header>
<div class="table-responsive"><table class="table align-middle mb-0 admin-vpc-table"><thead><tr><th>VPC</th><th>用户</th><th>地区与网段</th><th>宿主机投影</th><th>状态</th><th>操作</th></tr></thead><tbody id="admin-vpc-attention-body">
{foreach $vpc_overview.attention as $network}<tr><td data-label="VPC"><strong>{$network.name|escape}</strong><small>{$network.vpc_key|escape}</small></td><td data-label="用户"><strong>{$network.owner_name|default:'未记录'|escape}</strong><small>ID {$network.user_id|escape}</small></td><td data-label="地区与网段"><strong>{$network.region_name|escape}</strong><small class="admin-mono">{$network.cidr|escape}</small></td><td data-label="宿主机投影"><strong>{$network.host_summary.ready|escape} / {$network.host_summary.total|escape}</strong><small>{$network.port_count|escape} 个实例端口</small></td><td data-label="状态"><span class="admin-vpc-state is-{$network.display.tone|escape}">{$network.display.label|escape}</span></td><td data-label="操作"><button class="btn btn-light btn-sm" type="button" data-vpc-network-focus="{$network.vpc_key|escape}">定位网络</button></td></tr>{foreachelse}<tr><td colspan="6" class="text-center text-muted py-4">当前没有需要人工处理的 VPC。</td></tr>{/foreach}
</tbody></table></div>
</section>
</section>
<section id="admin-vpc-panel-networks" class="admin-vpc-panel" role="tabpanel" {if $vpc_view != 'networks'}hidden{/if}>
<section class="card admin-vpc-section" aria-labelledby="admin-vpc-networks-title">
<header class="admin-vpc-section-head"><div><p class="admin-eyebrow mb-1">Network Directory</p><h2 id="admin-vpc-networks-title">全站 VPC 网络</h2><p>按所有者、地区和运行状态定位网络;私网成员调整仍由用户侧批量流程执行。</p></div><span class="badge text-bg-light" id="admin-vpc-network-count">共 {$vpc_networks.pagination.total|escape} 个</span></header>
<form id="admin-vpc-filter" class="admin-vpc-filter" novalidate><label><span class="form-label">搜索</span><input class="form-control" name="q" type="search" maxlength="120" value="{$vpc_networks.filters.q|escape}" placeholder="名称、标识、CIDR 或用户"></label><label><span class="form-label">所属地区</span><select class="form-select" name="region_id"><option value="0">全部地区</option>{foreach $vpc_overview.regions as $region}<option value="{$region.id|escape}" {if $vpc_networks.filters.region_id == $region.id}selected{/if}>{$region.name|escape}</option>{/foreach}</select></label><label><span class="form-label">运行状态</span><select class="form-select" name="state"><option value="">全部状态</option><option value="active" {if $vpc_networks.filters.state == 'active'}selected{/if}>运行正常</option><option value="changing" {if $vpc_networks.filters.state == 'changing'}selected{/if}>变更中</option><option value="degraded" {if $vpc_networks.filters.state == 'degraded'}selected{/if}>需要处理</option></select></label><label><span class="form-label">每页条数</span><select class="form-select" name="per_page"><option value="20">20 条</option><option value="50" {if $vpc_networks.pagination.per_page == 50}selected{/if}>50 条</option><option value="100" {if $vpc_networks.pagination.per_page == 100}selected{/if}>100 条</option></select></label><div class="admin-vpc-filter-actions"><button class="btn btn-primary" type="submit"><i class="mdi mdi-magnify me-1" aria-hidden="true"></i>应用筛选</button><button class="btn btn-light" id="admin-vpc-filter-reset" type="button">清空</button></div></form>
<div class="table-responsive"><table class="table table-hover align-middle mb-0 admin-vpc-table"><thead><tr><th>VPC</th><th>所有者</th><th>地区与网段</th><th>实例</th><th>宿主机投影</th><th>状态</th><th>最近变化</th><th>操作</th></tr></thead><tbody id="admin-vpc-network-body">
{foreach $vpc_networks.items as $network}<tr><td data-label="VPC"><strong>{$network.name|escape}</strong><small>{$network.vpc_key|escape}</small></td><td data-label="所有者">{if $network.owner_url}<a href="{$network.owner_url|escape}">{$network.owner_name|default:'未记录'|escape}</a>{else}<strong>{$network.owner_name|default:'未记录'|escape}</strong>{/if}<small>ID {$network.user_id|escape}</small></td><td data-label="地区与网段"><strong>{$network.region_name|escape}</strong><small class="admin-mono">{$network.cidr|escape}</small></td><td data-label="实例"><strong>{$network.port_count|escape}</strong><small>已连接端口</small></td><td data-label="宿主机投影"><strong>{$network.host_summary.ready|escape} / {$network.host_summary.total|escape}</strong><small>已收敛 / 全部</small></td><td data-label="状态"><span class="admin-vpc-state is-{$network.display.tone|escape}">{$network.display.label|escape}</span>{if $network.active_batch}<small>任务 #{$network.active_batch.job_id|escape}</small>{/if}</td><td data-label="最近变化"><time data-epoch="{$network.updated_at|escape}">{$network.updated_at|date_format:'%Y-%m-%d %H:%M'|escape}</time></td><td data-label="操作"><button class="btn btn-primary btn-sm" type="button" data-vpc-detail="{$network.id|escape}">查看详情</button></td></tr>{foreachelse}<tr><td colspan="8" class="text-center text-muted py-4">没有符合条件的 VPC。</td></tr>{/foreach}
</tbody></table></div>
<nav class="admin-vpc-pagination" aria-label="VPC 网络分页"><button class="btn btn-light" id="admin-vpc-previous" type="button" {if $vpc_networks.pagination.page <= 1}disabled{/if}>上一页</button><span id="admin-vpc-page-label">第 {$vpc_networks.pagination.page|escape} / {$vpc_networks.pagination.total_pages|escape} 页 · 共 {$vpc_networks.pagination.total|escape} 个</span><button class="btn btn-light" id="admin-vpc-next" type="button" {if $vpc_networks.pagination.page >= $vpc_networks.pagination.total_pages}disabled{/if}>下一页</button></nav>
</section>
</section>
<section id="admin-vpc-panel-pools" class="admin-vpc-panel" role="tabpanel" {if $vpc_view != 'pools'}hidden{/if}>
<div class="cloud-admin-grid"><section class="card"><div class="card-body"><div class="cloud-admin-card-head"><div><p class="admin-eyebrow mb-1">Allocation Pools</p><h2 class="h5 mb-1">地区地址池</h2><p class="text-muted mb-0">停用只会阻止新建 VPC,不会断开或重新分配已有网络。</p></div><button id="admin-vpc-pool-new" class="btn btn-primary" type="button" {if !$admin_can_manage|default:false}disabled{/if}><i class="mdi mdi-plus me-1" aria-hidden="true"></i>添加</button></div><div id="admin-vpc-pool-list" class="cloud-admin-host-list"></div></div></section><form id="admin-vpc-pool-form" class="card cloud-admin-form-card"><div class="card-body"><div class="cloud-admin-card-head"><div><p class="admin-eyebrow mb-1">Allocation Boundary</p><h2 id="admin-vpc-pool-title" class="h5 mb-1">添加 VPC 地址池</h2><p class="text-muted mb-0">已有 VPC 占用时 CIDR 与分配前缀自动锁定。</p></div></div><input id="admin-vpc-pool-id" type="hidden"><input id="admin-vpc-pool-revision" type="hidden" value="0"><section class="cloud-admin-form-section"><div class="cloud-admin-form-grid"><div><label for="admin-vpc-pool-region" class="form-label">所属地区</label><select id="admin-vpc-pool-region" class="form-select" required {if !$admin_can_manage|default:false}disabled{/if}></select></div><div><label for="admin-vpc-pool-state" class="form-label">运行状态</label><select id="admin-vpc-pool-state" class="form-select" required {if !$admin_can_manage|default:false}disabled{/if}><option value="active">启用分配</option><option value="disabled">停用</option></select></div><div class="cloud-admin-full"><label for="admin-vpc-pool-name" class="form-label">地址池名称</label><input id="admin-vpc-pool-name" class="form-control" maxlength="80" required {if !$admin_can_manage|default:false}disabled{/if}></div><div><label for="admin-vpc-pool-cidr" class="form-label">RFC1918 CIDR</label><input id="admin-vpc-pool-cidr" class="form-control admin-mono" placeholder="例如 10.64.0.0/12" required {if !$admin_can_manage|default:false}disabled{/if}></div><div><label for="admin-vpc-pool-prefix" class="form-label">每个 VPC 的前缀</label><input id="admin-vpc-pool-prefix" class="form-control" type="number" min="16" max="28" value="24" required {if !$admin_can_manage|default:false}disabled{/if}></div><div id="admin-vpc-pool-capacity" class="cloud-admin-full form-text">保存后显示可分配子网数量。</div></div></section><div class="cloud-admin-form-footer"><span class="text-muted">仅接受 RFC1918 内的规范网络地址。</span><button id="admin-vpc-pool-save" class="btn btn-primary" type="submit" {if !$admin_can_manage|default:false}disabled{/if}>保存地址池</button></div></div></form></div>
</section>
</main>
<dialog data-admin-instance-drawer id="admin-vpc-detail" aria-labelledby="admin-vpc-detail-title"><header class="admin-instance-drawer-header"><div><p class="admin-eyebrow mb-1">VPC Detail</p><h2 id="admin-vpc-detail-title">VPC 详情</h2></div><button class="admin-modal-close position-static" id="admin-vpc-detail-close" type="button" aria-label="关闭 VPC 详情"><i class="mdi mdi-close" aria-hidden="true"></i></button></header><div class="admin-instance-drawer-body"><p id="admin-vpc-detail-notice" class="alert alert-info">详情功能将在下一阶段启用。</p><div id="admin-vpc-detail-body"></div></div></dialog>
<script id="admin-vpc-bootstrap" type="application/json">{$admin_vpc_bootstrap_json|default:'null' nofilter}</script>
<script type="module" src="/cloud/admin-vpc.js?v={$venix_asset_version}"></script>
{include file='admin/static_footer.tpl'}

@ -1,2 +1,2 @@
{* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *}
{assign var=venix_asset_version value='2026103113' scope='global'}
{assign var=venix_asset_version value='2026103114' scope='global'}

@ -55,23 +55,30 @@ $assert(str_contains($apiRoutes, "'/admin/vpc-control'")
&& str_contains($middleware, '/api/v1/admin/vpc-control'),
'Administrator VPC control-plane read routes are incomplete.');
$assert(str_contains($template, 'data-admin-vpc')
&& str_contains($template, 'id="admin-vpc-bootstrap"')
&& str_contains($template, 'data-vpc-view="overview"')
&& str_contains($template, 'id="admin-vpc-network-body"')
&& str_contains($template, 'id="admin-vpc-pool-form"')
&& str_contains($template, '/cloud/admin-vpc.css?v={$venix_asset_version}')
&& str_contains($template, '/cloud/admin-vpc.js?v={$venix_asset_version}')
&& str_contains($javascript, 'globalThis.crypto?.getRandomValues')
&& str_contains($javascript, "api('/api/v1/admin/vpc-control')")
&& str_contains($javascript,
"api(`/api/v1/admin/vpc-control/vpcs")
&& str_contains($javascript, "method: id ? 'PATCH' : 'POST'"),
'Administrator VPC CIDR pool UI lost its versioned or idempotent workflow.');
'Administrator VPC control UI lost its bootstrap, filter or idempotent workflow.');
$assert(str_contains($siteSettings, 'id="cloud_vpc_enabled"')
&& str_contains($siteSettings, 'name="cloud_vpc_enabled"')
&& str_contains($siteSettingsController,
"CloudVpcFeature::CONFIG_KEY => 'false'")
&& str_contains($siteSettingsController,
"CloudVpcFeature::CONFIG_KEY => 'VPC 私网'")
&& str_contains($javascript, 'payload.feature_enabled')
&& str_contains($javascript, 'state.page.overview.feature')
&& !str_contains($javascript, '功能开关仍保持关闭。'),
'The VPC feature switch is not editable in site settings or the administrator page still reports a hard-coded state.');
$assert(preg_match("/venix_asset_version value='([0-9]+)'/", $assets,
$version) === 1
&& (int) $version[1] >= 2026102806,
&& (int) $version[1] >= 2026103114,
'Administrator VPC browser assets were not cache-busted.');
echo "Administrator VPC CIDR pool page and API contracts passed.\n";

Loading…
Cancel
Save