2020-10-29 19:11:46 +08:00
|
|
|
<template>
|
2021-04-07 09:58:34 +08:00
|
|
|
<div :class="['delete-button',(deleteObjs.length<1?'':'delete-button-light')]">
|
2021-05-14 17:19:21 +08:00
|
|
|
<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">
|
|
|
|
|
<span><i class="nz-icon nz-icon-delete" ></i></span>
|
|
|
|
|
</button>
|
2021-05-18 15:06:37 +08:00
|
|
|
<div v-if="this.type === 'link'" :id="id" :class="{'nz-btn-disabled' : deleteObjs.length<1}" @click="batchDelete">
|
2021-05-14 17:19:21 +08:00
|
|
|
<span><i class="nz-icon nz-icon-delete" ></i>{{title}}</span>
|
|
|
|
|
</div>
|
2021-04-07 09:58:34 +08:00
|
|
|
</div>
|
2020-10-29 19:11:46 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-03-19 18:52:19 +08:00
|
|
|
export default {
|
|
|
|
|
name: 'deleteButton',
|
|
|
|
|
props: {
|
|
|
|
|
filterFunction: Function,
|
|
|
|
|
deleteObjs: Array,
|
|
|
|
|
api: String,
|
|
|
|
|
clickFunction: Function,
|
2021-05-14 17:19:21 +08:00
|
|
|
id: String,
|
|
|
|
|
type: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: 'button'
|
|
|
|
|
},
|
|
|
|
|
title: {
|
|
|
|
|
type: String
|
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
batchDelete: function () {
|
|
|
|
|
if (this.deleteObjs.length < 1) return
|
|
|
|
|
if (this.clickFunction) {
|
|
|
|
|
this.clickFunction()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.$confirm(this.$t('tip.confirmBatchDelete', [this.deleteObjs.length]), {
|
|
|
|
|
confirmButtonText: this.$t('tip.yes'),
|
|
|
|
|
cancelButtonText: this.$t('tip.no'),
|
|
|
|
|
type: 'warning'
|
|
|
|
|
}).then(() => {
|
|
|
|
|
this.$emit('before')
|
|
|
|
|
const params = this.filterParam()
|
|
|
|
|
this.$delete(this.api + params).then(response => {
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.deleteSuccess') })
|
|
|
|
|
this.$emit('after')
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error(response.msg)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
2020-10-29 19:11:46 +08:00
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
filterParam: function () {
|
|
|
|
|
let filterFunction = this.filterFunction
|
|
|
|
|
if (!filterFunction) {
|
|
|
|
|
filterFunction = (arr) => { return '?ids=' + arr.map(t => t.id).join(',') }
|
|
|
|
|
}
|
2020-10-29 19:11:46 +08:00
|
|
|
|
2021-03-19 18:52:19 +08:00
|
|
|
return filterFunction(this.deleteObjs)
|
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>
|