添加运维系统

This commit is contained in:
zhanghouying
2019-11-19 11:42:54 +08:00
parent 752d9c8478
commit b313fe34dd
25 changed files with 2728 additions and 0 deletions

180
src/views/mnt/app/form.vue Normal file
View File

@@ -0,0 +1,180 @@
<template>
<el-dialog
:append-to-body="true"
:close-on-click-modal="false"
:visible.sync="dialog"
:title="isAdd ? '新增' : '编辑'"
width="800px"
>
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px">
<el-form-item label="应用名称" prop="name">
<el-input v-model="form.name" style="width: 670px" placeholder="部署后的文件或者目录名称,用于备份" />
</el-form-item>
<el-form-item label="应用端口" prop="port">
<el-input-number v-model="form.port" placeholder="例如8080" />
</el-form-item>
<el-form-item label="上传目录" prop="uploadPath">
<el-input
v-model="form.uploadPath"
style="width: 670px"
placeholder="例如: /opt/upload"
/>
</el-form-item>
<el-form-item label="部署目录" prop="deployPath">
<el-input
v-model="form.deployPath"
style="width: 670px"
placeholder="例如: /opt/app"
/>
</el-form-item>
<el-form-item label="备份目录" prop="backupPath">
<el-input
v-model="form.backupPath"
style="width: 670px"
placeholder="例如: /opt/backup"
/>
</el-form-item>
<el-form-item label="启动脚本" prop="startScript">
<el-input
v-model="form.startScript"
:rows="2"
type="textarea"
autosize
style="width: 670px"
placeholder=""
/>
</el-form-item>
<el-form-item label="部署脚本" prop="deployScript">
<el-input
v-model="form.deployScript"
:rows="2"
type="textarea"
autosize
style="width: 670px"
placeholder=""
/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="cancel">取消</el-button>
<el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
</div>
</el-dialog>
</template>
<script>
import { add, edit } from '@/api/app'
export default {
props: {
isAdd: {
type: Boolean,
required: true
}
},
data() {
return {
loading: false,
dialog: false,
form: {
id: '',
name: '',
port: 8080,
uploadPath: '/opt/upload',
deployPath: '/opt/app',
backupPath: '/opt/backup',
startScript: '',
deployScript: ''
},
rules: {
name: [
{ required: true, message: '请输入应用名称', trigger: 'change' }
],
uploadPath: [
{ required: true, message: '请输入上传目录', trigger: 'change' }
],
deployPath: [
{ required: true, message: '请输入部署目录', trigger: 'change' }
],
backupPath: [
{ required: true, message: '请输入备份目录', trigger: 'change' }
],
startScript: [
{ required: true, message: '请输入启动脚本', trigger: 'change' }
],
deployScript: [
{ required: true, message: '请输入部署脚本', trigger: 'change' }
]
}
}
},
mounted() {},
methods: {
cancel() {
this.resetForm()
},
doSubmit() {
this.$refs['form'].validate(valid => {
if (valid) {
this.loading = true
if (this.isAdd) {
this.doAdd()
} else this.doEdit()
} else {
this.$message.error('请将表单中的信息补充完整!')
}
})
},
doAdd() {
add(this.form)
.then(res => {
this.resetForm()
this.$notify({
title: '添加成功',
type: 'success',
duration: 2500
})
this.loading = false
this.$parent.init()
})
.catch(err => {
this.loading = false
console.log(err.response.data.message)
})
},
doEdit() {
edit(this.form)
.then(res => {
this.resetForm()
this.$notify({
title: '修改成功',
type: 'success',
duration: 2500
})
this.loading = false
this.$parent.init()
})
.catch(err => {
this.loading = false
console.log(err.response.data.message)
})
},
resetForm() {
this.dialog = false
this.$refs['form'].resetFields()
this.form = {
id: '',
name: '',
port: 8080,
uploadPath: '/opt/upload',
deployPath: '/opt/app',
backupPath: '/opt/backup',
startScript: '',
deployScript: ''
}
}
}
}
</script>
<style scoped>
</style>

214
src/views/mnt/app/index.vue Normal file
View File

