|
|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|