feat(admin/vm): 流量概览展示新字段 + 修改入口改挂 traffic_policy 接口
缘由:上次(802eaa3)我把概览"流量上限"的"修改"按钮挂到旧 update_traffic 接口
(兼容字段 traffic_max),与 docs/2026.05.08.12.37-add.json 中真正的流量策略接口
(traffic_policy/update + add_fixed + add_temporary)路径错位;同时 vm 详情返回
已新增 traffic_max_mb / temporary_traffic_mb / temporary_cycle_start / traffic_used /
traffic_exhausted_rx_mbps / traffic_exhausted_tx_mbps 等字段,概览未体现。
修改:
- UserVmDetail.vue & VmDetail.vue 概览将"流量上限"单值 cell 改为分段展示:
主行 已用/总量;副行 基础 + 临时(含周期起始日期);按钮组「修改」「加临时」。
- 主行/副行字段来源 add.json 新字段,旧 traffic_max 仅作 fallback。
- 「修改」按钮改挂 openTrafficPolicyDialog / openVmTrafficPolicyDialog
(对应 user_vm/traffic_policy/update 与 host_service/point/vm/traffic_policy/update);
「加临时」直达 openAddTrafficDialog('temporary') / openVmAddTrafficDialog('temporary')。
- openTrafficPolicyDialog / openVmTrafficPolicyDialog 增加 vm / detail 字段 fallback,
并在 trafficPolicy 未加载时异步触发 loadTrafficPolicy,避免懒加载导致初值全 0。
- 新增 formatTrafficMb helper(VmDetail.vue)处理 MB 自适应单位、对 0 友好输出。
- 新增 .traffic-cell 系列样式。
预期:
- 详情概览能直接看到 总/已用/基础/临时/周期 五个关键信息。
- 概览"修改"走 add.json 中的新流量策略接口,与"流量策略" tab 行为一致。
- 旧 dropdown 中"修改带宽"路径保留(不删除),用于纯带宽场景。
未测试:admin_dashboard_pc 本地 HMR 已更新,无编译/控制台报错。新流量策略接口与
真实 vm.value 字段填充尚需联调验证(特别是 traffic_used 单位假设为 MB,若实际为
字节需调整 formatTraffic / detailTrafficUsedMb 的换算)。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -130,12 +130,22 @@
|
||||
</span>
|
||||
</div>
|
||||
<div class="config-cell">
|
||||
<span class="config-label">流量上限</span>
|
||||
<span class="config-value">
|
||||
{{ formatTraffic(vm.traffic_max) }}
|
||||
<el-button link type="primary" size="small" class="cfg-edit-btn" @click="handleMoreCmd('updateTraffic')">
|
||||
<el-icon :size="14"><Edit /></el-icon>修改
|
||||
</el-button>
|
||||
<span class="config-label">流量</span>
|
||||
<span class="config-value traffic-cell">
|
||||
<span class="traffic-main">{{ formatTraffic(trafficUsedMb) }} / {{ formatTraffic(trafficTotalMb) }}</span>
|
||||
<span class="traffic-sub">
|
||||
基础 {{ formatTraffic(trafficBaseMb) }}
|
||||
<template v-if="trafficTempMb > 0">
|
||||
· 临时 {{ formatTraffic(trafficTempMb) }}
|
||||
<span v-if="trafficCycleStartText" class="traffic-cycle">(周期 {{ trafficCycleStartText }})</span>
|
||||
</template>
|
||||
</span>
|
||||
<span class="traffic-actions">
|
||||
<el-button link type="primary" size="small" class="cfg-edit-btn" @click="openTrafficPolicyDialog">
|
||||
<el-icon :size="14"><Edit /></el-icon>修改
|
||||
</el-button>
|
||||
<el-button link type="warning" size="small" class="cfg-edit-btn" @click="openAddTrafficDialog('temporary')">加临时</el-button>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="config-cell"><span class="config-label">续费价格</span><span class="config-value">¥{{ (userGoods.renewPrice / 100).toFixed(2) }}</span></div>
|
||||
@@ -1180,6 +1190,18 @@ const copyAllIps = async (ipList) => {
|
||||
|
||||
const isWindows = computed(() => vmImage.value?.os_type === 'windows')
|
||||
|
||||
// 流量字段优先使用 traffic_max_mb(add.json 新字段),fallback 旧字段 traffic_max
|
||||
// traffic_used 单位假设为 MB(与 traffic_max_mb 同维度),如后端实为字节需调整
|
||||
const trafficBaseMb = computed(() => Number(vm.value?.traffic_max_mb ?? vm.value?.traffic_max ?? 0) || 0)
|
||||
const trafficTempMb = computed(() => Number(vm.value?.temporary_traffic_mb || 0))
|
||||
const trafficTotalMb = computed(() => trafficBaseMb.value + trafficTempMb.value)
|
||||
const trafficUsedMb = computed(() => Number(vm.value?.traffic_used || 0))
|
||||
const trafficCycleStartText = computed(() => {
|
||||
const t = vm.value?.temporary_cycle_start
|
||||
const sec = typeof t === 'object' ? (t?.seconds ?? null) : t
|
||||
return sec ? dayjs(Number(sec) * 1000).format('YYYY-MM-DD') : ''
|
||||
})
|
||||
|
||||
const vmPublicIpList = computed(() => {
|
||||
return vmNetworks.value.filter(n => n.type === 'bridge').map(n => n.address ? n.address.split('/')[0] : n.name).filter(Boolean)
|
||||
})
|
||||
@@ -2078,12 +2100,15 @@ const loadTrafficPolicy = async () => {
|
||||
}
|
||||
|
||||
const openTrafficPolicyDialog = () => {
|
||||
// 从概览触发时 trafficPolicy 可能尚未加载(trafficPolicy tab 懒加载),
|
||||
// 用 vm.value 上 add.json 新字段作 fallback;同时异步加载策略以便后续 submit 时数据准确
|
||||
Object.assign(trafficPolicyForm, {
|
||||
traffic_max_mb: trafficPolicy.value?.traffic_max_mb || 0,
|
||||
exhausted_rx_mbps: trafficPolicy.value?.exhausted_rx_mbps || 0,
|
||||
exhausted_tx_mbps: trafficPolicy.value?.exhausted_tx_mbps || 0
|
||||
traffic_max_mb: trafficPolicy.value?.traffic_max_mb ?? vm.value?.traffic_max_mb ?? vm.value?.traffic_max ?? 0,
|
||||
exhausted_rx_mbps: trafficPolicy.value?.exhausted_rx_mbps ?? vm.value?.traffic_exhausted_rx_mbps ?? 0,
|
||||
exhausted_tx_mbps: trafficPolicy.value?.exhausted_tx_mbps ?? vm.value?.traffic_exhausted_tx_mbps ?? 0
|
||||
})
|
||||
trafficPolicyVisible.value = true
|
||||
if (!trafficPolicy.value) loadTrafficPolicy()
|
||||
}
|
||||
|
||||
const submitUpdateTrafficPolicy = async () => {
|
||||
@@ -2416,6 +2441,12 @@ onBeforeUnmount(() => { disposeCharts() })
|
||||
.config-value { font-size: 13px; color: #1d2129; line-height: 1.4; word-break: break-all; }
|
||||
.cfg-edit-btn { margin-left: 8px; padding: 0 4px; height: 18px; vertical-align: middle; }
|
||||
.cfg-edit-btn .el-icon { margin-right: 2px; vertical-align: -2px; }
|
||||
.traffic-cell { display: flex; flex-direction: column; gap: 2px; }
|
||||
.traffic-cell .traffic-main { font-size: 13px; color: #1d2129; }
|
||||
.traffic-cell .traffic-sub { font-size: 12px; color: #86909c; line-height: 1.3; }
|
||||
.traffic-cell .traffic-cycle { color: #c0c4cc; margin-left: 2px; }
|
||||
.traffic-cell .traffic-actions { display: inline-flex; gap: 6px; margin-top: 2px; }
|
||||
.traffic-cell .traffic-actions .cfg-edit-btn { margin-left: 0; }
|
||||
.pwd-value { display: inline-flex; align-items: center; gap: 4px; }
|
||||
.pwd-text { font-family: 'Consolas', 'Monaco', monospace; font-size: 13px; background: #f5f7fa; padding: 2px 8px; border-radius: 3px; letter-spacing: .5px; user-select: all; }
|
||||
.pwd-btn { padding: 0 !important; height: auto !important; min-height: auto !important; }
|
||||
|
||||
Reference in New Issue
Block a user