feat:对接虚拟机实例接口
This commit is contained in:
@@ -225,18 +225,22 @@
|
||||
:type="scope.row.container_state == 0 || scope.row.container_state == 1
|
||||
? 'info'
|
||||
: scope.row.container_state == 2
|
||||
? 'success'
|
||||
: 'danger'"
|
||||
? 'danger'
|
||||
: scope.row.container_state == 3
|
||||
? 'danger'
|
||||
: 'success'"
|
||||
effect="light"
|
||||
>
|
||||
{{
|
||||
scope.row.container_state == 0
|
||||
? "未支付"
|
||||
? "未构建"
|
||||
: scope.row.container_state == 1
|
||||
? "未开通"
|
||||
? "已构建"
|
||||
: scope.row.container_state == 2
|
||||
? "开机"
|
||||
: "关机"
|
||||
? "构建失败"
|
||||
: scope.row.container_state == 3
|
||||
? "已删除"
|
||||
: "未知状态"
|
||||
}}
|
||||
</el-tag>
|
||||
</template>
|
||||
@@ -378,6 +382,7 @@
|
||||
v-model="spec_form.cpu"
|
||||
:placeholder="TypeData == 'dockerContainer' ? 'CPU 限制 (1核=1000毫核)' : 'CPU 限制'"
|
||||
type="number"
|
||||
min="1"
|
||||
>
|
||||
<template #append>{{ TypeData == 'dockerContainer' ? '毫核' : '核' }}</template>
|
||||
</el-input>
|
||||
@@ -432,28 +437,28 @@
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="允许开放端口数">
|
||||
<el-input v-model="spec_form.port_num" placeholder="默认允许开放端口数" type="number">
|
||||
<el-input v-model="spec_form.port_num" placeholder="默认允许开放端口数" type="number" :value="spec_form.port_num || 5">
|
||||
<template #append>个</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="允许快照数">
|
||||
<el-input v-model="spec_form.snapshot_num" placeholder="默认允许快照数" type="number">
|
||||
<el-input v-model="spec_form.snapshot_num" placeholder="默认允许快照数" type="number" :value="spec_form.snapshot_num || 3">
|
||||
<template #append>个</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="读写限制">
|
||||
<el-input v-model="spec_form.min_iops" placeholder="读写限制(1iops=8kb/s)" type="number">
|
||||
<el-input v-model="spec_form.min_iops" placeholder="读写限制(1iops=8kb/s)" type="number" :value="spec_form.min_iops || 1000">
|
||||
<template #append>IOPS</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="读写最大突发">
|
||||
<el-input v-model="spec_form.max_iops" placeholder="读写最大突发" type="number">
|
||||
<el-input v-model="spec_form.max_iops" placeholder="读写最大突发" type="number" :value="spec_form.max_iops || 5000">
|
||||
<template #append>IOPS</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
@@ -609,6 +614,8 @@ import {
|
||||
} from "@/utils/acs/server";
|
||||
import { ElMessage, ElNotification } from 'element-plus';
|
||||
import { copyDomText } from "@/utils/hide";
|
||||
import { getUserInfoV1 } from "@/utils/acs/user";
|
||||
import {getUserInfo, userLogin} from "@/api/login.js";
|
||||
import {
|
||||
Plus,
|
||||
Edit,
|
||||
@@ -660,11 +667,30 @@ const initData = async () => {
|
||||
// 获取实例规格
|
||||
await GetSpecs();
|
||||
|
||||
// 获取用户信息并设置用户类型
|
||||
try {
|
||||
const userInfoRes = await getUserInfo();
|
||||
console.log("获取用户信息", userInfoRes);
|
||||
if (userInfoRes && userInfoRes.data && userInfoRes.data.data) {
|
||||
// 根据API返回的用户信息设置用户类型
|
||||
const userType = userInfoRes.data.is_admin == true ? "1" : "0";
|
||||
localStorage.setItem("user_id", userInfoRes.real_name.UserId);
|
||||
localStorage.setItem("user_type", userType);
|
||||
console.log("获取到用户类型", userType);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取用户信息失败:", error);
|
||||
// 如果获取失败,默认设置为管理员权限确保功能可用
|
||||
localStorage.setItem("user_type", "1");
|
||||
}
|
||||
|
||||
// 获取所有容器
|
||||
let usertype = localStorage.getItem("user_type");
|
||||
console.log("用户类型", usertype);
|
||||
if (usertype == "1") {
|
||||
containerBox.server_id = route.query.server_id;
|
||||
let cons = await getContainer(containerBox);
|
||||
console.log("获取容器列表", cons);
|
||||
if (cons && cons.data) {
|
||||
user_servers.value = cons.data.data || [];
|
||||
total.value = cons.data.count || 0;
|
||||
@@ -900,10 +926,11 @@ const editSpec = async () => {
|
||||
if (addOrChange.value) {
|
||||
const res = await addServerPlan({
|
||||
...spec_form,
|
||||
server_id: route.query.server_id
|
||||
server_id: route.query.server_id,
|
||||
server_type:TypeData.value
|
||||
});
|
||||
|
||||
if (res.data.code == 200) {
|
||||
if (res.code == 200) {
|
||||
ElNotification({
|
||||
title: '添加成功',
|
||||
message: `已成功添加规格 "${spec_form.name}"`,
|
||||
@@ -916,7 +943,32 @@ const editSpec = async () => {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
const res = await editServerPlan(spec_form);
|
||||
const submitData = {
|
||||
...spec_form,
|
||||
server_id:route.query.server_id,
|
||||
server_type:TypeData.value
|
||||
}
|
||||
|
||||
// 处理虚拟机特有字段
|
||||
if (TypeData.value === 'hyperV') {
|
||||
// 确保数值类型字段有默认值
|
||||
submitData.port_num = submitData.port_num || 5;
|
||||
submitData.snapshot_num = submitData.snapshot_num || 3;
|
||||
submitData.min_iops = submitData.min_iops || 1000;
|
||||
submitData.max_iops = submitData.max_iops || 5000;
|
||||
|
||||
// 容器特有字段设为空
|
||||
submitData.bandwidth_rx = '0';
|
||||
submitData.bandwidth_tx = '0';
|
||||
submitData.threshold_rx = '0';
|
||||
submitData.threshold_tx = '0';
|
||||
} else {
|
||||
// 处理容器特有字段
|
||||
submitData.bandwidth_rx = submitData.bandwidth_rx || '100';
|
||||
submitData.bandwidth_tx = submitData.bandwidth_tx || '100';
|
||||
}
|
||||
|
||||
const res = await editServerPlan(submitData);
|
||||
|
||||
if (res.data.code == 200) {
|
||||
ElNotification({
|
||||
@@ -1018,7 +1070,7 @@ const spec_form = reactive({
|
||||
bandwidth_tx: "",
|
||||
threshold_rx: "",
|
||||
threshold_tx: "",
|
||||
port_num: "",
|
||||
port_num: 0,
|
||||
snapshot_num: "",
|
||||
number: "",
|
||||
volume_price: "",
|
||||
@@ -1030,22 +1082,33 @@ const spec_form = reactive({
|
||||
|
||||
function show_spec(data = null) {
|
||||
if (!data) {
|
||||
// 当data未传值,视为新增实例规格
|
||||
// 遍历form对象的每个键值对
|
||||
// 重置表单时根据服务器类型设置不同默认值
|
||||
Object.keys(spec_form).forEach(key => {
|
||||
spec_form[key] = key === 'must_real_name' ? 0 : '';
|
||||
});
|
||||
|
||||
// 设置默认类型
|
||||
|
||||
// 设置服务器类型和类型相关默认值
|
||||
spec_form.server_type = TypeData.value;
|
||||
|
||||
if (TypeData.value === 'dockerContainer') {
|
||||
spec_form.bandwidth_rx = '100';
|
||||
spec_form.bandwidth_tx = '100';
|
||||
} else {
|
||||
// 虚拟机默认值
|
||||
spec_form.port_num = '5';
|
||||
spec_form.snapshot_num = '3';
|
||||
spec_form.min_iops = '1000';
|
||||
spec_form.max_iops = '5000';
|
||||
}
|
||||
} else {
|
||||
// data传值,视为修改实例规格
|
||||
// 遍历data对象的每个键值对
|
||||
// 复制传入的数据
|
||||
Object.keys(data).forEach(key => {
|
||||
if (key in spec_form) {
|
||||
spec_form[key] = data[key];
|
||||
}
|
||||
});
|
||||
// 确保服务器类型正确
|
||||
spec_form.server_type = TypeData.value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user