generated from Leo_Ding/web-template
主机
This commit is contained in:
parent
db0fc99a24
commit
6c2042ccee
@ -1,8 +1,5 @@
|
|||||||
import request from '@/utils/request'
|
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)
|
export const getCardsList = (params) => request.basic.get('/api/v1/cards', params)
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
import request from '@/utils/request'
|
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}`)
|
export const delHost = (id) => request.basic.delete(`/api/v1/power-hosts/${id}`)
|
||||||
// 编辑主机列表
|
// 编辑主机列表
|
||||||
|
|||||||
@ -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>
|
|
||||||
@ -75,16 +75,20 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-if="'action' === column.key">
|
<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>
|
<a-tooltip>
|
||||||
<template #title> {{ $t('pages.system.role.edit') }}</template>
|
<template #title>
|
||||||
|
{{ record.status === 'DISABLED' ? '已下架' : '下架主机' }}
|
||||||
|
</template>
|
||||||
<edit-outlined />
|
<edit-outlined />
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</x-action-button> -->
|
</x-action-button>
|
||||||
<x-action-button @click="handleRemove(record)">
|
<x-action-button @click="handleRemove(record)">
|
||||||
<a-tooltip>
|
<a-tooltip>
|
||||||
<template #title> {{ $t('pages.system.delete') }}</template>
|
<template #title>
|
||||||
<delete-outlined style="color: #ff4d4f" />
|
{{ $t('pages.system.delete') }}
|
||||||
|
</template>
|
||||||
|
<delete-outlined style="color: red;" />
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</x-action-button>
|
</x-action-button>
|
||||||
</template>
|
</template>
|
||||||
@ -94,7 +98,6 @@
|
|||||||
</a-col>
|
</a-col>
|
||||||
</a-row>
|
</a-row>
|
||||||
|
|
||||||
<edit-dialog ref="editDialogRef" @ok="onOk"></edit-dialog>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@ -105,7 +108,6 @@ import { formatUtcDateTime } from '@/utils/util'
|
|||||||
import { config } from '@/config'
|
import { config } from '@/config'
|
||||||
import { statusTypeEnum } from '@/enums/system'
|
import { statusTypeEnum } from '@/enums/system'
|
||||||
import { usePagination, useForm } from '@/hooks'
|
import { usePagination, useForm } from '@/hooks'
|
||||||
import EditDialog from './components/EditDialog.vue'
|
|
||||||
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'
|
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { disabledDict } from '@/enums/dict'
|
import { disabledDict } from '@/enums/dict'
|
||||||
@ -172,7 +174,6 @@ const columns = [
|
|||||||
const { listData, loading, showLoading, hideLoading, paginationState, searchFormData, resetPagination } =
|
const { listData, loading, showLoading, hideLoading, paginationState, searchFormData, resetPagination } =
|
||||||
usePagination()
|
usePagination()
|
||||||
const { resetForm } = useForm()
|
const { resetForm } = useForm()
|
||||||
const editDialogRef = ref()
|
|
||||||
|
|
||||||
getPageList()
|
getPageList()
|
||||||
|
|
||||||
@ -184,7 +185,7 @@ async function getPageList() {
|
|||||||
try {
|
try {
|
||||||
showLoading()
|
showLoading()
|
||||||
const { pageSize, current } = paginationState
|
const { pageSize, current } = paginationState
|
||||||
const { data, total } = await apis.computing
|
const { data, total } = await apis.host
|
||||||
.getHostList({
|
.getHostList({
|
||||||
pageSize,
|
pageSize,
|
||||||
current: current,
|
current: current,
|
||||||
@ -208,8 +209,8 @@ async function getPageList() {
|
|||||||
*/
|
*/
|
||||||
function handleRemove({ id }) {
|
function handleRemove({ id }) {
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
title: t('pages.system.role.delTip'),
|
title: '提示',
|
||||||
content: t('button.confirm'),
|
content: '是否删除该主机?',
|
||||||
okText: t('button.confirm'),
|
okText: t('button.confirm'),
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
return new Promise((resolve, reject) => {
|
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()
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页
|
* 分页
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -134,7 +134,6 @@ async function getPageList() {
|
|||||||
.catch(() => {
|
.catch(() => {
|
||||||
throw new Error()
|
throw new Error()
|
||||||
})
|
})
|
||||||
console.log("====data",data)
|
|
||||||
hideLoading()
|
hideLoading()
|
||||||
if (data.length > 0) {
|
if (data.length > 0) {
|
||||||
listData.value = data
|
listData.value = data
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user