@@ -0,0 +1,214 @@
<template>
<div class="app-container">
<!--工具栏-->
<div class="head-container">
<!-- 搜索 -->
<el-input
v-model="query.value"
clearable
placeholder="输入搜索内容"
style="width: 200px"
class="filter-item"
@keyup.enter.native="toQuery"
/>
<el-select
v-model="query.type"
clearable
placeholder="类型"
class="filter-item"
style="width: 130px"
>
<el-option
v-for="item in queryTypeOptions"
:key="item.key"
:label="item.display_name"
:value="item.key"
/>
</el-select>
<el-button
class="filter-item"
size="mini"
type="success"
icon="el-icon-search"
@click="toQuery"
>搜索</el-button>
<!-- 新增 -->
<div style="display: inline-block;margin: 0px 2px">
<el-button
v-permission="['admin','app:add']"
class="filter-item"
size="mini"
type="primary"
icon="el-icon-plus"
@click="add"
>新增</el-button>
<el-button
v-permission="['admin','app:add']"
class="filter-item"
size="mini"
type="primary"
icon="el-icon-plus"
@click="copy"
>复制新增</el-button>
</div>
</div>
<!--表单组件-->
<eForm ref="form" :is-add="isAdd" />
<!--表格渲染-->
<el-table
v-loading="loading"
:data="data"
highlight-current-row
size="small"
style="width: 100%"
@current-change="handleCurrentChange"
>
<el-table-column prop="name" label="应用名称" />
<el-table-column prop="port" label="端口号" />
<el-table-column prop="deployPath" label="部署目录" />
<el-table-column
v-if="checkPermission(['admin','app:edit','app:del'])"
label="操作"
width="150px"
align="center"
>
<template slot-scope="scope">
<el-button
v-permission="['admin','app:edit']"
size="mini"
type="primary"
icon="el-icon-edit"
@click="edit(scope.row)"
/>
<el-popover
v-permission="['admin','app:del']"
:ref="scope.row.id"
placement="top"
width="180"
>
<p>确定删除本条数据吗</p>
<div style="text-align: right; margin: 0">
<el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
<el-button
:loading="delLoading"
type="primary"
size="mini"
@click="subDelete(scope.row.id)"
>确定</el-button>
</div>
<el-button slot="reference" type="danger" icon="el-icon-delete" size="mini" />
</el-popover>
</template>
</el-table-column>
</el-table>
<!--分页组件-->
<el-pagination
:total="total"
:current-page="page + 1"
style="margin-top: 8px"
layout="total, prev, pager, next, sizes"
@size-change="sizeChange"
@current-change="pageChange"
/>
</div>
</template>
<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { del } from '@/api/app'
import eForm from './form'
export default {
components: { eForm },
mixins: [initData],
data() {
return {
delLoading: false,
queryTypeOptions: [{ key: 'name', display_name: '应用名称' }],
currentRow: {}
}
},
created() {
this.$nextTick(() => {
this.init()
})
},
methods: {
checkPermission,
beforeInit() {
this.url = 'api/app'
const sort = 'id,desc'
this.params = { page: this.page, size: this.size, sort: sort }
const query = this.query
const type = query.type
const value = query.value
if (type && value) {
this.params[type] = value
}
return true
},
subDelete(id) {
this.delLoading = true
del(id)
.then(res => {
this.delLoading = false
this.$refs[id].doClose()
this.dleChangePage()
this.init()
this.$notify({
title: '删除成功',
type: 'success',
duration: 2500
})
})
.catch(err => {
this.delLoading = false
this.$refs[id].doClose()
console.log(err.response.data.message)
})
},
add() {
this.isAdd = true
this.$refs.form.dialog = true
const _this = this.$refs.form
_this.form = {
id: '',
name: '',
port: 8080,
uploadPath: '/opt/upload',
deployPath: '/opt/app',
backupPath: '/opt/backup',
startScript: '',
deployScript: ''
}
},
copy() {
this.isAdd = true
this.$refs.form.dialog = true
const _this = this.$refs.form
_this.form = this.currentRow
},
edit(data) {
this.isAdd = false
const _this = this.$refs.form
_this.form = {
id: data.id,
name: data.name,
port: data.port,
uploadPath: data.uploadPath,
deployPath: data.deployPath,
backupPath: data.backupPath,
startScript: data.startScript,
deployScript: data.deployScript
}
_this.dialog = true
},
handleCurrentChange(row) {
this.currentRow = row
}
}
}
</script>
<style scoped>
</style>