fix: 修改内存的基础单位为kb
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
<el-table-column prop="description" label="描述" min-width="160" show-overflow-tooltip />
|
||||
<el-table-column label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 'completed' ? 'success' : row.status === 'failed' ? 'danger' : 'warning'" size="small">
|
||||
<el-tag :type="taskStatusType(row.status)" size="small">
|
||||
{{ statusLabel(row.status) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
@@ -22,12 +22,18 @@
|
||||
<el-table-column label="操作" width="180" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" size="small" @click="handleRestore(row)">恢复</el-button>
|
||||
<el-button link type="info" size="small" @click="handleProgress(row)">进度</el-button>
|
||||
<el-button link type="info" size="small" @click="handleProgress(row)" v-if="row.status === 'running' || row.status === 'pending'">进度</el-button>
|
||||
<el-button link type="danger" size="small" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-empty v-if="!list.length && !loading" description="暂无快照数据" />
|
||||
<div class="pagination-wrapper" v-if="total > pageSize">
|
||||
<el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize"
|
||||
:page-sizes="[10, 20, 50]" :total="total" layout="total, sizes, prev, pager, next"
|
||||
@size-change="s => { pageSize = s; currentPage = 1; loadList() }"
|
||||
@current-change="p => { currentPage = p; loadList() }" />
|
||||
</div>
|
||||
|
||||
<el-dialog v-model="createVisible" title="创建快照" width="480px" destroy-on-close>
|
||||
<el-form :model="createForm" label-width="100px">
|
||||
@@ -49,15 +55,26 @@
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog v-model="progressVisible" title="快照任务进度" width="420px" destroy-on-close>
|
||||
<el-dialog v-model="progressVisible" title="快照任务进度" width="520px" destroy-on-close>
|
||||
<div v-loading="progressLoading">
|
||||
<el-descriptions :column="1" border size="small" v-if="progressData">
|
||||
<el-descriptions-item v-for="(val, key) in progressData" :key="key" :label="key">{{ val }}</el-descriptions-item>
|
||||
<el-descriptions-item label="任务ID">
|
||||
<span style="font-family: Consolas, monospace; font-size: 13px">{{ progressData.task_id || '-' }}</span>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="状态">
|
||||
<el-tag :type="taskStatusType(progressData.status)" size="small">{{ taskStatusLabel(progressData.status) }}</el-tag>
|
||||
</el-descriptions-item>
|
||||
<template v-if="parsedMeta">
|
||||
<el-descriptions-item v-for="(val, key) in parsedMeta" :key="key" :label="metaLabelMap[key] || key">
|
||||
<span :style="key.includes('path') ? 'font-family: Consolas, monospace; font-size: 13px; word-break: break-all' : ''">{{ val }}</span>
|
||||
</el-descriptions-item>
|
||||
</template>
|
||||
</el-descriptions>
|
||||
<el-empty v-else description="暂无进度信息" />
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="progressVisible = false">关闭</el-button>
|
||||
<el-button type="primary" @click="handleProgress(progressRow)" :loading="progressLoading" v-if="progressData?.status === 'running' || progressData?.status === 'pending'">刷新进度</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
@@ -74,8 +91,11 @@ const serviceId = inject('serviceId')
|
||||
const loading = ref(false)
|
||||
const submitLoading = ref(false)
|
||||
const list = ref([])
|
||||
const total = ref(0)
|
||||
const currentPage = ref(1)
|
||||
const pageSize = ref(10)
|
||||
|
||||
const statusLabel = (s) => ({ completed: '完成', pending: '等待', running: '运行中', failed: '失败' }[s] || s || '-')
|
||||
const statusLabel = (s) => ({ completed: '完成', ready: '完成', success: '成功', pending: '等待', running: '运行中', failed: '失败', error: '错误' }[s] || s || '-')
|
||||
const formatTs = (ts) => {
|
||||
if (!ts) return '-'
|
||||
if (typeof ts === 'object' && ts.seconds) return new Date(Number(ts.seconds) * 1000).toLocaleString('zh-CN')
|
||||
@@ -85,12 +105,13 @@ const formatTs = (ts) => {
|
||||
const loadList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await getSnapshotList({ service_id: serviceId.value })
|
||||
const res = await getSnapshotList({ service_id: serviceId.value, page: currentPage.value, page_size: pageSize.value })
|
||||
if (res?.data?.code === 200 && res?.data?.data) {
|
||||
const d = res.data.data
|
||||
list.value = d.snapshots || d.data || d.list || (Array.isArray(d) ? d : [])
|
||||
} else list.value = []
|
||||
} catch { list.value = [] } finally { loading.value = false }
|
||||
total.value = d.meta?.count ?? d.all_count ?? d.total ?? list.value.length
|
||||
} else { list.value = []; total.value = 0 }
|
||||
} catch { list.value = []; total.value = 0 } finally { loading.value = false }
|
||||
}
|
||||
|
||||
const vmOptions = ref([])
|
||||
@@ -166,15 +187,35 @@ const handleDelete = (row) => {
|
||||
const progressVisible = ref(false)
|
||||
const progressLoading = ref(false)
|
||||
const progressData = ref(null)
|
||||
const progressRow = ref(null)
|
||||
|
||||
const taskStatusType = (s) => ({ running: 'primary', completed: 'success', ready: 'success', success: 'success', failed: 'danger', error: 'danger', pending: 'info', cancelled: 'warning' }[s] || 'info')
|
||||
const taskStatusLabel = (s) => ({ running: '运行中', completed: '已完成', ready: '已完成', success: '成功', failed: '失败', error: '错误', pending: '等待中', cancelled: '已取消' }[s] || s || '-')
|
||||
const metaLabelMap = { vm_name: '虚拟机名称', backup_path: '备份路径', snapshot_path: '快照路径', path: '路径', progress: '进度', message: '信息', error: '错误信息' }
|
||||
|
||||
const parsedMeta = computed(() => {
|
||||
if (!progressData.value?.meta) return null
|
||||
const raw = progressData.value.meta
|
||||
if (typeof raw === 'object') return raw
|
||||
if (typeof raw === 'string') {
|
||||
const trimmed = raw.trim()
|
||||
if (!trimmed || trimmed === '""' || trimmed === '{}') return null
|
||||
try { return JSON.parse(trimmed) } catch { return { 信息: raw } }
|
||||
}
|
||||
return null
|
||||
})
|
||||
|
||||
const handleProgress = async (row) => {
|
||||
progressRow.value = row
|
||||
progressData.value = null
|
||||
progressVisible.value = true
|
||||
progressLoading.value = true
|
||||
try {
|
||||
const res = await getSnapshotProgress({ service_id: serviceId.value, task_id: String(row.task_id || row.id) })
|
||||
if (res?.data?.code === 200) progressData.value = res.data.data
|
||||
else ElMessage.warning('暂无进度信息')
|
||||
if (res?.data?.code === 200) {
|
||||
const d = res.data.data
|
||||
progressData.value = d?.data ?? d
|
||||
} else ElMessage.warning('暂无进度信息')
|
||||
} catch { ElMessage.warning('获取进度失败') } finally { progressLoading.value = false }
|
||||
}
|
||||
|
||||
@@ -184,4 +225,5 @@ onMounted(() => { loadList() })
|
||||
<style scoped>
|
||||
.snapshot-manage { padding: 0; }
|
||||
.toolbar { display: flex; gap: 8px; margin-bottom: 16px; }
|
||||
.pagination-wrapper { display: flex; justify-content: flex-end; margin-top: 16px; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user