Files
dvcp_v2_webapp/project/oms/apps/AppDeploy/AppDeploy.vue

210 lines
6.7 KiB
Vue
Raw Normal View History

2022-03-30 19:20:44 +08:00
<template>
<section class="AppDeploy">
<ai-list>
<ai-title slot="title" title="部署发布" isShowBottomBorder/>
<template #content>
<ai-search-bar>
<template #left>
<el-button type="primary" icon="iconfont iconAdd" @click="dialog=true">增加</el-button>
</template>
<template #right>
<el-input size="small" placeholder="搜索项目/系统" v-model="search.name" clearable
@change="page.current=1,getTableData()"/>
</template>
2022-03-30 19:20:44 +08:00
</ai-search-bar>
<ai-table :tableData="tableData" :total="page.total" :current.sync="page.current" :size.sync="page.size"
@getList="getTableData" :col-configs="colConfigs" :dict="dict">
2022-04-01 16:09:49 +08:00
<el-table-column slot="process" label="打包进度">
<template slot-scope="{row}">
<span v-if="row.count==0" v-text="row.download?`最近打包时间:${row.download}`:`暂无打包`"/>
<el-progress v-else :percentage="row.count"/>
</template>
</el-table-column>
<el-table-column slot="options" label="操作" fixed="right" align="center" width="300">
2022-03-30 19:20:44 +08:00
<template slot-scope="{row}">
<el-button type="text" @click="handleEdit(row)">编辑</el-button>
<el-button type="text" @click="handleDelete(row.id)">删除</el-button>
2022-03-31 18:23:20 +08:00
<el-button type="text" @click="handleZip(row)">打包</el-button>
<el-button type="text" v-if="row.download" @click="handleDownload(row)">下载</el-button>
2022-04-01 16:09:49 +08:00
<el-button v-if="row.target" type="text" @click="handleUpdateSystem(row)">更新部署</el-button>
2022-03-30 19:20:44 +08:00
</template>
</el-table-column>
</ai-table>
</template>
</ai-list>
<ai-dialog :visible.sync="dialog" title="部署任务设置" width="600px" @close="form={}" @onConfirm="submit">
<el-form ref="DialogForm" :model="form" size="small" label-width="100px" :rules="rules">
<el-form-item label="项目/系统" prop="name">
<el-input v-model="form.name" clearable placeholder="请输入"/>
</el-form-item>
<el-form-item label="git" prop="git">
<el-input v-model="form.git" clearable placeholder="请输入"/>
</el-form-item>
2022-03-31 09:08:03 +08:00
<el-form-item label="git分支" prop="branch">
<el-input v-model="form.branch" clearable placeholder="请输入"/>
</el-form-item>
2022-04-01 16:09:49 +08:00
<el-form-item label="开发环境nginx" prop="target">
2022-03-30 19:20:44 +08:00
<el-input v-model="form.target" clearable placeholder="请输入"/>
</el-form-item>
</el-form>
</ai-dialog>
</section>
</template>
<script>
import {mapState} from "vuex";
export default {
name: "AppDeploy",
label: "部署发布",
props: {
instance: Function,
dict: Object,
permissions: Function
},
computed: {
...mapState(['user'])
},
data() {
return {
search: {name: ""},
page: {current: 1, size: 10, total: 0},
tableData: [],
colConfigs: [
2022-04-01 16:09:49 +08:00
{label: "项目/系统名称", prop: "name", width: 200},
{label: "git", render: (h, {row}) => h('p', {class: "textRight"}, row.git)},
{label: "git分支", prop: "branch", width: 140},
{label: "开发环境nginx", prop: "target"},
{slot: "process"},
2022-03-30 19:20:44 +08:00
{slot: "options"}
],
dialog: false,
form: {},
rules: {
name: {required: true, message: "请输入项目/系统名称"},
git: {required: true, message: "请输入git"},
2022-03-31 09:08:03 +08:00
branch: {required: true, message: "请输入 git分支"},
2022-03-30 19:20:44 +08:00
}
}
},
methods: {
getTableData() {
this.instance.post("/node/autodeploy/list", null, {
params: {...this.page, ...this.search}
}).then(res => {
if (res?.data) {
2022-04-01 16:09:49 +08:00
this.tableData = res.data?.records.map(e => ({...e, count: 0}))
2022-03-30 19:20:44 +08:00
this.page.total = res.data.total
}
})
},
handleDownload(row) {
2022-04-01 16:09:49 +08:00
let {id} = row
this.instance.post("/node/autodeploy/download", null, {
params: {id},
responseType: "blob"
}).then(res => {
if (res?.code == 1) {
this.$message.error(res.err)
} else {
const link = document.createElement('a')
let blob = new Blob([res], {type: 'application/zip'})
link.style.display = 'none'
link.href = URL.createObjectURL(blob)
link.setAttribute('download', row.name + '.zip')
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
})
2022-03-31 18:23:20 +08:00
},
handleZip(row) {
2022-04-01 16:09:49 +08:00
let {id} = row
this.instance.post("/node/autodeploy/getZip", null, {
params: {id}
}).then(res => {
if (res?.code == 0) {
2022-04-01 16:09:49 +08:00
row.count = 1
let timer = setInterval(() => {
if (row.count >= 100) {
2022-03-31 18:23:20 +08:00
clearInterval(timer)
2022-03-31 18:25:28 +08:00
this.$message.error("打包失败!")
2022-04-01 16:09:49 +08:00
} else this.handleConfirmZip(row).then(v => {
if (v) {
2022-03-31 18:23:20 +08:00
clearInterval(timer)
2022-04-01 16:09:49 +08:00
row.count = 100
row.download = true
} else row.count++
})
}, 3000)
}
})
},
handleUpdateSystem(row) {
let {id} = row
return this.instance.post("/node/autodeploy/updateSystem", null, {
params: {id}
}).then(res => {
if (res?.code == 0) {
}
2022-04-01 16:09:49 +08:00
})
2022-03-30 19:20:44 +08:00
},
handleEdit(row) {
this.form = JSON.parse(JSON.stringify(row))
this.dialog = true
},
submit() {
this.$refs.DialogForm.validate(v => {
if (v) {
this.instance.post("/node/autodeploy/addOrUpdate", this.form).then(res => {
if (res?.code == 0) {
this.$message.success("提交成功")
this.getTableData()
this.dialog = false
}
})
}
})
},
handleDelete(ids) {
this.$confirm("是否要删除该项目/系统?").then(() => {
this.instance.post("/node/autodeploy/delete", null, {
params: {ids}
}).then(res => {
if (res?.code == 0) {
this.$message.success("删除成功")
this.getTableData()
}
})
}).catch(() => 0)
2022-04-01 16:09:49 +08:00
},
handleConfirmZip(row) {
let {id} = row
return this.instance.post("/node/autodeploy/confirmZip", null, {
params: {id}
}).then(res => {
if (res?.code == 0) return res.data
else return false
})
2022-03-30 19:20:44 +08:00
}
},
created() {
this.getTableData()
}
}
</script>
<style lang="scss" scoped>
.AppDeploy {
height: 100%;
2022-04-01 16:09:49 +08:00
::v-deep.textRight {
direction: rtl;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
2022-03-30 19:20:44 +08:00
}
</style>