fix: 修改内存的基础单位为kb
Build and Deploy Vue3 / build (push) Successful in 2m38s
Build and Deploy Vue3 / deploy (push) Successful in 1m3s

This commit is contained in:
2026-03-21 15:25:38 +08:00
parent cf19956b88
commit 9edb59d16e
14 changed files with 819 additions and 155 deletions
+17 -28
View File
@@ -5,7 +5,7 @@
<el-button @click="goBack" :icon="ArrowLeft">返回</el-button>
<div class="header-info">
<h3>数据卷管理</h3>
<span class="sub-info" v-if="serviceName">主控服务{{ serviceName }} | 宿主机{{ selectedHostName || '请选择' }}</span>
<span class="sub-info" v-if="serviceName">主控服务{{ serviceName }}</span>
</div>
</div>
<div class="header-right">
@@ -25,9 +25,6 @@
<el-option label="错误" value="error" />
<el-option label="未知" value="unknown" />
</el-select>
<el-select v-model="hostIdInput" placeholder="选择宿主机" clearable filterable style="width: 220px" @change="handleSearch">
<el-option v-for="h in hostOptions" :key="h.id" :label="`${h.name} (${h.ip || h.id})`" :value="h.id" />
</el-select>
</div>
<el-table :data="volumeList" v-loading="loading" stripe>
@@ -143,7 +140,7 @@
<el-form-item label="当前宿主机">{{ getHostLabel(transferTarget?.host_id) }}</el-form-item>
<el-form-item label="目标宿主机" required>
<el-select v-model="transferHostId" placeholder="请选择目标宿主机" style="width: 100%" filterable>
<el-option v-for="h in hostOptions.filter(x => x.id !== transferTarget?.host_id)" :key="h.id" :label="`${h.name} (${h.ip || h.id})`" :value="h.id" />
<el-option v-for="h in hostOptions" :key="h.id" :label="`${h.name} (${h.ip || h.id})`" :value="h.id" :disabled="h.id === transferTarget?.host_id" />
</el-select>
</el-form-item>
</el-form>
@@ -185,7 +182,7 @@
<!-- 虚拟机选择器 (创建) -->
<VmSelectorPopup v-model="showVmSelector" :service-id="serviceId" :host-id="createForm.host_id" :current-id="createForm.vm_id" @confirm="handleVmSelected" />
<!-- 虚拟机选择器 (挂载) -->
<VmSelectorPopup v-model="showMountVmSelector" :service-id="serviceId" :host-id="mountTarget?.host_id || hostIdInput" :current-id="mountVmId" @confirm="handleMountVmSelected" />
<VmSelectorPopup v-model="showMountVmSelector" :service-id="serviceId" :host-id="mountTarget?.host_id || 0" :current-id="mountVmId" @confirm="handleMountVmSelected" />
</div>
</template>
@@ -207,8 +204,9 @@ 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 hostId = computed(() => parseInt(route.query.host_id) || 0)
const hostId = computed(() => injectedHostId?.value || parseInt(route.query.host_id) || 0)
const serviceName = computed(() => injectedServiceName?.value || route.query.service_name || '')
const loading = ref(false)
@@ -217,15 +215,9 @@ const detailLoading = ref(false)
const volumeList = ref([])
const total = ref(0)
const filterStatus = ref('')
const hostIdInput = ref(0)
const hostOptions = ref([])
const queryParams = reactive({ page: 1, count: 10 })
const selectedHostName = computed(() => {
const h = hostOptions.value.find(x => x.id === hostIdInput.value)
return h ? `${h.name} (${h.ip || h.id})` : (hostIdInput.value || '')
})
const getHostLabel = (hid) => {
const h = hostOptions.value.find(x => x.id === hid)
return h ? `${h.name}` : (hid || '-')
@@ -245,11 +237,13 @@ const formatTimestamp = (ts) => {
const loadHostOptions = async () => {
try {
const res = await getRemoteHostList({ service_id: serviceId.value, page: 1, page_size: 100 })
const res = await getRemoteHostList({ service_id: serviceId.value, page: 1, page_size: 200 })
const body = res?.data
if (body?.code === 200 && body?.data) {
const inner = body.data
hostOptions.value = inner.hosts || inner.data || (Array.isArray(inner) ? inner : [])
const items = Array.isArray(inner) ? inner : (inner.hosts || inner.list || inner.data || [])
hostOptions.value = items
if (!items.length) console.warn('[VolumeManage] host list empty, raw:', JSON.stringify(inner).slice(0, 500))
}
} catch (e) { console.error('加载宿主机列表失败:', e) }
}
@@ -298,11 +292,10 @@ const handleMountVmSelected = (vm) => { mountVmId.value = vm.id; mountVmName.val
const loadList = async () => {
if (!serviceId.value) return
const hid = hostIdInput.value || hostId.value
if (!hid) { ElMessage.warning('请先选择宿主机'); return }
loading.value = true
try {
const params = { service_id: serviceId.value, host_id: hid, page: queryParams.page, count: queryParams.count }
const params = { service_id: serviceId.value, page: queryParams.page, count: queryParams.count }
if (hostId.value) params.host_id = hostId.value
if (filterStatus.value) params.status = filterStatus.value
const res = await getVolumeList(params)
const body = res?.data
@@ -318,7 +311,7 @@ const handleSearch = () => { queryParams.page = 1; loadList() }
const handleAdd = () => {
Object.assign(createForm, {
name: '', size: 10, host_id: hostIdInput.value || hostId.value || 0,
name: '', size: 10, host_id: hostId.value || 0,
is_system: false, image_id: 0, vm_id: 0, target_device: '',
_imageName: '', _vmName: ''
})
@@ -384,9 +377,10 @@ const handleUnmount = (row) => {
}
// 迁移卷
const handleTransfer = (row) => {
const handleTransfer = async (row) => {
transferTarget.value = row
transferHostId.value = ''
if (!hostOptions.value.length) await loadHostOptions()
transferDialogVisible.value = true
}
@@ -438,15 +432,10 @@ const handleDelete = (row) => {
const goBack = () => { router.push('/virtualization/kvm-service') }
onMounted(async () => {
onMounted(() => {
if (serviceId.value) {
await loadHostOptions()
if (hostId.value) {
hostIdInput.value = hostId.value
} else if (hostOptions.value.length > 0) {
hostIdInput.value = hostOptions.value[0].id
}
if (hostIdInput.value) loadList()
loadHostOptions()
loadList()
}
})
</script>