2020-10-29 19:11:46 +08:00
|
|
|
<template>
|
2022-08-30 14:43:05 +08:00
|
|
|
<div>
|
|
|
|
|
<div :class="['delete-button',(deleteObjs.length<1?'':'delete-button-light')]">
|
|
|
|
|
<button v-if="this.type === 'button'" :id="id" :class="{'nz-btn-disabled' : deleteObjs.length<1}" class="top-tool-btn top-tool-btn--delete" @click="batchDelete" :title="$t('overall.delete')">
|
|
|
|
|
<span><i class="nz-icon nz-icon-delete" ></i></span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2022-10-14 15:43:11 +08:00
|
|
|
<button v-if="this.type === 'btn'" class="table-operation-item delete-button" :id="id" @click="batchDelete" :title="$t('overall.delete')"><i class="nz-icon nz-icon-delete"></i></button>
|
2022-08-30 14:43:05 +08:00
|
|
|
<div v-if="this.type === 'link'" :id="id" @click="batchDelete" :title="$t('overall.delete')">
|
2021-05-14 17:19:21 +08:00
|
|
|
<span><i class="nz-icon nz-icon-delete" ></i>{{title}}</span>
|
|
|
|
|
</div>
|
2022-08-26 15:56:19 +08:00
|
|
|
<el-dialog
|
|
|
|
|
ref="batchDeleteDialog"
|
|
|
|
|
id="batch-delete-dialog"
|
|
|
|
|
class="batch-delete-dialog"
|
2022-10-18 15:17:00 +08:00
|
|
|
:title="$t('el.table.confirmFilter')"
|
2022-08-26 15:56:19 +08:00
|
|
|
v-if="dialogVisible"
|
|
|
|
|
:visible.sync="dialogVisible"
|
|
|
|
|
@close='handleClose'
|
2022-09-26 16:22:34 +08:00
|
|
|
width="660px"
|
2022-08-26 15:56:19 +08:00
|
|
|
:modal-append-to-body="true"
|
|
|
|
|
:append-to-body="true"
|
|
|
|
|
>
|
|
|
|
|
<!-- -->
|
|
|
|
|
<div class="dialog-header" style="vertical-align:top;" v-if="prepare">
|
2022-08-29 13:46:13 +08:00
|
|
|
<i class="nz-icon nz-icon-jinggao"></i>
|
2022-10-19 16:37:21 +08:00
|
|
|
<span>{{$t('batch.prepare', { dataLength: idStr.length })}}</span>
|
2022-08-26 15:56:19 +08:00
|
|
|
</div>
|
|
|
|
|
<!-- -->
|
|
|
|
|
<div class="dialog-header" style="vertical-align:top;" v-if="process">
|
2022-08-29 13:46:13 +08:00
|
|
|
<i class="nz-icon nz-icon-import-failed1"></i>
|
|
|
|
|
<span>{{$t('batch.process', {title: $t(deleteTitle)})}}</span>
|
2022-08-26 15:56:19 +08:00
|
|
|
</div>
|
|
|
|
|
<!-- -->
|
|
|
|
|
<div class="dialog-header" style="vertical-align:top;" v-if="finish">
|
|
|
|
|
<i class="nz-icon nz-icon-import-success1"></i>
|
2022-08-29 13:46:13 +08:00
|
|
|
<span>{{$t('batch.finish', {title: $t(deleteTitle)})}}</span>
|
2022-08-26 15:56:19 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="batch-delete-tree">
|
|
|
|
|
<div class="tree-header tree-body-item">
|
|
|
|
|
<el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="checkAllChange" v-if="!finish"></el-checkbox>
|
2022-09-26 16:22:34 +08:00
|
|
|
<div class="batch-delete-item-id" v-if="idShow">ID</div>
|
2022-08-26 15:56:19 +08:00
|
|
|
<div class="batch-delete-item-name">{{$t('overall.name')}}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<el-checkbox-group v-model="idStr" @change="checkedChange">
|
|
|
|
|
<div class="tree-body">
|
|
|
|
|
<div v-for="(item,index) in deleteData" :key = 'index' class="tree-body-item">
|
|
|
|
|
<el-checkbox :key="item.id" :label="item.id" v-if="!finish"></el-checkbox>
|
|
|
|
|
<div class="batch-delete-item-id" v-if="idShow">{{item.id}}</div>
|
|
|
|
|
<div class="batch-delete-item-name" @click="showChild(item)">
|
2022-09-26 16:22:34 +08:00
|
|
|
<i class="nz-icon nz-icon-caret-right" :class="item.showChildren ? 'rotate90': '' " :style="item.relates && item.relates.length ? '': 'opacity: 0'"/>
|
2022-08-26 15:56:19 +08:00
|
|
|
<i :class="selectIcon(item.type)"/>
|
|
|
|
|
<span class="text-ellipsis batch-delete-item-text" :title="item.name">{{item.name}}</span>
|
|
|
|
|
<el-collapse-transition>
|
2022-09-26 16:22:34 +08:00
|
|
|
<div v-show="item.showChildren && item.relates.length">
|
2022-09-26 16:42:10 +08:00
|
|
|
<div v-for="(relate,i) in item.relates" :key = 'i' class="tree-body-item tree-body-children" @click="showChild(relate)" :style="i === item.relates.length-1?'margin-bottom: 0':''">
|
2022-09-26 16:22:34 +08:00
|
|
|
<i class="nz-icon nz-icon-caret-right" :class="relate.showChildren ? 'rotate90': '' " :style="relate.relates && relate.relates.length ? '' : 'opacity: 0'"/>
|
2022-08-26 15:56:19 +08:00
|
|
|
<i :class="selectIcon(relate.type)"/>
|
2022-09-02 11:11:53 +08:00
|
|
|
<span class="text-ellipsis batch-delete-item-text" :title="relate.name"> {{relate.name}}</span>
|
2022-09-26 17:18:01 +08:00
|
|
|
<div class="text-ellipsis batch-delete-item-text" :title="relate.name" v-if="relate.showChildren && relate.relates && relate.relates.length">
|
2022-09-26 16:22:34 +08:00
|
|
|
<div v-for="(cildren,j) in relate.relates" :key = 'j' class="tree-body-item tree-body-children" :style="j === relate.relates.length-1?'margin-bottom: 0':''">
|
2022-09-02 11:11:53 +08:00
|
|
|
<i :class="selectIcon(cildren.type)"/>
|
|
|
|
|
<span class="text-ellipsis batch-delete-item-text" :title="cildren.name">{{cildren.name}}</span>
|
|
|
|
|
</div>
|
2022-08-26 15:56:19 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</el-collapse-transition>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</el-checkbox-group>
|
|
|
|
|
</div>
|
|
|
|
|
<!-- 底部按钮 -->
|
|
|
|
|
<span slot="footer" class="dialog-footer right-box__footer batch-delete-footer" v-if="!finish">
|
|
|
|
|
<div>
|
|
|
|
|
<button id="batch-delete-cancel" class="footer__btn footer__btn--light" style="margin-top: 8px;" type="button" @click="dialogVisible = false">{{$t('tip.no')}}</button>
|
|
|
|
|
<button id="batch-delete-next" class="footer__btn" type="button" @click="batchDeleteYes">{{$t('tip.yes')}}</button>
|
|
|
|
|
</div>
|
2022-08-29 13:46:13 +08:00
|
|
|
<div v-if="forceDeleteShow">
|
|
|
|
|
<el-checkbox v-model="forceDelete" text-color="black" name="type" :true-label="1" :false-label="0"></el-checkbox>
|
2022-09-28 15:17:24 +08:00
|
|
|
<span class="check-title">{{$t('batch.forceDelete')}}</span>
|
2022-08-29 13:46:13 +08:00
|
|
|
</div>
|
2022-08-26 15:56:19 +08:00
|
|
|
</span>
|
|
|
|
|
</el-dialog>
|
2021-04-07 09:58:34 +08:00
|
|
|
</div>
|
2020-10-29 19:11:46 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2022-06-20 16:31:52 +08:00
|
|
|
import bus from '@/libs/bus'
|
2021-03-19 18:52:19 +08:00
|
|
|
export default {
|
|
|
|
|
name: 'deleteButton',
|
2022-08-26 15:56:19 +08:00
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
prepare: true,
|
|
|
|
|
process: false,
|
|
|
|
|
finish: false,
|
|
|
|
|
dialogVisible: false,
|
|
|
|
|
idShow: true,
|
|
|
|
|
idStr: [],
|
2022-10-14 15:43:11 +08:00
|
|
|
backupName: [],
|
2022-08-26 15:56:19 +08:00
|
|
|
deleteData: [],
|
|
|
|
|
forceDelete: 0,
|
|
|
|
|
batchDeleteObjs: [],
|
|
|
|
|
checkAll: false,
|
|
|
|
|
isIndeterminate: false
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
props: {
|
2022-10-17 11:46:41 +08:00
|
|
|
forceDeleteShow: { // 是否显示强制删除
|
2022-08-26 15:56:19 +08:00
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
filterFunction: Function,
|
2022-10-17 11:46:41 +08:00
|
|
|
deleteObjs: Array, // 删除的数组
|
|
|
|
|
api: String, // 删除的接口
|
|
|
|
|
from: String, // 通过 from 确认删除的 icon
|
2021-03-19 18:52:19 +08:00
|
|
|
clickFunction: Function,
|
2021-05-14 17:19:21 +08:00
|
|
|
id: String,
|
2022-10-17 11:46:41 +08:00
|
|
|
type: { // 删除按钮的样式 是按钮 还是文字
|
2021-05-14 17:19:21 +08:00
|
|
|
type: String,
|
|
|
|
|
default: 'button'
|
|
|
|
|
},
|
|
|
|
|
title: {
|
|
|
|
|
type: String
|
2022-08-29 13:46:13 +08:00
|
|
|
},
|
2022-10-17 11:46:41 +08:00
|
|
|
deleteTitle: { // 删除的名称
|
2022-08-29 13:46:13 +08:00
|
|
|
type: String,
|
|
|
|
|
default: 'project.topology.data'
|
2022-10-14 15:43:11 +08:00
|
|
|
},
|
2022-10-17 11:46:41 +08:00
|
|
|
single: { // 是否需要强制删除
|
2022-10-14 15:43:11 +08:00
|
|
|
type: Boolean
|
2021-05-14 17:19:21 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
},
|
2022-10-14 15:43:11 +08:00
|
|
|
inject: ['getTableData'],
|
2021-03-19 18:52:19 +08:00
|
|
|
methods: {
|
|
|
|
|
batchDelete: function () {
|
2022-10-14 15:43:11 +08:00
|
|
|
if (!this.single) {
|
|
|
|
|
this.$emit('before')
|
|
|
|
|
if (this.deleteObjs.length < 1) return
|
|
|
|
|
if (this.clickFunction) {
|
|
|
|
|
this.clickFunction()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.idShow = true
|
|
|
|
|
this.prepare = true
|
|
|
|
|
this.process = false
|
|
|
|
|
this.finish = false
|
|
|
|
|
this.forceDelete = 0
|
|
|
|
|
this.deleteData = this.$loadsh.cloneDeep(this.deleteObjs).map(item => {
|
|
|
|
|
item.type = this.from
|
|
|
|
|
return item
|
|
|
|
|
})
|
|
|
|
|
this.checkAll = true
|
|
|
|
|
this.idStr = this.deleteData.map(item => item.id)
|
|
|
|
|
this.dialogVisible = true
|
|
|
|
|
} else {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.$emit('before')
|
|
|
|
|
if (this.deleteObjs.length < 1) return
|
|
|
|
|
if (this.clickFunction) {
|
|
|
|
|
this.clickFunction()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.idShow = true
|
|
|
|
|
this.prepare = true
|
|
|
|
|
this.process = false
|
|
|
|
|
this.finish = false
|
|
|
|
|
this.forceDelete = 0
|
|
|
|
|
this.deleteData = this.$loadsh.cloneDeep(this.deleteObjs).map(item => {
|
|
|
|
|
item.type = this.from
|
|
|
|
|
return item
|
|
|
|
|
})
|
|
|
|
|
this.checkAll = true
|
|
|
|
|
this.idStr = this.deleteData.map(item => item.id)
|
|
|
|
|
if (this.from == 'backup') {
|
|
|
|
|
this.backupName = this.deleteData.map(item => item.fileName)
|
|
|
|
|
}
|
|
|
|
|
this.dialogVisible = true
|
|
|
|
|
}, 50)
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
2022-08-26 15:56:19 +08:00
|
|
|
},
|
|
|
|
|
handleClose () {
|
|
|
|
|
this.dialogVisible = false
|
|
|
|
|
if (this.finish) {
|
|
|
|
|
this.$emit('after')
|
2022-10-14 15:43:11 +08:00
|
|
|
if (this.single) {
|
|
|
|
|
this.getTableData()
|
|
|
|
|
}
|
2022-08-26 15:56:19 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
batchDeleteYes () {
|
|
|
|
|
if (!this.forceDeleteShow) {
|
|
|
|
|
this.forceDelete = 1
|
|
|
|
|
}
|
2022-10-14 15:43:11 +08:00
|
|
|
this.$delete(this.api + `?ids=${this.idStr.join(',')}&force=${this.forceDelete}` + `${this.from == 'backup' ? '&filename=' + this.backupName : ''}`).then(res => {
|
2022-08-26 15:56:19 +08:00
|
|
|
this.idShow = false
|
|
|
|
|
this.prepare = false
|
|
|
|
|
this.process = true
|
|
|
|
|
this.finish = false
|
|
|
|
|
if (res.data && res.data.list && res.code !== 200) {
|
|
|
|
|
this.deleteData = res.data.list.map(item => {
|
|
|
|
|
item.showChildren = true
|
|
|
|
|
item.relates && item.relates.forEach(relate => {
|
|
|
|
|
relate.showChildren = true
|
|
|
|
|
})
|
|
|
|
|
return item
|
|
|
|
|
})
|
|
|
|
|
} else if (res.code === 200) {
|
|
|
|
|
this.idShow = false
|
|
|
|
|
this.prepare = false
|
|
|
|
|
this.process = false
|
|
|
|
|
this.finish = true
|
2022-10-21 09:28:51 +08:00
|
|
|
this.deleteData = this.deleteData.filter(item => {
|
|
|
|
|
return this.idStr.indexOf(item.id) !== -1
|
|
|
|
|
})
|
2022-08-26 15:56:19 +08:00
|
|
|
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.deleteSuccess') })
|
|
|
|
|
// this.$emit('after')
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error(res.msg)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
showProcess (arr) {
|
|
|
|
|
this.idShow = false
|
|
|
|
|
this.prepare = false
|
|
|
|
|
this.process = true
|
|
|
|
|
this.finish = false
|
|
|
|
|
this.deleteData = arr.map(item => {
|
|
|
|
|
item.showChildren = true
|
|
|
|
|
item.relates && item.relates.forEach(relate => {
|
|
|
|
|
relate.showChildren = true
|
2021-03-19 18:52:19 +08:00
|
|
|
})
|
2022-08-26 15:56:19 +08:00
|
|
|
return item
|
|
|
|
|
})
|
|
|
|
|
this.idStr = this.deleteData.map(item => item.id)
|
|
|
|
|
this.checkAll = true
|
|
|
|
|
this.dialogVisible = true
|
|
|
|
|
},
|
|
|
|
|
checkAllChange (value) {
|
|
|
|
|
const allId = this.deleteData.map(item => {
|
|
|
|
|
return item.id
|
2021-03-19 18:52:19 +08:00
|
|
|
})
|
2022-08-26 15:56:19 +08:00
|
|
|
this.idStr = value ? allId : []
|
|
|
|
|
this.isIndeterminate = false
|
2020-10-29 19:11:46 +08:00
|
|
|
},
|
2022-08-26 15:56:19 +08:00
|
|
|
checkedChange (value) {
|
|
|
|
|
const checkedCount = value.length
|
|
|
|
|
this.checkAll = checkedCount > 0
|
|
|
|
|
this.isIndeterminate = checkedCount > 0 && checkedCount < this.deleteData.length
|
|
|
|
|
},
|
|
|
|
|
showChild (item, e) {
|
|
|
|
|
e && e.stopPropagation ? e.stopPropagation() : window.event.cancelBubble = true
|
2022-09-26 16:22:34 +08:00
|
|
|
if (item.relates && !item.relates.length) {
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-08-26 15:56:19 +08:00
|
|
|
item.showChildren = !item.showChildren
|
|
|
|
|
},
|
|
|
|
|
selectIcon (type) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case 'asset' : return 'nz-icon monitorColor nz-icon-overview-project'
|
|
|
|
|
case 'datacenter' : return 'nz-icon monitorColor nz-icon-Datacenter2'
|
2022-10-17 11:46:41 +08:00
|
|
|
case 'dc' : return 'nz-icon monitorColor nz-icon-Datacenter2'
|
2022-08-26 15:56:19 +08:00
|
|
|
case 'project' : return 'nz-icon monitorColor nz-icon-project'
|
|
|
|
|
case 'module' : return 'nz-icon monitorColor nz-icon-overview-module'
|
|
|
|
|
case 'endpoint' : return 'nz-icon monitorColor nz-icon-overview-endpoint'
|
|
|
|
|
case 'alertrule' : return 'nz-icon monitorColor nz-icon-Alertrule'
|
2022-08-30 09:33:30 +08:00
|
|
|
case 'cabinetTab' : return 'nz-icon monitorColor nz-icon-Cabinet1'
|
|
|
|
|
case 'roles' : return 'nz-icon monitorColor nz-icon-role1'
|
|
|
|
|
case 'alertSilence' : return 'nz-icon monitorColor nz-icon-a-Silencealert'
|
|
|
|
|
case 'user' : return 'nz-icon monitorColor nz-icon-user1'
|
2022-10-17 11:46:41 +08:00
|
|
|
case 'cabinet' : return 'nz-icon monitorColor nz-icon-Cabinet1'
|
|
|
|
|
case 'alertRule' : return 'nz-icon monitorColor nz-icon-Alertrule'
|
|
|
|
|
case 'alertMessage' : return 'nz-icon monitorColor nz-icon-overview-alert'
|
|
|
|
|
case 'agent' : return 'nz-icon monitorColor nz-icon-agent'
|
2022-10-17 14:17:05 +08:00
|
|
|
case 'assetMeta' : return 'nz-icon monitorColor nz-icon-label'
|
|
|
|
|
case 'model' : return 'nz-icon monitorColor nz-icon-model'
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
2022-08-29 13:46:13 +08:00
|
|
|
return ' '
|
2020-10-29 19:11:46 +08:00
|
|
|
}
|
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
2020-10-29 19:11:46 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.delete-button{
|
2021-04-13 20:33:12 +08:00
|
|
|
margin-right: 10px;
|
2020-10-30 15:16:25 +08:00
|
|
|
opacity: 0.7;
|
|
|
|
|
border-radius: 2px;
|
2020-10-29 19:11:46 +08:00
|
|
|
}
|
2020-10-30 15:16:25 +08:00
|
|
|
.delete-button-light.delete-button{
|
|
|
|
|
border-radius: 2px;
|
2021-05-18 15:06:37 +08:00
|
|
|
opacity: 1;
|
2020-10-30 15:16:25 +08:00
|
|
|
}
|
2020-10-29 19:11:46 +08:00
|
|
|
</style>
|