Commit 1402aae2 authored by xuhaoze's avatar xuhaoze

宿主机业务前端初始化

parent 59efc8a7
import request from '@/utils/request'
import Qs from 'qs'
/**
* 1. 列表查询
* 2. 查询详细信息
* 3. 新增
* 4. 修改
* 5. 逻辑删除
* 6. 导出
*
*/
// 1. 查询宿主机列表
export function listResHost(query) {
return request({
url: '/reshost/list',
method: 'get',
params: query
})
}
// 2. 查询宿主机详细信息
export function getResHost(businessId) {
return request({
url: '/reshost/detail/' + businessId,
method: 'get'
})
}
// 3. 新增宿主机
export function addResHost(data) {
data = Qs.stringify(data)
return request({
url: '/reshost/add',
method: 'post',
data: data
})
}
// 4. 修改宿主机
export function updateResHost(data) {
const businessId = data.businessId
data = Qs.stringify(data)
return request({
url: '/reshost/update/' + businessId,
method: 'put',
data
})
}
// 5. 逻辑删除宿主机
export function delResHost(businessId) {
return request({
url: '/reshost/deleteLogical/' + businessId,
method: 'delete'
})
}
// 6. 导出宿主机
export function exportResHost(query) {
return request({
url: '/reshost/export',
method: 'get',
params: query,
responseType: 'blob'
})
}
<template>
<div class="app-container">
<el-form ref="queryForm" style="padding: 0 0 0 10px" :model="queryParams" :inline="true">
<el-form-item label="宿主机名称" prop="hostName">
<el-input
v-model="queryParams.hostName"
placeholder="请输入宿主机名称"
clearable
:maxlength="255"
size="small"
style="width: 150px"
/>
</el-form-item>
<el-form-item label="宿主机状态" prop="hostStatus">
<el-input
v-model="queryParams.hostStatus"
placeholder="请输入宿主机状态"
clearable
:maxlength="1"
size="small"
style="width: 150px"
/>
</el-form-item>
<el-form-item label="CPU" prop="hostCpu">
<el-input
v-model="queryParams.hostCpu"
placeholder="请输入cpu"
clearable
:maxlength="255"
size="small"
style="width: 150px"
/>
</el-form-item>
<el-form-item label="已分配cpu" prop="hostCpuUsage">
<el-input
v-model="queryParams.hostCpuUsage"
placeholder="请输入已分配cpu"
clearable
:maxlength="255"
size="small"
style="width: 150px"
/>
</el-form-item>
<el-form-item label="内存" prop="hostMemory">
<el-input
v-model="queryParams.hostMemory"
placeholder="请输入memory"
clearable
:maxlength="255"
size="small"
style="width: 150px"
/>
</el-form-item>
<el-form-item label="已分配内存" prop="hostMemoryUsage">
<el-input
v-model="queryParams.hostMemoryUsage"
placeholder="请输入已分配内存"
clearable
:maxlength="255"
size="small"
style="width: 150px"
/>
</el-form-item>
<el-form-item label="硬盘" prop="hostDisk">
<el-input
v-model="queryParams.hostDisk"
placeholder="请输入disk"
clearable
:maxlength="255"
size="small"
style="width: 150px"
/>
</el-form-item>
<el-form-item label="已分配disk" prop="hostDiskUsage">
<el-input
v-model="queryParams.hostDiskUsage"
placeholder="请输入已分配disk"
clearable
:maxlength="255"
size="small"
style="width: 150px"
/>
</el-form-item>
<el-form-item label="GPU" prop="hostGpu">
<el-input
v-model="queryParams.hostGpu"
placeholder="请输入gpu"
clearable
:maxlength="255"
size="small"
style="width: 150px"
/>
</el-form-item>
<el-form-item label="已分配gpu" prop="hostGpuUsage">
<el-input
v-model="queryParams.hostGpuUsage"
placeholder="请输入已分配gpu"
clearable
:maxlength="255"
size="small"
style="width: 150px"
/>
</el-form-item>
<el-form-item label="实例数量" prop="hostContainerInstanceNum">
<el-input
v-model="queryParams.hostContainerInstanceNum"
placeholder="请输入实例数量"
clearable
:maxlength="255"
size="small"
style="width: 150px"
/>
</el-form-item>
<el-form-item label="宿主机ip" prop="hostIp">
<el-input
v-model="queryParams.hostIp"
placeholder="请输入宿主机ip"
clearable
:maxlength="255"
size="small"
style="width: 150px"
/>
</el-form-item>
<el-form-item label="状态" prop="flag">
<el-select v-model="queryParams.flag" placeholder="请选择状态" clearable size="small">
<el-option
v-for="dict in statusOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button
:class="commonField.queryClass"
:type="commonField.typePrimary"
:icon="commonField.queryIcon"
:size="commonField.smallSize"
@click="handleQuery"
>查询</el-button>
<el-button
:class="commonField.resetClass"
:icon="commonField.resetIcon"
:size="commonField.smallSize"
@click="resetQuery"
>重置</el-button>
</el-form-item>
<div style="float: right">
<el-form-item>
<el-button
:class="commonField.addClass"
:type="commonField.typePrimary"
:icon="commonField.addIcon"
:size="commonField.smallSize"
@click="handleAdd"
>新增</el-button>
<el-button
:class="commonField.exportClass"
:type="commonField.typeSuccess"
:icon="commonField.exportIcon"
:size="commonField.smallSize"
@click="handleExport"
>导出</el-button>
</el-form-item>
</div>
</el-form>
<div class="placeholder" />
<div style="padding:5px 10px">
<div class="mb12 font-small-bold">宿主机列表</div>
<el-table v-loading="loading" border :data="resHostList">
<el-table-column type="index" label="序号" width="55" align="center" />
<el-table-column label="宿主机名称" prop="hostName" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.hostName || '-' }}
</template>
</el-table-column>
<el-table-column label="宿主机状态" prop="hostStatus" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.hostStatus || '-' }}
</template>
</el-table-column>
<el-table-column label="cpu" prop="hostCpu" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.hostCpu || '-' }}
</template>
</el-table-column>
<el-table-column label="已分配cpu" prop="hostCpuUsage" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.hostCpuUsage || '-' }}
</template>
</el-table-column>
<el-table-column label="内存" prop="hostMemory" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.hostMemory || '-' }}
</template>
</el-table-column>
<el-table-column label="已分配内存" prop="hostMemoryUsage" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.hostMemoryUsage || '-' }}
</template>
</el-table-column>
<el-table-column label="硬盘" prop="hostDisk" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.hostDisk || '-' }}
</template>
</el-table-column>
<el-table-column label="已分配硬盘" prop="hostDiskUsage" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.hostDiskUsage || '-' }}
</template>
</el-table-column>
<el-table-column label="GPU" prop="hostGpu" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.hostGpu || '-' }}
</template>
</el-table-column>
<el-table-column label="已分配gpu" prop="hostGpuUsage" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.hostGpuUsage || '-' }}
</template>
</el-table-column>
<el-table-column label="实例数量" prop="hostContainerInstanceNum" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.hostContainerInstanceNum || '-' }}
</template>
</el-table-column>
<el-table-column label="宿主机ip" prop="hostIp" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.hostIp || '-' }}
</template>
</el-table-column>
<el-table-column width="120" label="状态" prop="flag">
<template slot-scope="scope">
<el-switch
v-model="scope.row.flag"
class="switchDisabledStyle"
inactive-value="0"
active-value="1"
@click.native="handleStatusChange(scope.row)"
/>
</template>
</el-table-column>
<el-table-column label="备注" prop="remarks" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.remarks || '-' }}
</template>
</el-table-column>
<el-table-column label="创建时间" prop="createDate" :show-overflow-tooltip="true">
<template slot-scope="scope">
<span>{{ scope.row.createDate | transformDateByFormat('YYYY-MM-DD HH:mm') }}</span>
</template>
</el-table-column>
<el-table-column label="操作" class-name="small-padding fixed-width" width="200px">
<template slot-scope="scope">
<el-button
:class="commonField.updateClass"
:type="commonField.typeParent"
:size="commonField.size"
@click="handleUpdate(scope.row)"
>修改</el-button>
<el-button
:class="commonField.delClass"
:type="commonField.typeParent"
:size="commonField.size"
@click="handleDelete(scope.row)"
>删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.page"
:limit.sync="queryParams.rows"
@pagination="getList"
/>
<!-- 添加或修改宿主机配置对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="90px">
<el-form-item label="宿主机名称" prop="hostName">
<el-input v-model.trim="form.hostName" show-word-limit :maxlength="255" placeholder="请输入宿主机名称" />
</el-form-item>
<el-form-item label="宿主机状态" prop="hostStatus">
<el-input v-model.trim="form.hostStatus" show-word-limit :maxlength="1" placeholder="请输入宿主机状态(1正常,2告警,3下线)" />
</el-form-item>
<el-form-item label="cpu" prop="hostCpu">
<el-input v-model.trim="form.hostCpu" show-word-limit :maxlength="255" placeholder="请输入cpu" />
</el-form-item>
<el-form-item label="已分配cpu" prop="hostCpuUsage">
<el-input v-model.trim="form.hostCpuUsage" show-word-limit :maxlength="255" placeholder="请输入已分配cpu" />
</el-form-item>
<el-form-item label="memory" prop="hostMemory">
<el-input v-model.trim="form.hostMemory" show-word-limit :maxlength="255" placeholder="请输入memory" />
</el-form-item>
<el-form-item label="已分配内存" prop="hostMemoryUsage">
<el-input v-model.trim="form.hostMemoryUsage" show-word-limit :maxlength="255" placeholder="请输入已分配内存" />
</el-form-item>
<el-form-item label="disk" prop="hostDisk">
<el-input v-model.trim="form.hostDisk" show-word-limit :maxlength="255" placeholder="请输入disk" />
</el-form-item>
<el-form-item label="已分配disk" prop="hostDiskUsage">
<el-input v-model.trim="form.hostDiskUsage" show-word-limit :maxlength="255" placeholder="请输入已分配disk" />
</el-form-item>
<el-form-item label="gpu" prop="hostGpu">
<el-input v-model.trim="form.hostGpu" show-word-limit :maxlength="255" placeholder="请输入gpu" />
</el-form-item>
<el-form-item label="已分配gpu" prop="hostGpuUsage">
<el-input v-model.trim="form.hostGpuUsage" show-word-limit :maxlength="255" placeholder="请输入已分配gpu" />
</el-form-item>
<el-form-item label="实例数量" prop="hostContainerInstanceNum">
<el-input v-model.trim="form.hostContainerInstanceNum" show-word-limit :maxlength="255" placeholder="请输入实例数量" />
</el-form-item>
<el-form-item label="宿主机ip" prop="hostIp">
<el-input v-model.trim="form.hostIp" show-word-limit :maxlength="255" placeholder="请输入宿主机ip" />
</el-form-item>
<el-form-item label="状态">
<el-radio-group v-model="form.flag">
<el-radio label="1">启用</el-radio>
<el-radio label="0">停用</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="备注" prop="remarks">
<el-input v-model.trim="form.remarks" maxlength="200" show-word-limit type="textarea" placeholder="请输入内容" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button class="cancelBtn" @click="cancel">取 消</el-button>
<el-button class="submitBtn" type="primary" @click="submitForm">确 定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {
listResHost,
getResHost,
delResHost,
addResHost,
updateResHost,
exportResHost } from '@/api/resHost'
import commonField from '@/utils/commonField'
export default {
name: 'ResHost',
data() {
return {
// 遮罩层
loading: true,
// 总条数
total: 0,
// 宿主机表格数据
resHostList: [],
// 弹出层标题
title: '',
// 是否显示弹出层
open: false,
// 状态菜单
statusOptions: [
{
dictLabel: '启用',
dictValue: '1'
},
{
dictLabel: '停用',
dictValue: '0'
}
],
// 查询参数
queryParams: {
page: 1,
rows: 10,
hostName: undefined,
hostStatus: undefined,
hostCpu: undefined,
hostCpuUsage: undefined,
hostMemory: undefined,
hostMemoryUsage: undefined,
hostDisk: undefined,
hostDiskUsage: undefined,
hostGpu: undefined,
hostGpuUsage: undefined,
hostContainerInstanceNum: undefined,
hostIp: undefined,
flag: ''
},
// 表单参数
form: {},
// 表单校验
rules: {
}
}
},
computed: {
commonField() {
return commonField
}
},
created() {
this.getList() // 列表查询
},
methods: {
/** 查询宿主机列表 */
getList() {
this.loading = true
listResHost(this.queryParams).then(
response => {
this.resHostList = response.rows
this.total = response.total
this.loading = false
}
)
},
// 取消按钮
cancel() {
this.open = false
this.reset()
},
// 表单重置
reset() {
this.form = {
businessId: undefined,
remarks: undefined,
hostName: undefined,
hostStatus: undefined,
hostCpu: undefined,
hostCpuUsage: undefined,
hostMemory: undefined,
hostMemoryUsage: undefined,
hostDisk: undefined,
hostDiskUsage: undefined,
hostGpu: undefined,
hostGpuUsage: undefined,
hostContainerInstanceNum: undefined,
hostIp: undefined,
flag: '1'
}
this.resetForm('form')
},
/** 查询按钮操作 */
handleQuery() {
this.queryParams.page = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.queryParams = {
page: 1,
rows: 10,
hostName: undefined,
hostStatus: undefined,
hostCpu: undefined,
hostCpuUsage: undefined,
hostMemory: undefined,
hostMemoryUsage: undefined,
hostDisk: undefined,
hostDiskUsage: undefined,
hostGpu: undefined,
hostGpuUsage: undefined,
hostContainerInstanceNum: undefined,
hostIp: undefined,
flag: ''
}
this.handleQuery()
},
/** 新增按钮操作 */
handleAdd() {
this.reset()
this.open = true
this.title = '添加宿主机'
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset()
const id = row.businessId
getResHost(id).then(response => {
this.form = response.data
this.open = true
this.title = '修改宿主机'
})
},
// 改变状态
handleStatusChange(row) {
const text = row.flag === '1' ? '启用' : '停用'
this.$confirm('确认操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
return updateResHost(row)
}).then(() => {
this.$message({
message: text + '成功',
type: 'success'
})
}).catch(function() {
row.flag = row.flag === '0' ? '1' : '0'
})
},
/** 提交按钮 */
submitForm: function() {
this.$refs['form'].validate(valid => {
if (valid) {
if (this.form.businessId !== undefined) {
updateResHost(this.form).then(response => {
this.msgSuccess('修改成功')
this.open = false
this.getList()
})
} else {
addResHost(this.form).then(response => {
this.msgSuccess('新增成功')
this.open = false
this.getList()
})
}
}
})
},
/** 删除按钮操作 */
handleDelete(row) {
const id = row.businessId
this.$confirm('是否确认操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
return delResHost(id)
}).then(() => {
this.getList()
this.$message({
message: '删除成功',
type: 'success'
})
}).catch(function() {
})
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams
this.$confirm('是否确认操作?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
return exportResHost(queryParams).then(response => {
const blob = new Blob([response])
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)// 创建下载的链接
downloadElement.href = href
downloadElement.download = '宿主机信息' + '.xls' // 下载后文件名
document.body.appendChild(downloadElement)
downloadElement.click()// 点击下载
document.body.removeChild(downloadElement)// 下载完成移除元素
window.URL.revokeObjectURL(href)// 释放掉blob对象
})
})
}
}
}
</script>
<style lang="scss" scoped>
.app-container {
font-size: 18px;
padding: 0;
.placeholder {
height: 1.3vh;
background-color: #F4F4F4;
margin-bottom: 10px
}
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment