This commit is contained in:
qiuyuan 2026-01-27 16:04:48 +08:00
parent db0fc99a24
commit 6c2042ccee
5 changed files with 46 additions and 176 deletions

View File

@ -1,8 +1,5 @@
import request from '@/utils/request'
//获取主机列表
export const getHostList = (params) => request.basic.get('/api/v1/power-hosts', params)
//获取算力卡列表
export const getCardsList = (params) => request.basic.get('/api/v1/cards', params)

View File

@ -3,7 +3,7 @@
*/
import request from '@/utils/request'
// 获取主机列表
export const getPageList = (params) => request.basic.get('/api/v1/power-hosts', params)
export const getHostList = (params) => request.basic.get('/api/v1/power-hosts', params)
// 删除主机列表
export const delHost = (id) => request.basic.delete(`/api/v1/power-hosts/${id}`)
// 编辑主机列表

View File

@ -1,158 +0,0 @@
<template>
<a-modal :open="modal.open" :title="modal.title" :width="640" :confirm-loading="modal.confirmLoading"
:after-close="onAfterClose" :cancel-text="cancelText" :ok-text="okText" @ok="handleOk" @cancel="handleCancel">
<a-form ref="formRef" :model="formData" :rules="formRules">
<a-card class="mb-8-2">
<a-row :gutter="24">
<a-col :span="24">
<a-form-item :label="$t('pages.system.role.form.name')" name="name">
<a-input v-model:value="formData.name"></a-input>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item :label="$t('pages.system.role.form.sequence')" name="sequence">
<a-input :defaultValue="0" type="number" v-model:value="formData.sequence"></a-input>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item :label="$t('pages.system.role.form.status')" name="status">
<a-radio-group v-model:value="formData.status" :options="[
{ label: $t('pages.system.role.form.status.enabled'), value: 'enabled' },
{ label: $t('pages.system.role.form.status.disabled'), value: 'disabled' },
]"></a-radio-group>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item :label="'描述'">
<a-textarea v-model:value="formData.description"></a-textarea>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item :label="'上传图片'" name="permissions">
<GxUpload :fileNumber="1" />
</a-form-item>
</a-col>
</a-row>
</a-card>
</a-form>
</a-modal>
</template>
<script setup>
import { cloneDeep } from 'lodash-es'
import { message } from 'ant-design-vue'
import { ref, watch } from 'vue'
import { config } from '@/config'
import apis from '@/apis'
import { useForm, useModal } from '@/hooks'
import GxUpload from '@/components/GxUpload/index.vue'
const emit = defineEmits(['ok'])
import { useI18n } from 'vue-i18n'
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
const { formRecord, formData, formRef, formRules, resetForm } = useForm()
const { t } = useI18n() // t
const cancelText = ref(t('button.cancel'))
const okText = ref(t('button.confirm'))
formData.value.enabled='enabled'
formRules.value = {
name: { required: true, message: t('pages.system.role.form.name.placeholder') },
code: { required: true, message: t('pages.system.role.form.code.placeholder') },
status: { required: true, message: t('pages.system.role.form.status.placeholder') },
}
/**
* 新建
*/
function handleCreate() {
showModal({
type: 'create',
title: t('pages.system.role.add'),
})
}
/**
* 编辑
*/
async function handleEdit(record = {}) {
showModal({
type: 'edit',
title: t('pages.system.role.edit'),
})
const { data, success } = await apis.host.getHostDetail(record.id).catch()
if (!success) {
message.error(t('component.message.error.save'))
hideModal()
return
}
let menus = []
if (data.menus) {
for (let item of data.menus) {
menus.push(item.menu_id)
}
}
checkedKeys.value = menus
formRecord.value = data
formData.value = cloneDeep(data)
}
/**
* 确定
*/
function handleOk() {
formRef.value
.validateFields()
.then(async (values) => {
try {
showLoading()
const params = {...values}
let result = null
switch (modal.value.type) {
case 'create':
result = await apis.banner.createBanner(params).catch(() => {
throw new Error()
})
break
case 'edit':
result = await apis.host.updateHost(formData.value.id, params).catch(() => {
throw new Error()
})
break
}
hideLoading()
if (config('http.code.success') === result?.success) {
hideModal()
emit('ok')
}
} catch (error) {
hideLoading()
}
})
.catch(() => {
hideLoading()
})
}
/**
* 取消
*/
function handleCancel() {
hideModal()
}
/**
* 关闭后
*/
function onAfterClose() {
resetForm()
hideLoading()
}
defineExpose({
handleCreate,
handleEdit,
})
</script>
<style lang="less" scoped></style>

