diff --git a/web/app/Services/Cloud/CloudUserPageView.php b/web/app/Services/Cloud/CloudUserPageView.php index 193f4408..4ec36304 100644 --- a/web/app/Services/Cloud/CloudUserPageView.php +++ b/web/app/Services/Cloud/CloudUserPageView.php @@ -75,48 +75,55 @@ final class CloudUserPageView public static function trafficPools(array $payload): array { - $regions = []; - foreach ($payload['region_groups'] ?? [] as $region) { + $linePools = []; + foreach ($payload['line_pools'] ?? [] as $pool) { [$stateLabel, $stateClass] = self::state( - (string) ($region['summary_state'] ?? ''), + (string) ($pool['summary_state'] ?? ''), [ 'available' => ['状态正常', 'running'], 'preparing' => ['额度准备中', 'warning'], 'applying' => ['网络策略应用中', 'warning'], - 'exhausted' => ['存在已用尽流量池', 'stopped'], - 'restricted' => ['存在断网实例', 'stopped'], + 'exhausted' => ['流量已用尽', 'stopped'], + 'restricted' => ['线路池已断网', 'stopped'], 'attention' => ['需要核查', 'stopped'], ] ); - $items = []; - foreach ($region['items'] ?? [] as $pool) { - $items[] = self::trafficPool($pool); + $coverage = []; + foreach ($pool['coverage_regions'] ?? [] as $region) { + $name = trim((string) ($region['name'] ?? '')); + if ($name !== '' && !in_array($name, $coverage, true)) { + $coverage[] = $name; + } } - $regions[] = [ - 'key' => self::text($region['key'] ?? '', 'region:unknown'), - 'kind' => self::text($region['kind'] ?? '', 'unassigned'), - 'name' => self::text($region['name'] ?? '', '地区待配置'), - 'description' => self::text( - $region['description'] ?? '', - '按线路独立核算共享额度' - ), - 'pool_count' => max(0, (int) ($region['pool_count'] ?? 0)), - 'instance_count' => max( - 0, - (int) ($region['instance_count'] ?? 0) - ), - 'state_label' => $stateLabel, - 'state_class' => $stateClass, - 'requires_attention' => - ($region['requires_attention'] ?? false) === true, - 'default_open' => ($region['default_open'] ?? false) === true, - 'items' => $items, - ]; + $item = self::trafficPool($pool); + $item['key'] = self::text( + $pool['key'] ?? '', + 'line-group:' . (int) ($pool['group_id'] ?? 0) + ); + $item['coverage_display'] = $coverage === [] + ? '覆盖地区待核查' + : '覆盖:' . implode('、', $coverage); + $item['coverage_region_count'] = max( + 0, + (int) ($pool['coverage_region_count'] ?? count($coverage)) + ); + $item['instance_count'] = max( + 0, + (int) ($pool['instance_count'] ?? count($item['instances'])) + ); + $item['summary_state_label'] = $stateLabel; + $item['summary_state_class'] = $stateClass; + $item['requires_attention'] = + ($pool['requires_attention'] ?? false) === true; + $item['default_open'] = ($pool['default_open'] ?? false) === true; + $linePools[] = $item; } return [ - 'regions' => $regions, - 'region_count' => max(0, (int) ($payload['region_count'] ?? 0)), - 'pool_count' => max(0, (int) ($payload['pool_count'] ?? 0)), + 'line_pools' => $linePools, + 'line_pool_count' => max( + 0, + (int) ($payload['line_pool_count'] ?? count($linePools)) + ), ]; } @@ -176,26 +183,18 @@ final class CloudUserPageView 'expires_display' => self::date( $instance['service_expires_at'] ?? null ), + 'region_label' => self::text( + is_array($instance['region'] ?? null) + ? ($instance['region']['name'] ?? '') : '', + '地区待核查' + ), 'network_label' => $instanceNetworkLabel, 'network_class' => $instanceNetworkClass, ]; } - $scope = $pool['region_scope'] ?? []; - $scopeNames = array_map( - static fn (array $region): string => (string) ($region['name'] ?? ''), - array_values(array_filter( - is_array($scope['regions'] ?? null) ? $scope['regions'] : [], - 'is_array' - )) - ); - $scopeKind = (string) ($scope['kind'] ?? ''); - $scopeNote = $scopeKind === 'cross_region' - ? '涉及 ' . implode('、', array_filter($scopeNames)) - : ($scopeKind === 'unassigned' ? '地区信息待核查' : ''); return [ 'group_id' => (int) ($pool['group_id'] ?? 0), 'name' => self::text($pool['name'] ?? '', '共享流量池'), - 'scope_note' => $scopeNote, 'state_label' => $stateLabel, 'state_class' => $stateClass, 'network_label' => $networkLabel, diff --git a/web/public/cloud/styles.css b/web/public/cloud/styles.css index 0b12a3cf..40ef2f88 100644 --- a/web/public/cloud/styles.css +++ b/web/public/cloud/styles.css @@ -305,24 +305,26 @@ body.vu-body .ssh-key-picker-manage:hover { .cloud-traffic-panel>.panel-heading{padding:20px 22px;border-bottom:1px solid #e8eef2} .cloud-traffic-panel>#cloud-traffic-status{margin:18px 22px 0} .cloud-traffic-list{display:grid;gap:16px;padding:20px 22px} -.cloud-traffic-region{min-width:0;border:1px solid #dbe6eb;border-radius:14px;background:#f8fbfc;overflow:hidden} -.cloud-traffic-region-summary{display:flex;align-items:center;justify-content:space-between;gap:20px;min-height:72px;padding:14px 18px;background:#fff;cursor:pointer;list-style:none;user-select:none} -.cloud-traffic-region-summary::-webkit-details-marker{display:none} -.cloud-traffic-region-summary::marker{content:""} -.cloud-traffic-region-summary:hover{background:#fbfefe} -.cloud-traffic-region-summary:focus-visible{outline:3px solid rgba(18,166,176,.22);outline-offset:-3px} -.cloud-traffic-region[open]>.cloud-traffic-region-summary{border-bottom:1px solid #e3ebef;background:#fbfefe} -.cloud-traffic-region-identity{display:flex;align-items:center;gap:12px;min-width:0} -.cloud-traffic-region-icon{display:grid;place-items:center;flex:0 0 38px;width:38px;height:38px;border-radius:11px;background:#eaf7f8;color:#178e98;font-size:18px} -.cloud-traffic-region-title{display:grid;gap:4px;min-width:0} -.cloud-traffic-region-title strong{color:#2c465a;font-size:14px;overflow-wrap:anywhere} -.cloud-traffic-region-title small{color:#8496a4;font-size:10px;line-height:1.45;overflow-wrap:anywhere} -.cloud-traffic-region-meta{display:flex;align-items:center;justify-content:flex-end;gap:11px;flex:none} -.cloud-traffic-region-counts{display:flex;align-items:center;gap:9px;color:#718594;font-size:10px;white-space:nowrap} -.cloud-traffic-region-counts>span+span{padding-left:9px;border-left:1px solid #dce5e9} -.cloud-traffic-region-arrow{display:grid;place-items:center;width:26px;height:26px;color:#738997;font-size:18px;transition:transform .18s ease} -.cloud-traffic-region[open] .cloud-traffic-region-arrow{transform:rotate(180deg)} -.cloud-traffic-region-body{display:grid;gap:14px;padding:16px;background:#f7fafb} +.cloud-traffic-line{min-width:0;border:1px solid #dbe6eb;border-radius:14px;background:#f8fbfc;overflow:hidden} +.cloud-traffic-line-summary{display:flex;align-items:center;justify-content:space-between;gap:20px;min-height:72px;padding:14px 18px;background:#fff;cursor:pointer;list-style:none;user-select:none} +.cloud-traffic-line-summary::-webkit-details-marker{display:none} +.cloud-traffic-line-summary::marker{content:""} +.cloud-traffic-line-summary:hover{background:#fbfefe} +.cloud-traffic-line-summary:focus-visible{outline:3px solid rgba(18,166,176,.22);outline-offset:-3px} +.cloud-traffic-line[open]>.cloud-traffic-line-summary{border-bottom:1px solid #e3ebef;background:#fbfefe} +.cloud-traffic-line-identity{display:flex;align-items:center;gap:12px;min-width:0} +.cloud-traffic-line-icon{display:grid;place-items:center;flex:0 0 38px;width:38px;height:38px;border-radius:11px;background:#eaf7f8;color:#178e98;font-size:18px} +.cloud-traffic-line-title{display:grid;gap:4px;min-width:0} +.cloud-traffic-line-title strong{color:#2c465a;font-size:14px;overflow-wrap:anywhere} +.cloud-traffic-line-title small{color:#8496a4;font-size:10px;line-height:1.45;overflow-wrap:anywhere} +.cloud-traffic-line-meta{display:flex;align-items:center;justify-content:flex-end;gap:11px;flex:none} +.cloud-traffic-line-counts{display:flex;align-items:center;gap:9px;color:#718594;font-size:10px;white-space:nowrap} +.cloud-traffic-line-counts>span+span{padding-left:9px;border-left:1px solid #dce5e9} +.cloud-traffic-line-arrow{display:grid;place-items:center;width:26px;height:26px;color:#738997;font-size:18px;transition:transform .18s ease} +.cloud-traffic-line[open] .cloud-traffic-line-arrow{transform:rotate(180deg)} +.cloud-traffic-line-body{display:grid;gap:14px;padding:16px;background:#f7fafb} +.cloud-traffic-line-intro{display:flex;align-items:center;justify-content:space-between;gap:16px;margin-bottom:15px} +.cloud-traffic-line-intro p{margin:0;color:#748895;font-size:11px;line-height:1.6} .cloud-traffic-card{display:grid;gap:18px;min-width:0;padding:19px;border:1px solid #dfe8ed;border-radius:12px;background:#fff} .cloud-traffic-card-heading{display:flex;align-items:flex-start;justify-content:space-between;gap:18px} .cloud-traffic-card-heading>div:first-child{display:flex;align-items:center;gap:12px;min-width:0} @@ -357,7 +359,7 @@ body.vu-body .ssh-key-picker-manage:hover { .cloud-traffic-empty>span:last-child{font-size:10px;line-height:1.6} @media(max-width:1100px){.cloud-traffic-instance{grid-template-columns:1fr}.cloud-traffic-instance dl{grid-template-columns:repeat(2,minmax(0,1fr))}} @media(max-width:820px){.cloud-traffic-facts{grid-template-columns:repeat(2,minmax(0,1fr))}} -@media(max-width:510px){.cloud-traffic-panel>.panel-heading,.cloud-traffic-list{padding-inline:16px}.cloud-traffic-panel>.panel-heading{align-items:flex-start}.cloud-traffic-panel>.panel-heading>.state-pill{white-space:normal}.cloud-traffic-region-summary{align-items:stretch;flex-direction:column;gap:11px;min-height:88px;padding:14px}.cloud-traffic-region-meta{justify-content:space-between;width:100%;gap:8px}.cloud-traffic-region-counts{gap:7px}.cloud-traffic-region-counts>span+span{padding-left:7px}.cloud-traffic-region-meta>.state-pill{margin-left:auto;white-space:normal;text-align:center}.cloud-traffic-region-arrow{flex:0 0 26px}.cloud-traffic-region-body{gap:12px;padding:12px}.cloud-traffic-card{padding:15px}.cloud-traffic-card-heading{align-items:flex-start;flex-direction:column}.cloud-traffic-state-group{justify-content:flex-start}.cloud-traffic-facts{grid-template-columns:1fr 1fr}.cloud-traffic-instance{padding:12px}.cloud-traffic-instance dl{grid-template-columns:1fr}.cloud-traffic-instance dl>div{display:flex;align-items:center;justify-content:space-between;gap:10px}.cloud-traffic-instance dd{text-align:right}} +@media(max-width:510px){.cloud-traffic-panel>.panel-heading,.cloud-traffic-list{padding-inline:16px}.cloud-traffic-panel>.panel-heading{align-items:flex-start}.cloud-traffic-panel>.panel-heading>.state-pill{white-space:normal}.cloud-traffic-line-summary{align-items:stretch;flex-direction:column;gap:11px;min-height:88px;padding:14px}.cloud-traffic-line-meta{justify-content:space-between;width:100%;gap:8px}.cloud-traffic-line-counts{gap:7px}.cloud-traffic-line-counts>span+span{padding-left:7px}.cloud-traffic-line-meta>.state-pill{margin-left:auto;white-space:normal;text-align:center}.cloud-traffic-line-arrow{flex:0 0 26px}.cloud-traffic-line-body{gap:12px;padding:12px}.cloud-traffic-card{padding:15px}.cloud-traffic-line-intro{align-items:flex-start;flex-direction:column}.cloud-traffic-state-group{justify-content:flex-start}.cloud-traffic-facts{grid-template-columns:1fr 1fr}.cloud-traffic-instance{padding:12px}.cloud-traffic-instance dl{grid-template-columns:1fr}.cloud-traffic-instance dl>div{display:flex;align-items:center;justify-content:space-between;gap:10px}.cloud-traffic-instance dd{text-align:right}} /* VPC list, creation and member views share the existing user shell. */ #cloud-vpcs-workspace { color:#304a5d; min-width:0; scroll-margin-top:100px; } diff --git a/web/public/cloud/traffic.js b/web/public/cloud/traffic.js index 262c144a..5b213d7f 100644 --- a/web/public/cloud/traffic.js +++ b/web/public/cloud/traffic.js @@ -12,7 +12,7 @@ const { } = await import(versionedModuleUrl('./runtime.js')); const state = { - regions: [], regionCount: 0, poolCount: 0, + linePools: [], linePoolCount: 0, loading: false, controller: null, }; @@ -65,13 +65,13 @@ function restrictionState(value) { })[String(value || '')] || ['网络状态未知', 'other']; } -function regionState(value) { +function linePoolState(value) { return ({ available: ['状态正常', 'running'], preparing: ['额度准备中', 'warning'], applying: ['网络策略应用中', 'warning'], - exhausted: ['存在已用尽流量池', 'stopped'], - restricted: ['存在断网实例', 'stopped'], + exhausted: ['流量已用尽', 'stopped'], + restricted: ['线路池已断网', 'stopped'], attention: ['需要核查', 'stopped'], })[String(value || '')] || ['状态未知', 'other']; } @@ -106,8 +106,9 @@ function renderInstances(pool, section) { const link = element('a', 'cloud-traffic-instance'); link.href = `/user/cloud/instances/${encodeURIComponent(String(instance.id || ''))}`; const identity = document.createElement('div'); + const regionName = String(instance?.region?.name || '').trim() || '地区待核查'; identity.append(element('strong', '', instance.name || `实例 #${instance.id || ''}`), - element('small', '', `到期 ${formatDate(instance.service_expires_at, '时间未记录')}`)); + element('small', '', `${regionName} · 到期 ${formatDate(instance.service_expires_at, '时间未记录')}`)); const facts = document.createElement('dl'); facts.append(fact('本周期总额度', formatBytes(instance.period_traffic_quota_bytes)), fact('本实例已用', formatBytes(instance.traffic_used_bytes)), @@ -124,34 +125,26 @@ function renderInstances(pool, section) { section.append(heading, list); } -function poolScopeNote(pool) { - const scope = pool?.region_scope; - if (scope?.kind === 'unassigned') return '地区信息待核查'; - if (scope?.kind !== 'cross_region') return ''; +function coverageLabel(pool) { const names = []; - for (const region of Array.isArray(scope.regions) ? scope.regions : []) { + for (const region of Array.isArray(pool?.coverage_regions) ? pool.coverage_regions : []) { const name = String(region?.name || '').trim(); if (name && !names.includes(name)) names.push(name); } - return names.length ? `涉及 ${names.join('、')}` : '跨地区线路组'; + return names.length ? `覆盖:${names.join('、')}` : '覆盖地区待核查'; } -function renderPool(pool) { +function renderLineContent(pool) { const projectionReady = pool.projection_ready === true; - const card = element('article', 'cloud-traffic-card'); - const heading = element('header', 'cloud-traffic-card-heading'); - const identity = document.createElement('div'); - const title = document.createElement('div'); - const note = poolScopeNote(pool); - title.append(element('h3', '', pool.name || '共享流量池'), - element('p', '', `${note ? `${note} · ` : ''}共享额度按最早到期批次优先消耗`)); - identity.append(poolIcon(), title); + const card = element('article', 'cloud-traffic-card cloud-traffic-line-content'); + const intro = element('div', 'cloud-traffic-line-intro'); + intro.append(element('p', '', '线路内全部地区共享额度,并按最早到期批次优先消耗。')); const states = element('div', 'cloud-traffic-state-group'); const [stateLabel, stateClass] = poolState(pool.state); const [networkLabel, networkClass] = restrictionState(pool.network_restriction_state); states.append(element('span', `state-pill ${stateClass}`, stateLabel), element('span', `state-pill ${networkClass}`, networkLabel)); - heading.append(identity, states); + intro.append(states); const facts = element('dl', 'cloud-traffic-facts'); const pending = '正在准备'; facts.append(fact('当前有效额度', projectionReady @@ -170,16 +163,16 @@ function renderPool(pool) { const instances = element('section', 'cloud-traffic-instances'); instances.setAttribute('aria-label', `${pool.name || '共享流量池'} 中的当前实例`); renderInstances(pool, instances); - card.append(heading, facts, instances); + card.append(intro, facts, instances); return card; } -function existingRegionState(list) { +function existingLinePoolState(list) { const result = new Map(); for (const details of list.querySelectorAll( - 'details.cloud-traffic-region[data-region-key]', + 'details.cloud-traffic-line[data-line-key]', )) { - result.set(details.getAttribute('data-region-key'), { + result.set(details.getAttribute('data-line-key'), { open: details.open === true, requiresAttention: details.getAttribute('data-requires-attention') === '1', }); @@ -187,68 +180,65 @@ function existingRegionState(list) { return result; } -function renderRegion(region, previousState) { - const key = String(region.key || 'region:unknown'); - const details = element('details', 'cloud-traffic-region'); - details.setAttribute('data-region-key', key); - const requiresAttention = region.requires_attention === true; +function renderLinePool(pool, previousState) { + const key = String(pool.key || `line-group:${Number(pool.group_id) || 0}`); + const details = element('details', 'cloud-traffic-line'); + details.setAttribute('data-line-key', key); + const requiresAttention = pool.requires_attention === true; details.setAttribute('data-requires-attention', requiresAttention ? '1' : '0'); const previous = previousState.get(key); details.open = previous ? (requiresAttention && !previous.requiresAttention ? true : previous.open) - : region.default_open === true; - const summary = element('summary', 'cloud-traffic-region-summary'); - const identity = element('span', 'cloud-traffic-region-identity'); - const icon = element('span', 'cloud-traffic-region-icon'); - const marker = element('i', 'mdi mdi-map-marker-radius'); + : pool.default_open === true; + const summary = element('summary', 'cloud-traffic-line-summary'); + const identity = element('span', 'cloud-traffic-line-identity'); + const icon = element('span', 'cloud-traffic-line-icon'); + const marker = element('i', 'mdi mdi-lan-connect'); marker.setAttribute('aria-hidden', 'true'); icon.append(marker); - const title = element('span', 'cloud-traffic-region-title'); - title.append(element('strong', '', region.name || '地区待配置'), - element('small', '', region.description || '按线路独立核算共享额度')); + const title = element('span', 'cloud-traffic-line-title'); + title.append(element('strong', '', pool.name || '线路流量池'), + element('small', '', coverageLabel(pool))); identity.append(icon, title); - const meta = element('span', 'cloud-traffic-region-meta'); - const counts = element('span', 'cloud-traffic-region-counts'); - counts.append(element('span', '', `${Number(region.pool_count) || 0} 个流量池`), - element('span', '', `${Number(region.instance_count) || 0} 台实例`)); - const [statusLabel, statusClass] = regionState(region.summary_state); - const arrow = element('span', 'cloud-traffic-region-arrow', '⌄'); + const meta = element('span', 'cloud-traffic-line-meta'); + const counts = element('span', 'cloud-traffic-line-counts'); + counts.append(element('span', '', `${Number(pool.coverage_region_count) || 0} 个地区`), + element('span', '', `${Number(pool.instance_count) || 0} 台实例`)); + const [statusLabel, statusClass] = linePoolState(pool.summary_state); + const arrow = element('span', 'cloud-traffic-line-arrow', '⌄'); arrow.setAttribute('aria-hidden', 'true'); meta.append(counts, element('span', `state-pill ${statusClass}`, statusLabel), arrow); summary.append(identity, meta); - const body = element('div', 'cloud-traffic-region-body'); - for (const pool of Array.isArray(region.items) ? region.items : []) { - if (pool && typeof pool === 'object') body.append(renderPool(pool)); - } + const body = element('div', 'cloud-traffic-line-body'); + body.append(renderLineContent(pool)); details.append(summary, body); return details; } function render() { const list = byId('cloud-traffic-list'); - const previousState = existingRegionState(list); + const previousState = existingLinePoolState(list); list.replaceChildren(); - if (!state.regions.length) { + if (!state.linePools.length) { const empty = element('div', 'cloud-traffic-empty'); - empty.append(poolIcon(), element('strong', '', '当前没有已启用的共享流量池'), - element('span', '', '管理员完成影子核算验收并启用后,将在这里显示共享额度。')); + empty.append(poolIcon(), element('strong', '', '当前没有已启用的线路流量池'), + element('span', '', '管理员完成影子核算验收并启用后,将在这里显示线路共享额度。')); list.append(empty); } - for (const region of state.regions) { - list.append(renderRegion(region, previousState)); + for (const pool of state.linePools) { + list.append(renderLinePool(pool, previousState)); } byId('cloud-traffic-count').textContent = - `${state.regionCount} 个地区分组 · ${state.poolCount} 个流量池`; + `${state.linePoolCount} 个线路流量池`; byId('cloud-traffic-refresh').disabled = state.loading; } function applyPayload(payload) { - const values = Array.isArray(payload?.region_groups) ? payload.region_groups : []; - state.regions = values.filter(region => region && typeof region === 'object' - && typeof region.key === 'string' && region.key !== '' - && Array.isArray(region.items)); - state.regionCount = Math.max(0, Number(payload?.region_count) || 0); - state.poolCount = Math.max(0, Number(payload?.pool_count) || 0); + const values = Array.isArray(payload?.line_pools) ? payload.line_pools : []; + state.linePools = values.filter(pool => pool && typeof pool === 'object' + && typeof pool.key === 'string' && pool.key !== '' + && Array.isArray(pool.instances)); + state.linePoolCount = Math.max(0, Number(payload?.line_pool_count) || 0); render(); } diff --git a/web/resources/views/venix/cloud/pages/traffic.tpl b/web/resources/views/venix/cloud/pages/traffic.tpl index b3cb75c2..638b2c3b 100644 --- a/web/resources/views/venix/cloud/pages/traffic.tpl +++ b/web/resources/views/venix/cloud/pages/traffic.tpl @@ -1,53 +1,48 @@
-
SHARED TRAFFIC

流量池

按地区和线路查看当前有效的共享流量额度、到期批次和实例采样。

+
SHARED TRAFFIC

流量池

按商业线路查看当前有效的共享流量额度、覆盖地区和实例采样。

额度按服务周期到期同一线路内的实例共享有效额度,并按最早到期优先消耗;实例到期时只作废该周期尚未使用的额度。
-

当前共享流量池

只显示已经进入强制执行的线路分组;地区用于整理线路,不会合并不同线路的额度;“本周期总额度”是该实例当前服务周期贡献给共享池的总额度。

- {$cloud_traffic_view.region_count|default:0|escape:'html'} 个地区分组 · {$cloud_traffic_view.pool_count|default:0|escape:'html'} 个流量池 +

当前线路流量池

同一用户在该商业线路覆盖的所有地区共同消耗一个流量池;不同线路的额度保持隔离。“本周期总额度”是该实例当前服务周期贡献给线路池的总额度。

+ {$cloud_traffic_view.line_pool_count|default:0|escape:'html'} 个线路流量池
- {foreach $cloud_traffic_view.regions|default:[] as $region} -
- - - - {$region.name|escape:'html'}{$region.description|escape:'html'} + {foreach $cloud_traffic_view.line_pools|default:[] as $pool} +
+ + + + {$pool.name|escape:'html'}{$pool.coverage_display|escape:'html'} - - {$region.pool_count|escape:'html'} 个流量池{$region.instance_count|escape:'html'} 台实例 - {$region.state_label|escape:'html'} - + + {$pool.coverage_region_count|escape:'html'} 个地区{$pool.instance_count|escape:'html'} 台实例 + {$pool.summary_state_label|escape:'html'} + -
- {foreach $region.items as $pool} -
-
-

{$pool.name|escape:'html'}

{if $pool.scope_note}{$pool.scope_note|escape:'html'} · {/if}共享额度按最早到期批次优先消耗

-
{$pool.state_label|escape:'html'}{$pool.network_label|escape:'html'}
-
-
当前有效额度
{$pool.entitlement_display|escape:'html'}
有效额度已消耗
{$pool.consumed_display|escape:'html'}
当前可用余额
{$pool.available_display|escape:'html'}
采样超额债务
{$pool.overage_display|escape:'html'}
下一批额度到期
{$pool.next_expiry_display|escape:'html'}{$pool.next_expiry_note|escape:'html'}
最近可信采样
{$pool.last_observed_display|escape:'html'}
-
-

当前实例采样

{$pool.instances|@count|escape:'html'} 台
- -
-
- {/foreach} +
+
+

线路内全部地区共享额度,并按最早到期批次优先消耗。

{$pool.state_label|escape:'html'}{$pool.network_label|escape:'html'}
+
当前有效额度
{$pool.entitlement_display|escape:'html'}
有效额度已消耗
{$pool.consumed_display|escape:'html'}
当前可用余额
{$pool.available_display|escape:'html'}
采样超额债务
{$pool.overage_display|escape:'html'}
下一批额度到期
{$pool.next_expiry_display|escape:'html'}{$pool.next_expiry_note|escape:'html'}
最近可信采样
{$pool.last_observed_display|escape:'html'}
+
+

当前实例采样

{$pool.instances|@count|escape:'html'} 台
+ +
+
{foreachelse} -
当前没有已启用的共享流量池管理员完成影子核算验收并启用后,将在这里显示共享额度。
+
当前没有已启用的线路流量池管理员完成影子核算验收并启用后,将在这里显示线路共享额度。
{/foreach}
diff --git a/web/resources/views/venix/layout_assets.tpl b/web/resources/views/venix/layout_assets.tpl index 4f86d516..47aebc10 100644 --- a/web/resources/views/venix/layout_assets.tpl +++ b/web/resources/views/venix/layout_assets.tpl @@ -1,2 +1,2 @@ {* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *} -{assign var=venix_asset_version value='2026110104' scope='global'} +{assign var=venix_asset_version value='2026110105' scope='global'} diff --git a/web/tests/CloudTrafficPoolRegionBehaviorTest.mjs b/web/tests/CloudTrafficPoolRegionBehaviorTest.mjs index 13a3034a..dbb3a57e 100644 --- a/web/tests/CloudTrafficPoolRegionBehaviorTest.mjs +++ b/web/tests/CloudTrafficPoolRegionBehaviorTest.mjs @@ -39,10 +39,10 @@ class Node { querySelectorAll(selector) { const matches = node => selector - === 'details.cloud-traffic-region[data-region-key]' + === 'details.cloud-traffic-line[data-line-key]' && node.tagName === 'DETAILS' - && node.className.split(/\s+/).includes('cloud-traffic-region') - && node.attributes.has('data-region-key'); + && node.className.split(/\s+/).includes('cloud-traffic-line') + && node.attributes.has('data-line-key'); return this.children.flatMap(child => [ ...(matches(child) ? [child] : []), ...child.querySelectorAll(selector), @@ -86,77 +86,72 @@ const pool = (id, name = `线路 ${id}`) => ({ next_expiry_bytes: 0, last_observed_at: null, instances: [], - region_scope: { kind: 'region', regions: [{ code: 'hkg', name: '香港' }] }, -}); -const region = (key, overrides = {}) => ({ - key, - kind: 'region', - name: key === 'region:hkg' ? '香港' : '新加坡', - description: '按线路独立核算共享额度', - pool_count: 1, + key: `line-group:${id}`, + coverage_regions: [{ code: 'hkg', name: '香港' }], + coverage_region_count: 1, instance_count: 0, summary_state: 'available', requires_attention: false, default_open: false, - items: [pool(key === 'region:hkg' ? 1 : 2)], +}); +const linePool = (id, overrides = {}) => ({ + ...pool(id), ...overrides, }); -const payload = regions => ({ - region_groups: regions, - region_count: regions.length, - pool_count: regions.length, +const payload = linePools => ({ + line_pools: linePools, + line_pool_count: linePools.length, }); const details = () => nodes.get('cloud-traffic-list') - .querySelectorAll('details.cloud-traffic-region[data-region-key]'); + .querySelectorAll('details.cloud-traffic-line[data-line-key]'); context.traffic.applyPayload(payload([ - region('region:hkg', { default_open: true }), - region('region:sgp'), + linePool(1, { default_open: true }), + linePool(2), ])); assert.deepEqual(details().map(item => item.open), [true, false], 'Server default-open projection was not applied.'); assert.equal(nodes.get('cloud-traffic-count').textContent, - '2 个地区分组 · 2 个流量池'); + '2 个线路流量池'); details()[0].open = false; details()[1].open = true; context.traffic.applyPayload(payload([ - region('region:hkg', { default_open: true }), - region('region:sgp'), + linePool(1, { default_open: true }), + linePool(2), ])); assert.deepEqual(details().map(item => item.open), [false, true], 'Refresh did not retain both expanded and collapsed user choices.'); context.traffic.applyPayload(payload([ - region('region:hkg', { + linePool(1, { summary_state: 'attention', requires_attention: true, default_open: true, }), - region('region:sgp'), + linePool(2), ])); assert.deepEqual(details().map(item => item.open), [true, true], - 'A region that changed from healthy to attention remained hidden.'); + 'A line pool that changed from healthy to attention remained hidden.'); details()[0].open = false; context.traffic.applyPayload(payload([ - region('region:hkg', { + linePool(1, { summary_state: 'attention', requires_attention: true, default_open: true, }), - region('region:sgp'), + linePool(2), ])); assert.deepEqual(details().map(item => item.open), [false, true], - 'A user-collapsed attention region reopened on every refresh.'); + 'A user-collapsed attention line pool reopened on every refresh.'); context.traffic.applyPayload(payload([ - region('region:hkg', { + linePool(1, { summary_state: 'attention', requires_attention: true, default_open: true, }), - region('region:sgp'), - region('region:unassigned', { - kind: 'unassigned', name: '地区待配置', + linePool(2), + linePool(3, { + coverage_regions: [], coverage_region_count: 0, summary_state: 'attention', requires_attention: true, default_open: true, - items: [pool(3)], }), ])); assert.deepEqual(details().map(item => item.open), [false, true, true], - 'A newly appearing attention region did not use its server default.'); + 'A newly appearing attention line pool did not use its server default.'); -console.log('Cloud traffic-pool region behavior checks passed.'); +console.log('Cloud traffic-pool line behavior checks passed.'); diff --git a/web/tests/CloudTrafficPoolUserUiContractTest.php b/web/tests/CloudTrafficPoolUserUiContractTest.php index 571c50da..144ac164 100644 --- a/web/tests/CloudTrafficPoolUserUiContractTest.php +++ b/web/tests/CloudTrafficPoolUserUiContractTest.php @@ -47,6 +47,10 @@ $assert(str_contains($readModel, && str_contains($readModel, "'network_restriction_state' => \$networkState") && str_contains($readModel, 'private static function regionScopes(') + && str_contains($readModel, "'line_pools' => \$linePools") + && str_contains($readModel, "'line_pool_count' => count(\$linePools)") + && str_contains($readModel, "\$item['coverage_regions'] = \$coverage") + && str_contains($readModel, "'placement_scope_state'") && str_contains($readModel, "'region_groups' => \$regionGroups") && str_contains($readModel, "'key' => 'region:cross'") && str_contains($readModel, "'key' => 'region:unassigned'"), @@ -91,16 +95,19 @@ $assert(str_contains($sidebar, 'href="/user/cloud/traffic"') && str_contains($template, '下一批额度到期') && str_contains($template, '本周期总额度') && str_contains($template, '{$instance.period_quota_display|escape:') - && str_contains($template, '当前服务周期贡献给共享池的总额度') + && str_contains($template, '当前服务周期贡献给线路池的总额度') && str_contains($template, '本实例已用') - && str_contains($template, 'details class="cloud-traffic-region"') - && str_contains($template, 'data-region-key=') + && str_contains($template, 'details class="cloud-traffic-line"') + && str_contains($template, 'data-line-key=') && str_contains($template, 'data-requires-attention=') - && str_contains($template, 'cloud-traffic-region-summary') - && str_contains($template, '{$region.pool_count|escape:') - && str_contains($template, '{$region.instance_count|escape:') - && str_contains($template, '{if $region.default_open} open{/if}') - && str_contains($template, '只显示已经进入强制执行的线路分组'), + && str_contains($template, 'cloud-traffic-line-summary') + && str_contains($template, '{$pool.coverage_display|escape:') + && str_contains($template, '{$pool.coverage_region_count|escape:') + && str_contains($template, '{$pool.instance_count|escape:') + && str_contains($template, '{if $pool.default_open} open{/if}') + && str_contains($template, '{$instance.region_label|escape:') + && str_contains($template, '同一用户在该商业线路覆盖的所有地区') + && !str_contains($template, 'cloud-traffic-region'), 'The user traffic-pool page lacks SSR first paint, navigation or clear shared-vs-instance copy.'); $assert(str_contains($script, @@ -110,12 +117,17 @@ $assert(str_contains($script, && !str_contains($script, "method: 'DELETE'") && !str_contains($script, '.reduce(') && !str_contains($script, '.innerHTML') - && str_contains($script, 'payload?.region_groups') - && str_contains($script, 'function existingRegionState(') + && str_contains($script, 'payload?.line_pools') + && str_contains($script, 'payload?.line_pool_count') + && str_contains($script, 'function existingLinePoolState(') && str_contains($script, 'const result = new Map()') && str_contains($script, "requiresAttention: details.getAttribute('data-requires-attention') === '1'") && str_contains($script, 'requiresAttention && !previous.requiresAttention') - && str_contains($script, 'region.default_open === true') + && str_contains($script, 'pool.default_open === true') + && str_contains($script, "details.cloud-traffic-line[data-line-key]") + && str_contains($script, 'coverageLabel(pool)') + && str_contains($script, 'instance?.region?.name') + && !str_contains($script, 'payload?.region_groups') && str_contains($script, 'pool.active_entitlement_bytes') && str_contains($script, 'pool.active_consumed_bytes') && str_contains($script, 'pool.available_bytes') @@ -126,6 +138,9 @@ $assert(str_contains($script, 'Browser code must only refresh the server projection and must not mutate, sum or inject traffic data.'); $assert(str_contains($view, 'function trafficPools(') + && str_contains($view, "\$payload['line_pools']") + && str_contains($view, "'coverage_display'") + && str_contains($view, "'region_label'") && str_contains($view, "'network_restriction_state'") && str_contains($view, "'period_quota_display'") && str_contains($readModel, "'period_traffic_quota_bytes'") @@ -133,11 +148,13 @@ $assert(str_contains($view, 'function trafficPools(') && str_contains($detail, '本实例本期下载(RX)') && str_contains($detail, '本实例本期上传(TX)') && str_contains($styles, '.cloud-traffic-facts') - && str_contains($styles, '.cloud-traffic-region-summary') + && str_contains($styles, '.cloud-traffic-line-summary') && str_contains($styles, - '.cloud-traffic-region-summary::-webkit-details-marker') + '.cloud-traffic-line-summary::-webkit-details-marker') && str_contains($styles, - '.cloud-traffic-region[open] .cloud-traffic-region-arrow') + '.cloud-traffic-line[open] .cloud-traffic-line-arrow') + && str_contains($styles, '.cloud-traffic-line-intro') + && !str_contains($styles, '.cloud-traffic-region') && str_contains($styles, '.cloud-traffic-instance') && str_contains($styles, '.cloud-traffic-instance dl{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr))')