This commit is contained in:
qiuyuan 2026-01-19 15:30:18 +08:00
commit f5d15cc374
6 changed files with 636 additions and 34 deletions

View File

@ -3,7 +3,7 @@ export default () => ({
port: 8080,
proxy: {
'/api': {
target: 'http://10.10.1.31:8040/api',
target: 'http://10.10.1.36:8040/api',
// target: 'http://127.0.0.1:8045/api',
changeOrigin: true,
rewrite: (path) => path.replace('/api', ''),

22
src/apis/modules/host.js Normal file
View File

@ -0,0 +1,22 @@
/**
* 权限接口
*/
import request from '@/utils/request'
// 获取role列表
export const getPageList = (params) => request.basic.get('/api/v1/power-hosts', params)
// 获取role条数据
export const getPage = (id) => request.basic.get(`/api/v1/power-hosts/${id}`)
// 添加role
export const createPage = (params) => request.basic.post('/api/v1/power-hosts', params)
// 更新role
export const updatePage = (id, params) => request.basic.put(`/api/v1/power-hosts/${id}`, params)
// 删除role
export const delPage = (id) => request.basic.delete(`/api/v1/power-hosts/${id}`)
//获取区域列表
export const getRegionList = (params) => request.basic.get('/api/v1/computing-power-centers/label', params)
//添加算力卡
export const createComputeCard = (params) => request.basic.post('/api/v1/computing-cards', params)
//获取算力卡列表
export const getComputeCardList = (params) => request.basic.get('/api/v1/computing-cards', params)
//删除算力卡
export const delComputeCard = (id) => request.basic.delete(`/api/v1/computing-cards/${id}`)

View File

@ -171,13 +171,30 @@ defineOptions({
})
const columns = [
{ title: '区域ID', dataIndex: 'hostId' },
{ title: '区域名称', dataIndex: 'hostName' },
{ title: '区域编码', dataIndex: 'regionId' },
{ title: '数据中心地址', dataIndex: 'cpu' },
{ title: '状态', dataIndex: 'memory' },
{ title: '部署主机数量(主机数量)', dataIndex: 'storage' },
{ title: '可用计算卡总数', dataIndex: 'ip' },
{ title: '订单ID', dataIndex: 'hostId' },
{ title: '订单编号', dataIndex: 'hostName' },
{ title: '所属用户ID', dataIndex: 'regionId' },
{ title: '用户名', dataIndex: 'cpu' },
{ title: '手机号', dataIndex: 'memory' },
{ title: '实例ID', dataIndex: 'ip' },
{ title: '实例名称', dataIndex: 'hostId' },
{ title: '租赁配置', dataIndex: 'hostName' },
{ title: '计费方式', dataIndex: 'regionId' },
{ title: '订单金额', dataIndex: 'cpu' },
{ title: '实付金额', dataIndex: 'hostId' },
{ title: '创建时间', dataIndex: 'hostName' },
{ title: '支付时间', dataIndex: 'regionId' },
{ title: '订单状态', dataIndex: 'cpu' },
{ title: '到期时间', dataIndex: 'hostName' },
{ title: '续费状态', dataIndex: 'regionId' },
{ title: '支付方式', dataIndex: 'cpu' },
{ title: '支付订单ID', dataIndex: 'hostId' },
{ title: '发票状态', dataIndex: 'hostName' },
{ title: '合同ID', dataIndex: 'regionId' },
{ title: '是否开票', dataIndex: 'cpu' },
{ title: '备注', dataIndex: 'hostId' },
{ title: '当前运行状态', dataIndex: 'cpu' },
{ title: '剩余时长', dataIndex: 'hostId' },
{ title: '操作', key: 'action', width: 160 },
]
// const { listData, paginationState, loading, showLoading, hideLoading, resetPagination, searchFormData } =

View File

@ -1,23 +1,186 @@
<template>
<a-modal
:open="modal.open"
:title="modal.title"
:confirm-loading="modal.confirmLoading"
:after-close="onAfterClose"
@ok="handleOk"
@cancel="handleCancel">
<a-form
ref="formRef"
scroll-to-first-error
:model="formData"
:rules="formRules"
:label-col="{ style: { width: '80px' } }">
<a-form-item
label="标题"
name="title">
<a-input v-model:value="formData.title"></a-input>
</a-form-item>
</a-form>
<a-modal :open="modal.open" :title="modal.title" :confirm-loading="modal.confirmLoading" :after-close="onAfterClose"
@ok="handleOk" @cancel="handleCancel" width="800px">
<a-card>
<a-form ref="formRef" scroll-to-first-error :model="formData" :rules="formRules">
<a-divider>基础信息</a-divider>
<a-row :gutter="16">
<a-col :span="8">
<a-form-item label="主机名称" name="name">
<a-input v-model:value="formData.name" placeholder="请输入主机名称" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="区域" name="centerID">
<a-select v-model:value="formData.centerID" placeholder="请选择区域">
<a-select-option v-for="item in areaList" :value="item.id">{{ item.name }}</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="部署位置" name="deploymentLocation">
<a-input v-model:value="formData.deploymentLocation" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="描述" name="description">
<a-textarea v-model:value="formData.description" rows="1" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="状态" name="status">
<a-select v-model:value="formData.status" placeholder="请选择状态">
<a-select-option value="active">启用</a-select-option>
<a-select-option value="inactive">停用</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="内网IP" name="intranetIP">
<a-input v-model:value="formData.intranetIP" placeholder="192.168.x.x" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="公网IP" name="networkIP">
<a-input v-model:value="formData.networkIP" placeholder="x.x.x.x" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="开始时间" name="startAt">
<a-date-picker v-model:value="formData.startAt" format="YYYY-MM-DD HH:mm" show-time />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="结束时间" name="endAt">
<a-date-picker v-model:value="formData.endAt" format="YYYY-MM-DD HH:mm" show-time />
</a-form-item>
</a-col>
</a-row>
<!-- 硬件配置 -->
<a-divider>硬件配置</a-divider>
<a-row :gutter="16">
<a-col :span="8">
<a-form-item label="CPU数量" name="cpuNum">
<a-input-number v-model:value="formData.cpuNum" style="width: 100%" :min="0" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="CPU类型" name="cpuType">
<a-input v-model:value="formData.cpuType" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="内存 (GB)" name="memory">
<a-input-number v-model:value="formData.memory" style="width: 100%" :min="0" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="内存型号" name="memoryType">
<a-input v-model:value="formData.memoryType" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="系统盘 (GB)" name="systemDisk">
<a-input-number v-model:value="formData.systemDisk" style="width: 100%" :min="0" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="系统盘类型" name="systemDiskType">
<a-input v-model:value="formData.systemDiskType" placeholder="如 SSD, HDD" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="数据盘 (GB)" name="dataDisk">
<a-input-number v-model:value="formData.dataDisk" style="width: 100%" :min="0" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="数据盘类型" name="dataDiskType">
<a-input v-model:value="formData.dataDiskType" />
</a-form-item>
</a-col>
</a-row>
<a-form-item label="数据盘是否可挂载" name="dataDiskCanMount">
<a-switch v-model:checked="formData.dataDiskCanMount" />
</a-form-item>
<!-- GPU & 驱动 -->
<a-divider>GPU 与驱动</a-divider>
<a-row :gutter="16">
<a-col :span="12">
<a-form-item label="GPU 驱动版本" name="gpuDriver">
<a-input v-model:value="formData.gpuDriver" placeholder="如 535.129.03" />
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item label="CUDA 版本" name="cudaVersion">
<a-input v-model:value="formData.cudaVersion" placeholder="如 12.2" />
</a-form-item>
</a-col>
</a-row>
<!-- 带宽 -->
<a-divider>网络带宽</a-divider>
<a-row :gutter="16">
<a-col :span="12">
<a-form-item label="上行带宽" name="bandWidthUp">
<a-input-number v-model:value="formData.bandWidthUp" style="width: 100%" :min="0">
<template #addonAfter>
<a-select v-model:value="formData.bandWidthUnitUp"
default-value="Mbps" style="width: 80px;">
<a-select-option value="Mbps">Mbps</a-select-option>
<a-select-option value="Gbps">Gbps</a-select-option>
</a-select>
</template>
</a-input-number>
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item label="下行带宽" name="bandWidthDown">
<a-input-number v-model:value="formData.bandWidthDown" style="width: 100%" :min="0">
<template #addonAfter>
<a-select v-model:value="formData.bandWidthUnitDown" default-value="Mbps" style="width: 80px;">
<a-select-option value="Mbps">Mbps</a-select-option>
<a-select-option value="Gbps">Gbps</a-select-option>
</a-select>
</template>
</a-input-number>
</a-form-item>
</a-col>
</a-row>
<!-- 价格 -->
<a-divider>计费信息</a-divider>
<a-row :gutter="16">
<a-col :span="12">
<a-form-item label="日付价格 (元)" name="dailyPrice">
<a-input-number v-model:value="formData.dailyPrice" style="width: 100%" :min="0"
:step="0.01" />
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item label="周付价格 (元)" name="weekPrice">
<a-input-number v-model:value="formData.weekPrice" style="width: 100%" :min="0"
:step="0.01" />
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item label="月付价格 (元)" name="monthlyPrice">
<a-input-number v-model:value="formData.monthlyPrice" style="width: 100%" :min="0"
:step="0.01" />
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item label="按时计费 (元/小时)" name="payOnTime">
<a-input-number v-model:value="formData.payOnTime" style="width: 100%" :min="0"
:step="0.01" />
</a-form-item>
</a-col>
</a-row>
</a-form>
</a-card>
</a-modal>
</template>
@ -25,20 +188,22 @@
import { cloneDeep } from 'lodash-es'
import apis from '@/apis'
import { useForm, useModal } from '@/hooks'
import { ref } from 'vue'
import dayjs from 'dayjs'
const emit = defineEmits(['ok'])
const areaList=ref([])
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
const { formRef, formRules, formRecord, formData, resetForm } = useForm()
formData.value.computingCards = []
formRules.value = {
title: { required: true, message: '请输入标题' },
name: { required: true, message: '请输入标题' },
}
/**
* 新建
*/
function handleCreate() {
getAreatList()
showModal({
type: 'create',
title: '新建',
@ -53,10 +218,16 @@ function handleEdit(record = {}) {
type: 'edit',
title: '编辑',
})
getAreatList()
formRecord.value = record
formData.value = cloneDeep(record)
}
function getAreatList() {
apis.host.getRegionList().then((res) => {
areaList.value=res.data
})
}
/**
* 确定
*/
@ -72,18 +243,18 @@ function handleOk() {
let result = null
switch (modal.value.type) {
case 'create':
result = await apis.common.create(params).catch(() => {
result = await apis.host.createPage(params).catch(() => {
throw new Error()
})
break
case 'edit':
result = await apis.common.update(formRecord.value.id, params).catch(() => {
result = await apis.host.updatePage(formRecord.value.id, params).catch(() => {
throw new Error()
})
break
}
hideLoading()
if (200 === result?.code) {
if (true === result?.success) {
hideModal()
emit('ok')
}

View File

@ -0,0 +1,158 @@
<template>
<a-modal :open="modal.open" :title="modal.title" :confirm-loading="modal.confirmLoading" :after-close="onAfterClose"
@ok="handleOk" @cancel="handleCancel" width="800px">
<a-card>
<a-form ref="formRef" scroll-to-first-error :model="formData" :rules="formRules">
<a-row :gutter="24">
<!-- <a-col :span="12">
<a-form-item label="地区ID" name="centerID">
<a-input v-model:value="formData.centerID" placeholder="请输入地区ID" />
</a-form-item>
</a-col> -->
<a-col :span="12">
<a-form-item label="核心数" name="coreNum">
<a-input-number v-model:value="formData.coreNum" placeholder="请输入核心数"
style="width: 100%" />
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item label="GPU数量" name="gpuNum">
<a-input-number v-model:value="formData.gpuNum" placeholder="请输入GPU数量"
style="width: 100%" />
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item label="GPU类型" name="gpuType">
<a-input v-model:value="formData.gpuType" placeholder="例如A100, V100" />
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item label="显存 (GB)" name="vram">
<a-input-number v-model:value="formData.vram" placeholder="显存大小" style="width: 100%" />
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item label="状态" name="status">
<a-select v-model:value="formData.status" placeholder="请选择状态" style="width: 100%">
<a-select-option value="enabled">启用</a-select-option>
<a-select-option value="disabled">停用</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="描述" name="description">
<a-textarea v-model:value="formData.description" placeholder="请输入描述" :rows="3" />
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="是否使用" name="isUse">
<a-switch v-model:checked="formData.isUse" />
</a-form-item>
</a-col>
</a-row>
</a-form>
</a-card>
</a-modal>
</template>
<script setup>
import { cloneDeep } from 'lodash-es'
import apis from '@/apis'
import { useForm, useModal } from '@/hooks'
import { ref } from 'vue'
import dayjs from 'dayjs'
const emit = defineEmits(['ok'])
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
const { formRef, formRules, formRecord, formData, resetForm } = useForm()
formData.value.computingCards = []
formRules.value = {
// name: { required: true, message: '' },
}
/**
* 新建
*/
function handleCreate(record = {}) {
showModal({
type: 'create',
title: '新建',
})
console.log(record);
formData.value.centerID=record.id
formData.value.hostID=record.hostID
formData.value.status='enabled'
}
/**
* 编辑
*/
function handleEdit(record = {}) {
showModal({
type: 'edit',
title: '编辑',
})
formRecord.value = record
formData.value = cloneDeep(record)
}
/**
* 确定
*/
function handleOk() {
formRef.value
.validateFields()
.then(async (values) => {
try {
showLoading()
const params = {
...formData.value,
}
let result = null
switch (modal.value.type) {
case 'create':
result = await apis.host.createComputeCard(params).catch(() => {
throw new Error()
})
break
case 'edit':
result = await apis.host.updatePage(formRecord.value.id, params).catch(() => {
throw new Error()
})
break
}
hideLoading()
if (true === result?.success) {
hideModal()
emit('ok')
}
} catch (error) {
hideLoading()
}
})
.catch(() => {
hideLoading()
})
}
/**
* 取消
*/
function handleCancel() {
hideModal()
}
/**
* 关闭后
*/
function onAfterClose() {
resetForm()
}
defineExpose({
handleCreate,
handleEdit,
})
</script>
<style lang="less" scoped></style>

View File

@ -0,0 +1,234 @@
<template>
<a-modal :open="modal.open" :title="modal.title" :confirm-loading="modal.confirmLoading" :after-close="onAfterClose"
@ok="handleOk" @cancel="handleCancel" width="800px">
<a-card>
<div style="width: 100%;text-align: right;">
<a-button type="primary" style="margin-bottom: 10px;"
@click="$refs.computeDialogRef.handleCreate(record)">添加</a-button>
</div>
<a-table :columns="columns" :data-source="listData" :loading="loading" bordered
:pagination="paginationState" :scroll="{ x: 1000 }" row-key="id" @change="onTableChange">
<template #bodyCell="{ column, record }">
<template v-if="'action' === column.key">
<x-action-button @click="$refs.computeDialogRef.handleEdit(record)">编辑</x-action-button>
<x-action-button @click="handleDelete(record)"><span
style="color: red;">删除</span></x-action-button>
</template>
</template>
</a-table>
</a-card>
<compute-dialog ref="computeDialogRef" @ok="onComputeOk" />
</a-modal>
</template>
<script setup>
import { cloneDeep } from 'lodash-es'
import apis from '@/apis'
import { useForm, useModal } from '@/hooks'
import { ref } from 'vue'
import ComputeDialog from './ComputeDialog.vue'
import dayjs from 'dayjs'
import { message, Modal } from 'ant-design-vue'
const emit = defineEmits(['ok'])
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
const { formRef, formRules, formRecord, formData, resetForm } = useForm()
const listData = ref([])
formData.value.computingCards = []
const computeDialogRef = ref()
formRules.value = {
// name: { required: true, message: '' },
}
const columns = [
{
title: '地区ID',
dataIndex: 'centerID',
key: 'centerID',
width: 100,
},
{
title: '核心数',
dataIndex: 'coreNum',
key: 'coreNum',
align: 'center',
width: 100,
},
{
title: 'GPU数量',
dataIndex: 'gpuNum',
key: 'gpuNum',
align: 'center',
width: 100,
},
{
title: 'GPU类型',
dataIndex: 'gpuType',
key: 'gpuType',
width: 100,
},
{
title: '主机ID',
dataIndex: 'hostID',
key: 'hostID',
width: 100,
},
{
title: '显存 (GB)',
dataIndex: 'vram',
key: 'vram',
align: 'center',
width: 120,
customRender: ({ value }) => (value !== undefined ? `${value} GB` : '-'),
},
{
title: '是否使用',
dataIndex: 'isUse',
key: 'isUse',
align: 'center',
width: 100,
customRender: ({ value }) => (value ? '是' : '否'),
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
width: 120,
customRender: ({ value }) => {
if (value === 'active') return '启用';
if (value === 'inactive') return '停用';
return value || '-';
},
},
{
title: '描述',
dataIndex: 'description',
key: 'description',
ellipsis: true,
width: 200,
},
{ title: '操作', key: 'action', width: 120, fixed: 'right', },
]
/**
* 新建
*/
function handleCreate(record = {}) {
showModal({
type: 'create',
title: '计算卡列表',
})
formRecord.value.hostId = record.id
getDataList()
}
function getDataList() {
try {
apis.host.getComputeCardList().then((res) => {
if (true === res.success) {
listData.value = res.data
}
})
} catch (error) {
}
}
/**
* 编辑
*/
function handleEdit(record = {}) {
showModal({
type: 'edit',
title: '编辑',
})
formRecord.value = record
formData.value = cloneDeep(record)
}
/**
* 确定
*/
function handleOk() {
formRef.value
.validateFields()
.then(async (values) => {
try {
showLoading()
const params = {
...formData.value,
}
let result = null
switch (modal.value.type) {
case 'create':
result = await apis.host.createComputeCard(params).catch(() => {
throw new Error()
})
break
case 'edit':
result = await apis.host.updatePage(formRecord.value.id, params).catch(() => {
throw new Error()
})
break
}
hideLoading()
if (true === result?.success) {
hideModal()
emit('ok')
}
} catch (error) {
hideLoading()
}
})
.catch(() => {
hideLoading()
})
}
/**
* 取消
*/
function handleCancel() {
hideModal()
}
/**
* 关闭后
*/
function onAfterClose() {
resetForm()
}
function onComputeOk() {
getDataList()
}
/**
* 删除
*/
function handleDelete({ id }) {
Modal.confirm({
title: '删除提示',
content: '确认删除?',
onOk: () => {
return new Promise((resolve, reject) => {
; (async () => {
try {
const { code } = await apis.host.delComputeCard(id).catch(() => {
throw new Error()
})
if (config('http.code.success') === code) {
resolve()
message.success('删除成功')
await getDataList()
}
} catch (error) {
reject()
}
})()
})
},
})
}
defineExpose({
handleCreate,
handleEdit,
})
</script>
<style lang="less" scoped></style>