mirror of https://github.com/halo-dev/halo-admin
refactor: optimize attachment batch deletion logic
parent
83a7d07f5f
commit
b5ff5e437c
|
@ -41,7 +41,7 @@
|
||||||
<div class="table-operator" style="margin-bottom: 0;">
|
<div class="table-operator" style="margin-bottom: 0;">
|
||||||
<a-button type="primary" icon="cloud-upload" @click="() => (uploadVisible = true)">上传</a-button>
|
<a-button type="primary" icon="cloud-upload" @click="() => (uploadVisible = true)">上传</a-button>
|
||||||
<a-button type="primary" v-show="!supportMultipleSelection" @click="handleMultipleSelection">
|
<a-button type="primary" v-show="!supportMultipleSelection" @click="handleMultipleSelection">
|
||||||
批量选择
|
批量操作
|
||||||
</a-button>
|
</a-button>
|
||||||
<a-button type="primary" v-show="supportMultipleSelection" @click="handleDeleteAttachmentInBatch">
|
<a-button type="primary" v-show="supportMultipleSelection" @click="handleDeleteAttachmentInBatch">
|
||||||
删除
|
删除
|
||||||
|
@ -69,6 +69,8 @@
|
||||||
</a-card-meta>
|
</a-card-meta>
|
||||||
<a-checkbox
|
<a-checkbox
|
||||||
class="select-attachment-checkbox"
|
class="select-attachment-checkbox"
|
||||||
|
:style="getCheckStatus(item.id) ? selectedAttachmentStyle : ''"
|
||||||
|
:checked="getCheckStatus(item.id)"
|
||||||
@click="handleAttachmentSelectionChanged($event, item)"
|
@click="handleAttachmentSelectionChanged($event, item)"
|
||||||
v-show="supportMultipleSelection"
|
v-show="supportMultipleSelection"
|
||||||
></a-checkbox>
|
></a-checkbox>
|
||||||
|
@ -121,6 +123,7 @@ export default {
|
||||||
listLoading: true,
|
listLoading: true,
|
||||||
uploadVisible: false,
|
uploadVisible: false,
|
||||||
supportMultipleSelection: false,
|
supportMultipleSelection: false,
|
||||||
|
selectedAttachmentCheckbox: {},
|
||||||
batchSelectedAttachments: [],
|
batchSelectedAttachments: [],
|
||||||
selectAttachment: {},
|
selectAttachment: {},
|
||||||
attachments: [],
|
attachments: [],
|
||||||
|
@ -149,6 +152,11 @@ export default {
|
||||||
attachment.typeProperty = this.attachmentType[attachment.type]
|
attachment.typeProperty = this.attachmentType[attachment.type]
|
||||||
return attachment
|
return attachment
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
selectedAttachmentStyle() {
|
||||||
|
return {
|
||||||
|
border: `2px solid ${this.color()}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
@ -230,39 +238,50 @@ export default {
|
||||||
// 没有获取到文件返回false
|
// 没有获取到文件返回false
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
|
getCheckStatus(key) {
|
||||||
|
return this.selectedAttachmentCheckbox[key] || false
|
||||||
|
},
|
||||||
handleMultipleSelection() {
|
handleMultipleSelection() {
|
||||||
this.supportMultipleSelection = true
|
this.supportMultipleSelection = true
|
||||||
// 不允许附件详情抽屉显示
|
// 不允许附件详情抽屉显示
|
||||||
this.drawerVisible = false
|
this.drawerVisible = false
|
||||||
|
this.attachments.forEach(item => {
|
||||||
|
this.$set(this.selectedAttachmentCheckbox, item.id, false)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
handleCancelMultipleSelection() {
|
handleCancelMultipleSelection() {
|
||||||
this.supportMultipleSelection = false
|
this.supportMultipleSelection = false
|
||||||
this.drawerVisible = false
|
this.drawerVisible = false
|
||||||
// TODO 待改进
|
this.batchSelectedAttachments = []
|
||||||
this.$router.go(0)
|
for (var key in this.selectedCheckbox) {
|
||||||
|
this.$set(this.selectedAttachmentCheckbox, key, false)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
handleAttachmentSelectionChanged(e, item) {
|
handleAttachmentSelectionChanged(e, item) {
|
||||||
var isChecked = e.target.checked || false
|
var isChecked = e.target.checked || false
|
||||||
var $parentNode = e.currentTarget.parentNode.parentNode || {}
|
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
|
this.$set(this.selectedAttachmentCheckbox, item.id, true)
|
||||||
this.batchSelectedAttachments.push(item.id)
|
this.batchSelectedAttachments.push(item.id)
|
||||||
this.$set($parentNode.style, 'border', `2px solid ${this.color()}`)
|
|
||||||
} else {
|
} else {
|
||||||
|
this.$set(this.selectedAttachmentCheckbox, item.id, false)
|
||||||
// 从选中id集合中删除id
|
// 从选中id集合中删除id
|
||||||
var index = this.batchSelectedAttachments.indexOf(item.id)
|
var index = this.batchSelectedAttachments.indexOf(item.id)
|
||||||
this.batchSelectedAttachments.splice(index, 1)
|
this.batchSelectedAttachments.splice(index, 1)
|
||||||
// 取消边框
|
|
||||||
this.$set($parentNode.style, 'border', '')
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleDeleteAttachmentInBatch() {
|
handleDeleteAttachmentInBatch() {
|
||||||
var that = this
|
var that = this
|
||||||
|
if (this.batchSelectedAttachments.length <= 0) {
|
||||||
|
this.$message.success('你还未选择任何附件,先选择一个吧')
|
||||||
|
return
|
||||||
|
}
|
||||||
this.$confirm({
|
this.$confirm({
|
||||||
title: '确定要批量删除选中的附件吗?',
|
title: '确定要批量删除选中的附件吗?',
|
||||||
content: '一旦删除不可恢复,请谨慎操作',
|
content: '一旦删除不可恢复,请谨慎操作',
|
||||||
onOk() {
|
onOk() {
|
||||||
attachmentApi.deleteInBatch(that.batchSelectedAttachments).then(res => {
|
attachmentApi.deleteInBatch(that.batchSelectedAttachments).then(res => {
|
||||||
that.handleCancelMultipleSelection()
|
that.handleCancelMultipleSelection()
|
||||||
|
that.loadAttachments()
|
||||||
that.$message.success('删除成功')
|
that.$message.success('删除成功')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue