fix: 重构虚拟机内网外网参数设置选择网络
This commit is contained in:
@@ -174,9 +174,18 @@
|
||||
<el-radio value="ids">选择网络IP</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="IP数量" v-if="ipMode === 'num'">
|
||||
<el-input-number v-model="createForm.ip_num" :min="1" controls-position="right" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-row :gutter="16" v-if="ipMode === 'num'">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="IPv4数量">
|
||||
<el-input-number v-model="createForm.ipv4_num" :min="0" controls-position="right" style="width: 100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="IPv6数量">
|
||||
<el-input-number v-model="createForm.ipv6_num" :min="0" controls-position="right" style="width: 100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-form-item label="网络IP列表" v-if="ipMode === 'ids'">
|
||||
<el-select v-model="createForm.network_ids" multiple filterable placeholder="选择可用网络IP" style="width: 100%">
|
||||
<el-option v-for="n in networkOptions" :key="n.id" :label="`${n.name || ''} - ${n.address || n.ip || ''}`" :value="n.id" />
|
||||
@@ -447,7 +456,7 @@ const vmMetricsData = ref(null)
|
||||
const createForm = reactive({
|
||||
name: '', host_id: null, image_id: 0, vcpu: 0, memory: 0,
|
||||
system_size: 0, rx_bandwidth: 0, tx_bandwidth: 0,
|
||||
host_group_id: null, user_id: 0, ip_num: 0, network_ids: [],
|
||||
host_group_id: null, user_id: 0, ipv4_num: 0, ipv6_num: 0, network_ids: [],
|
||||
_imageName: '', _groupName: '', _userName: ''
|
||||
})
|
||||
|
||||
@@ -513,6 +522,7 @@ const loadList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const params = { service_id: serviceId.value, page: queryParams.page, page_size: queryParams.page_size }
|
||||
if (hostId.value) params.host_id = hostId.value
|
||||
if (keyword.value) params.key = keyword.value
|
||||
if (filterStatus.value) params.status = filterStatus.value
|
||||
const res = await getVmList(params)
|
||||
@@ -531,7 +541,7 @@ const handleAdd = () => {
|
||||
Object.assign(createForm, {
|
||||
name: '', host_id: injectedHostId?.value || null, image_id: 0,
|
||||
vcpu: 0, memory: 0, system_size: 0,
|
||||
rx_bandwidth: 0, tx_bandwidth: 0, host_group_id: null, user_id: 0, ip_num: 0, network_ids: [],
|
||||
rx_bandwidth: 0, tx_bandwidth: 0, host_group_id: null, user_id: 0, ipv4_num: 0, ipv6_num: 0, network_ids: [],
|
||||
_imageName: '', _groupName: '', _userName: ''
|
||||
})
|
||||
memoryUnit.value = 'GB'
|
||||
@@ -549,7 +559,7 @@ const submitCreate = () => {
|
||||
if (hostMode.value === 'host' && !createForm.host_id) { ElMessage.warning('请选择宿主机'); return }
|
||||
if (hostMode.value === 'group' && !createForm.host_group_id) { ElMessage.warning('请选择宿主机组'); return }
|
||||
if (ipMode.value === 'ids' && !createForm.network_ids.length) { ElMessage.warning('请选择网络IP'); return }
|
||||
if (ipMode.value === 'num' && !createForm.ip_num) { ElMessage.warning('请输入IP数量'); return }
|
||||
if (ipMode.value === 'num' && !createForm.ipv4_num && !createForm.ipv6_num) { ElMessage.warning('请输入IPv4或IPv6数量'); return }
|
||||
|
||||
createFormRef.value?.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
@@ -567,8 +577,10 @@ const submitCreate = () => {
|
||||
if (createForm.tx_bandwidth) fd.append('tx_bandwidth', createForm.tx_bandwidth)
|
||||
if (hostMode.value === 'host') fd.append('host_id', createForm.host_id)
|
||||
else fd.append('host_group_id', createForm.host_group_id)
|
||||
if (ipMode.value === 'num') fd.append('ip_num', createForm.ip_num)
|
||||
else createForm.network_ids.forEach(id => fd.append('network_ids', id))
|
||||
if (ipMode.value === 'num') {
|
||||
if (createForm.ipv4_num) fd.append('ipv4_num', createForm.ipv4_num)
|
||||
if (createForm.ipv6_num) fd.append('ipv6_num', createForm.ipv6_num)
|
||||
} else createForm.network_ids.forEach(id => fd.append('network_ids', id))
|
||||
const res = await createVm(fd)
|
||||
if (res?.data?.code === 200) { ElMessage.success('创建成功'); createDialogVisible.value = false; loadList() }
|
||||
else ElMessage.error(extractApiError(res?.data, '创建失败'))
|
||||
|
||||
Reference in New Issue
Block a user