View File

@ -75,16 +75,20 @@
</template>
<template v-if="'action' === column.key">
<!-- <x-action-button @click="$refs.editDialogRef.handleEdit(record)">
<x-action-button @click="handelEdit(record)" :disabled="record.status === 'DISABLED'">
<a-tooltip>
<template #title> {{ $t('pages.system.role.edit') }}</template>
<edit-outlined />
</a-tooltip>
</x-action-button> -->
<template #title>
{{ record.status === 'DISABLED' ? '已下架' : '下架主机' }}
</template>
<edit-outlined />
</a-tooltip>
</x-action-button>
<x-action-button @click="handleRemove(record)">
<a-tooltip>
<template #title> {{ $t('pages.system.delete') }}</template>
<delete-outlined style="color: #ff4d4f" />
<template #title>
{{ $t('pages.system.delete') }}
</template>
<delete-outlined style="color: red;" />
</a-tooltip>
</x-action-button>
</template>
@ -94,7 +98,6 @@
</a-col>
</a-row>
<edit-dialog ref="editDialogRef" @ok="onOk"></edit-dialog>
</template>
<script setup>
@ -105,7 +108,6 @@ import { formatUtcDateTime } from '@/utils/util'
import { config } from '@/config'
import { statusTypeEnum } from '@/enums/system'
import { usePagination, useForm } from '@/hooks'
import EditDialog from './components/EditDialog.vue'
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'
import { useI18n } from 'vue-i18n'
import { disabledDict } from '@/enums/dict'
@ -172,7 +174,6 @@ const columns = [
const { listData, loading, showLoading, hideLoading, paginationState, searchFormData, resetPagination } =
usePagination()
const { resetForm } = useForm()
const editDialogRef = ref()
getPageList()
@ -184,7 +185,7 @@ async function getPageList() {
try {
showLoading()
const { pageSize, current } = paginationState
const { data, total } = await apis.computing
const { data, total } = await apis.host
.getHostList({
pageSize,
current: current,
@ -208,8 +209,8 @@ async function getPageList() {
*/
function handleRemove({ id }) {
Modal.confirm({
title: t('pages.system.role.delTip'),
content: t('button.confirm'),
title: '提示',
content: '是否删除该主机?',
okText: t('button.confirm'),
onOk: () => {
return new Promise((resolve, reject) => {
@ -232,6 +233,37 @@ function handleRemove({ id }) {
})
}
//
function handelEdit({ id, status }) {
if (status === 'DISABLED') {
message.warning('该主机已下架,无法重复操作');
return;
}
Modal.confirm({
title: '提示',
content: '是否下架该主机?',
okText: t('button.confirm'),
onOk: () => {
return new Promise((resolve, reject) => {
; (async () => {
try {
const { success } = await apis.host.updateHost(id).catch(() => {
throw new Error()
})
if (config('http.code.success') === success) {
resolve()
message.success('下架成功')
await getPageList()
}
} catch (error) {
reject()
}
})()
})
},
})
}
/**
* 分页
*/

View File

@ -134,7 +134,6 @@ async function getPageList() {
.catch(() => {
throw new Error()
})
console.log("====data",data)
hideLoading()
if (data.length > 0) {
listData.value = data