Commit eade9f0d authored by 智勇's avatar 智勇

编辑删除模板

parent 3b6534e0
......@@ -32,6 +32,22 @@ export function createEnvTemplate(data) {
})
}
export function saveEnvTemplate(data) {
return request({
url: '/envTemplate/save',
method: 'post',
data
})
}
export function deleteEnvTemplate(query) {
return request({
url: '/envTemplate/delete',
method: 'get',
params: query
})
}
export function createEnv(data) {
return request({
url: '/env/create',
......
......@@ -23,7 +23,7 @@
<el-form-item v-for="(ns, index) in repoNamespaces" :label="ns.type | upper" :key="index">
<el-card>
<el-button
v-loading="listLoading"
v-loading="loading"
v-for="item in ns.repos"
:key="item.domain"
:type="dependant[ns.type] && dependant[ns.type].find(sys => sys.appname === item.appname) ? 'success' : ''"
......
......@@ -13,7 +13,7 @@
<el-card>
<el-button
v-for="item in ns.repos"
:key="item.domain"
:key="item.appname"
:type="dependant[ns.type] && dependant[ns.type].find(sys => sys.appname === item.appname) ? 'success' : ''"
style="margin:3px"
@click="selectSystem(item, ns.type)">
......@@ -21,13 +21,17 @@
</el-button>
</el-card>
</el-form-item>
</el-form>
<el-button v-permission="['admin']" :disabled="loading" style="margin-right:40px;margin-bottom:40px;float:right" type="primary" @click="createData()">{{ $t('table.confirm') }}</el-button>
</el-form >
<div style="float:right">
<el-button v-permission="['admin']" :disabled="name.length === 0" style="margin-right:10px;margin-bottom:40px;" type="primary" @click="createData()">新建</el-button>
<el-button v-permission="['admin']" :disabled="!currentTemplateObj.base" style="margin-right:10px;margin-bottom:40px;" type="primary" @click="saveData()">保存</el-button>
<el-button v-permission="['admin']" :disabled="!currentTemplateObj.base" style="margin-right:40px;margin-bottom:40px;" type="danger" @click="deleteData()">删除</el-button>
</div>
</div>
</template>
<script>
import { getAllRepos, getAllEnvTemplate, createEnvTemplate } from '@/api/docker'
import { getAllRepos, getAllEnvTemplate, createEnvTemplate, saveEnvTemplate, deleteEnvTemplate } from '@/api/docker'
import permission from '@/directive/permission/index.js' // 权限判断指令
export default {
......@@ -47,6 +51,7 @@ export default {
dependant: {},
repoNamespaces: [],
currentTemplate: '',
currentTemplateObj: {},
templates: {},
loading: true
}
......@@ -84,15 +89,15 @@ export default {
useTemplate() {
const vm = this
const t = this.templates.find(item => item.name === this.currentTemplate)
this.currentTemplateObj = this.templates.find(item => item.name === this.currentTemplate)
// 清空所有选择
vm.$set(this, 'dependant', {})
// 遍历设置
const keys = Object.keys(t)
const keys = Object.keys(this.currentTemplateObj)
keys.forEach(key => {
if (key !== 'name' && key !== '_id') {
t[key].forEach(repo => {
this.currentTemplateObj[key].forEach(repo => {
vm.selectSystem(repo, key)
})
}
......@@ -111,6 +116,42 @@ export default {
type: 'success',
duration: 1000
})
this.getAllEnvTemplate()
})
},
saveData() {
const param = {
name: this.currentTemplateObj.name,
_id: this.currentTemplateObj._id,
...this.dependant
}
saveEnvTemplate(param).then(res => {
// todo: 异常在http服务统一处理
this.$message({
message: res.data || '环境模板保存成功',
type: 'success',
duration: 1000
})
this.getAllEnvTemplate()
})
},
deleteData() {
const vm = this
const param = {
_id: this.currentTemplateObj._id
}
deleteEnvTemplate(param).then(res => {
// todo: 异常在http服务统一处理
this.$message({
message: '环境模板删除成功',
type: 'success',
duration: 1000
})
this.getAllEnvTemplate()
this.currentTemplate = ''
vm.$set(this, 'dependant', {})
})
}
}
......
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