fix: 修改内存的基础单位为kb
This commit is contained in:
@@ -23,9 +23,9 @@
|
||||
<el-input v-model="keyword" placeholder="搜索镜像名称" clearable style="width: 220px" @keyup.enter="handleSearch" @clear="handleSearch">
|
||||
<template #prefix><el-icon><Search /></el-icon></template>
|
||||
</el-input>
|
||||
<el-select v-model="filterHostId" placeholder="选择宿主机" clearable style="width: 180px" @change="handleSearch">
|
||||
<!-- <el-select v-if="!injectedHostId?.value" v-model="filterHostId" placeholder="选择宿主机" clearable style="width: 180px" @change="handleSearch">
|
||||
<el-option v-for="h in hostOptions" :key="h.id" :label="h.name || h.ip" :value="h.id" />
|
||||
</el-select>
|
||||
</el-select> -->
|
||||
<el-select v-model="filterOsType" placeholder="系统类型" clearable style="width: 130px" @change="handleSearch">
|
||||
<el-option label="Linux" value="linux" />
|
||||
<el-option label="Windows" value="windows" />
|
||||
@@ -61,6 +61,17 @@
|
||||
<el-tag :type="statusType(row.status)" size="small">{{ statusLabel(row.status) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-if="injectedHostId?.value" label="同步状态" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="syncStatusType(row.sync_status)" size="small">{{ syncStatusLabel(row.sync_status) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-if="injectedHostId?.value" label="宿主机状态" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.host_status" :type="statusType(row.host_status)" size="small">{{ statusLabel(row.host_status) }}</el-tag>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="path" label="路径" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column label="大小" width="90">
|
||||
<template #default="{ row }">{{ row.size ? formatSize(row.size) : '-' }}</template>
|
||||
@@ -69,7 +80,6 @@
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="handleGoDetail(row)">详情</el-button>
|
||||
<el-button link type="success" @click="handleSyncToHost(row)">同步</el-button>
|
||||
<el-button link type="warning" @click="handleReloadMaster(row)">主控重下载</el-button>
|
||||
<el-button link type="warning" @click="handleReloadOnHost(row)">宿主机重下载</el-button>
|
||||
<el-button link type="danger" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
@@ -218,7 +228,7 @@ import { useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Plus, Refresh, Search, ArrowLeft } from '@element-plus/icons-vue'
|
||||
import {
|
||||
getImageList, getImageDetail, getImageHostStatus, createImage, updateImage, deleteImage,
|
||||
getImageList, getImageCompareHost, getImageDetail, getImageHostStatus, createImage, updateImage, deleteImage,
|
||||
reloadImage, syncImageToHost, reloadImageOnHost, getRemoteHostList
|
||||
} from '@/api/admin/kvmService'
|
||||
import { extractApiError } from '@/utils/kvmErrorUtil'
|
||||
@@ -228,6 +238,7 @@ const router = useRouter()
|
||||
const embedded = inject('embedded', false)
|
||||
const injectedServiceId = inject('serviceId', null)
|
||||
const injectedServiceName = inject('serviceName', null)
|
||||
const injectedHostId = inject('hostId', null)
|
||||
const serviceId = computed(() => injectedServiceId?.value || parseInt(route.query.service_id) || 0)
|
||||
const serviceName = computed(() => injectedServiceName?.value || route.query.service_name || '')
|
||||
|
||||
@@ -275,6 +286,8 @@ const formRules = {
|
||||
|
||||
const statusType = (s) => ({ ready: 'success', success: 'success', downloading: 'warning', pending: 'info', error: 'danger', failed: 'danger', not_found: 'warning' }[s] || 'info')
|
||||
const statusLabel = (s) => ({ ready: '就绪', success: '已同步', downloading: '下载中', pending: '等待中', error: '错误', failed: '失败', not_found: '未同步' }[s] || s || '-')
|
||||
const syncStatusType = (s) => ({ synced: 'success', not_synced: 'warning', downloading: 'primary', error: 'danger', pending: 'info' }[s] || 'info')
|
||||
const syncStatusLabel = (s) => ({ synced: '已同步', not_synced: '未同步', downloading: '同步中', error: '同步错误', pending: '等待同步' }[s] || s || '-')
|
||||
const formatSize = (bytes) => {
|
||||
if (!bytes) return '0 B'
|
||||
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||
@@ -320,19 +333,33 @@ const loadList = async () => {
|
||||
if (!serviceId.value) return
|
||||
loading.value = true
|
||||
try {
|
||||
const params = { service_id: serviceId.value, page: queryParams.page, count: queryParams.count }
|
||||
if (keyword.value) params.keyword = keyword.value
|
||||
if (filterOsType.value) params.os_type = filterOsType.value
|
||||
if (filterType.value) params.type = filterType.value
|
||||
if (filterStatus.value) params.status = filterStatus.value
|
||||
if (filterHostId.value) params.host_id = filterHostId.value
|
||||
const res = await getImageList(params)
|
||||
let res
|
||||
if (injectedHostId?.value) {
|
||||
res = await getImageCompareHost({ service_id: serviceId.value, host_id: injectedHostId.value })
|
||||
} else {
|
||||
const params = { service_id: serviceId.value, page: queryParams.page, count: queryParams.count }
|
||||
if (keyword.value) params.keyword = keyword.value
|
||||
if (filterOsType.value) params.os_type = filterOsType.value
|
||||
if (filterType.value) params.type = filterType.value
|
||||
if (filterStatus.value) params.status = filterStatus.value
|
||||
if (filterHostId.value) params.host_id = filterHostId.value
|
||||
res = await getImageList(params)
|
||||
}
|
||||
const body = res?.data
|
||||
if (body?.code === 200 && body?.data) {
|
||||
const inner = body.data
|
||||
const items = Array.isArray(inner) ? inner : (inner.images || inner.data || inner.list || [])
|
||||
imageList.value = items
|
||||
total.value = inner.meta?.count ?? inner.all_count ?? inner.total ?? items.length
|
||||
if (injectedHostId?.value && Array.isArray(inner.data)) {
|
||||
imageList.value = inner.data.map(item => ({
|
||||
...(item.image || {}),
|
||||
sync_status: item.sync_status || '',
|
||||
host_status: item.host_status || ''
|
||||
}))
|
||||
total.value = inner.total ?? imageList.value.length
|
||||
} else {
|
||||
const items = Array.isArray(inner) ? inner : (inner.images || inner.data || inner.list || [])
|
||||
imageList.value = items
|
||||
total.value = inner.meta?.count ?? inner.all_count ?? inner.total ?? items.length
|
||||
}
|
||||
} else {
|
||||
imageList.value = []
|
||||
total.value = 0
|
||||
@@ -449,9 +476,10 @@ const handleViewDetail = async (row) => {
|
||||
}
|
||||
|
||||
// 同步镜像到宿主机
|
||||
const handleSyncToHost = (row) => {
|
||||
const handleSyncToHost = async (row) => {
|
||||
syncTarget.value = row
|
||||
syncHostId.value = ''
|
||||
if (!hostOptions.value.length) await loadHostOptions()
|
||||
syncDialogVisible.value = true
|
||||
}
|
||||
|
||||
@@ -493,9 +521,10 @@ const handleReloadMaster = (row) => {
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
const handleReloadOnHost = (row) => {
|
||||
const handleReloadOnHost = async (row) => {
|
||||
reloadTarget.value = row
|
||||
reloadHostId.value = ''
|
||||
if (!hostOptions.value.length) await loadHostOptions()
|
||||
reloadDialogVisible.value = true
|
||||
}
|
||||
|
||||
@@ -543,7 +572,7 @@ const goBack = () => { router.push('/virtualization/kvm-service') }
|
||||
onMounted(() => {
|
||||
if (serviceId.value) {
|
||||
loadList()
|
||||
loadHostOptions()
|
||||
if (!injectedHostId?.value) loadHostOptions()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user