fix: 将迁移记录移入主控服务详情 #30

Merged
shiran merged 4 commits from master into deploy 2026-08-04 09:34:56 +08:00
2 changed files with 37 additions and 2 deletions
Showing only changes of commit 1d013df0c1 - Show all commits
+18 -1
View File
@@ -2000,6 +2000,19 @@ const loadHostOptions = async () => {
} catch { /* */ }
}
const readHostId = value => Number(value?.host_id ?? value?.hostId ?? value?.HostId ?? 0) || 0
const resolveVmHostId = responseData => {
const vm = responseData?.data ?? responseData?.vm ?? responseData
const volumes = responseData?.volumes || []
const networks = responseData?.networks || []
const systemVolume = volumes.find(volume => (volume.is_system ?? volume.isSystem) && readHostId(volume))
const anyVolume = volumes.find(volume => readHostId(volume))
const anyNetwork = networks.find(network => readHostId(network))
return readHostId(responseData) || readHostId(responseData?.host) || readHostId(vm) ||
readHostId(systemVolume) || readHostId(anyVolume) || readHostId(anyNetwork) ||
Number(route.query.host_id) || 0
}
const loadDetail = async () => {
if (!vmId.value) return
loading.value = true
@@ -2024,7 +2037,7 @@ const loadDetail = async () => {
}
vmPortGroup.value = d.in_port_group || null
vmOutPortGroup.value = d.out_port_group || null
vmHostId.value = detail.value?.host_id || vmVolumes.value[0]?.host_id || vmNetworks.value[0]?.host_id || 0
vmHostId.value = resolveVmHostId(d)
handleDetailMigrateState()
} else ElMessage.error(extractApiError(res?.data, '加载失败'))
} catch (e) { ElMessage.error(extractApiError(e?.response?.data, '加载失败')) } finally { loading.value = false }
@@ -2162,6 +2175,10 @@ const vmMemPercent = (m) => {
const loadHistoricalMetrics = async () => {
if (!serviceId.value || !detail.value?.name) return
if (!vmHostId.value) {
ElMessage.warning('未获取到虚拟机所属宿主机,无法加载监控指标')
return
}
const range = getMonitorTimeRange()
if (!range) return
historicalMetricsLoading.value = true
+19 -1
View File
@@ -987,6 +987,18 @@ const handleExitRescue = (row) => {
}).catch(() => {})
}
const readHostId = value => Number(value?.host_id ?? value?.hostId ?? value?.HostId ?? 0) || 0
const resolveVmHostId = responseData => {
const vm = responseData?.data ?? responseData?.vm ?? responseData
const volumes = responseData?.volumes || []
const networks = responseData?.networks || []
const systemVolume = volumes.find(volume => (volume.is_system ?? volume.isSystem) && readHostId(volume))
const anyVolume = volumes.find(volume => readHostId(volume))
const anyNetwork = networks.find(network => readHostId(network))
return readHostId(responseData) || readHostId(responseData?.host) || readHostId(vm) ||
readHostId(systemVolume) || readHostId(anyVolume) || readHostId(anyNetwork) || 0
}
const handleViewDetail = async (row) => {
detailVisible.value = true
detailLoading.value = true
@@ -1001,6 +1013,7 @@ const handleViewDetail = async (row) => {
vm.volumes = d.volumes || []
vm.image = d.image || null
vm.in_port_group = d.in_port_group || null
vm.host_id = resolveVmHostId(d) || Number(hostId.value) || 0
if (!vm.ips && vm.networks?.length) vm.ips = vm.networks.map(n => n.address?.split('/')[0]).filter(Boolean).join(', ')
currentDetail.value = vm
}
@@ -1023,11 +1036,16 @@ const fetchVmStatus = async (vm) => {
const fetchVmMetrics = async (vm) => {
try {
const metricsHostId = readHostId(vm) || Number(hostId.value) || 0
if (!metricsHostId) {
ElMessage.warning('未获取到虚拟机所属宿主机,无法查看指标')
return
}
const now = new Date()
const start = new Date(now.getTime() - 60 * 60 * 1000)
const res = await getMetricsHistory({
service_id: serviceId.value,
host_id: vm.host_id || hostId.value,
host_id: metricsHostId,
vm_name: vm.name,
start: start.toISOString(),
end_time: now.toISOString(),