feat:supports mass deletion of attachments

pull/3445/head
guqing 2019-12-13 15:35:17 +08:00
parent a50eb67e4c
commit 655e867e19
2 changed files with 112 additions and 95 deletions

View File

@ -27,6 +27,17 @@ attachmentApi.delete = attachmentId => {
}) })
} }
attachmentApi.deleteInBatch = attachmentIds => {
return service({
url: `${baseUrl}`,
method: 'delete',
data: attachmentIds,
headers: {
'Content-Type': 'application/json;charset=UTF-8'
}
})
}
attachmentApi.update = (attachmentId, attachment) => { attachmentApi.update = (attachmentId, attachment) => {
return service({ return service({
url: `${baseUrl}/${attachmentId}`, url: `${baseUrl}/${attachmentId}`,

View File

@ -1,87 +1,54 @@
<template> <template>
<page-view> <page-view>
<a-row <a-row :gutter="12" type="flex" align="middle">
:gutter="12" <a-col :span="24" style="padding-bottom: 12px;">
type="flex" <a-card :bordered="false" :bodyStyle="{ padding: '16px' }">
align="middle"
>
<a-col
:span="24"
style="padding-bottom: 12px;"
>
<a-card
:bordered="false"
:bodyStyle="{ padding: '16px' }"
>
<div class="table-page-search-wrapper"> <div class="table-page-search-wrapper">
<a-form layout="inline"> <a-form layout="inline">
<a-row :gutter="48"> <a-row :gutter="48">
<a-col <a-col :md="6" :sm="24">
:md="6"
:sm="24"
>
<a-form-item label="关键词"> <a-form-item label="关键词">
<a-input v-model="queryParam.keyword" @keyup.enter="handleQuery()"/> <a-input v-model="queryParam.keyword" @keyup.enter="handleQuery()" />
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col <a-col :md="6" :sm="24">
:md="6"
:sm="24"
>
<a-form-item label="存储位置"> <a-form-item label="存储位置">
<a-select <a-select v-model="queryParam.attachmentType" @change="handleQuery()">
v-model="queryParam.attachmentType" <a-select-option v-for="item in Object.keys(attachmentType)" :key="item" :value="item">{{
@change="handleQuery()" attachmentType[item].text
> }}</a-select-option>
<a-select-option
v-for="item in Object.keys(attachmentType)"
:key="item"
:value="item"
>{{ attachmentType[item].text }}</a-select-option>
</a-select> </a-select>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col <a-col :md="6" :sm="24">
:md="6"
:sm="24"
>
<a-form-item label="文件类型"> <a-form-item label="文件类型">
<a-select <a-select v-model="queryParam.mediaType" @change="handleQuery()">
v-model="queryParam.mediaType" <a-select-option v-for="(item, index) in mediaTypes" :key="index" :value="item">{{
@change="handleQuery()" item
> }}</a-select-option>
<a-select-option
v-for="(item,index) in mediaTypes"
:key="index"
:value="item"
>{{ item }}</a-select-option>
</a-select> </a-select>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col <a-col :md="6" :sm="24">
:md="6"
:sm="24"
>
<span class="table-page-search-submitButtons"> <span class="table-page-search-submitButtons">
<a-button <a-button type="primary" @click="handleQuery()"></a-button>
type="primary" <a-button style="margin-left: 8px;" @click="handleResetParam()"></a-button>
@click="handleQuery()"
>查询</a-button>
<a-button
style="margin-left: 8px;"
@click="handleResetParam()"
>重置</a-button>
</span> </span>
</a-col> </a-col>
</a-row> </a-row>
</a-form> </a-form>
</div> </div>
<div class="table-operator" style="margin-bottom: 0;"> <div class="table-operator" style="margin-bottom: 0;">
<a-button <a-button type="primary" icon="cloud-upload" @click="() => (uploadVisible = true)">上传</a-button>
type="primary" <a-button type="primary" v-show="!supportMultipleSelection" @click="handleMultipleSelection">
icon="cloud-upload" 批量选择
@click="()=>this.uploadVisible = true" </a-button>
>上传</a-button> <a-button type="primary" v-show="supportMultipleSelection" @click="handleDeleteAttachmentInBatch">
删除
</a-button>
<a-button type="primary" v-show="supportMultipleSelection" @click="handleCancelMultipleSelection">
取消
</a-button>
</div> </div>
</a-card> </a-card>
</a-col> </a-col>
@ -91,31 +58,20 @@
:dataSource="formattedDatas" :dataSource="formattedDatas"
:loading="listLoading" :loading="listLoading"
> >
<a-list-item <a-list-item slot="renderItem" slot-scope="item, index" :key="index">
slot="renderItem" <a-card :bodyStyle="{ padding: 0 }" hoverable @click="handleShowDetailDrawer(item)">
slot-scope="item, index"
:key="index"
>
<a-card
:bodyStyle="{ padding: 0 }"
hoverable
@click="handleShowDetailDrawer(item)"
>
<div class="attach-thumb"> <div class="attach-thumb">
<span v-show="!handleJudgeMediaType(item)"></span> <span v-show="!handleJudgeMediaType(item)"></span>
<img <img :src="item.thumbPath" v-show="handleJudgeMediaType(item)" loading="lazy" />
:src="item.thumbPath"
v-show="handleJudgeMediaType(item)"
loading="lazy"
>
</div> </div>
<a-card-meta style="padding: 0.8rem;"> <a-card-meta style="padding: 0.8rem;">
<ellipsis <ellipsis :length="isMobile() ? 12 : 16" tooltip slot="description">{{ item.name }}</ellipsis>
:length="isMobile()?12:16"
tooltip
slot="description"
>{{ item.name }}</ellipsis>
</a-card-meta> </a-card-meta>
<a-checkbox
class="select-attachment-checkbox"
@click="handleAttachmentSelectionChanged($event, item)"
v-show="supportMultipleSelection"
></a-checkbox>
</a-card> </a-card>
</a-list-item> </a-list-item>
</a-list> </a-list>
@ -127,30 +83,21 @@
:current="pagination.page" :current="pagination.page"
:total="pagination.total" :total="pagination.total"
:defaultPageSize="pagination.size" :defaultPageSize="pagination.size"
:pageSizeOptions="['18', '36', '54','72','90','108']" :pageSizeOptions="['18', '36', '54', '72', '90', '108']"
showSizeChanger showSizeChanger
@change="handlePaginationChange" @change="handlePaginationChange"
@showSizeChange="handlePaginationChange" @showSizeChange="handlePaginationChange"
/> />
</div> </div>
<a-modal <a-modal title="上传附件" v-model="uploadVisible" :footer="null" :afterClose="onUploadClose" destroyOnClose>
title="上传附件" <FilePondUpload ref="upload" :uploadHandler="uploadHandler"></FilePondUpload>
v-model="uploadVisible"
:footer="null"
:afterClose="onUploadClose"
destroyOnClose
>
<FilePondUpload
ref="upload"
:uploadHandler="uploadHandler"
></FilePondUpload>
</a-modal> </a-modal>
<AttachmentDetailDrawer <AttachmentDetailDrawer
v-model="drawerVisible" v-model="drawerVisible"
v-if="selectAttachment" v-if="selectAttachment"
:attachment="selectAttachment" :attachment="selectAttachment"
:addToPhoto="true" :addToPhoto="true"
@delete="()=>this.loadAttachments()" @delete="() => this.loadAttachments()"
/> />
</page-view> </page-view>
</template> </template>
@ -160,6 +107,7 @@ import { mixin, mixinDevice } from '@/utils/mixin.js'
import { PageView } from '@/layouts' import { PageView } from '@/layouts'
import AttachmentDetailDrawer from './components/AttachmentDetailDrawer' import AttachmentDetailDrawer from './components/AttachmentDetailDrawer'
import attachmentApi from '@/api/attachment' import attachmentApi from '@/api/attachment'
import { mapGetters } from 'vuex'
export default { export default {
components: { components: {
@ -172,6 +120,8 @@ export default {
attachmentType: attachmentApi.type, attachmentType: attachmentApi.type,
listLoading: true, listLoading: true,
uploadVisible: false, uploadVisible: false,
supportMultipleSelection: false,
batchSelectedAttachments: [],
selectAttachment: {}, selectAttachment: {},
attachments: [], attachments: [],
mediaTypes: [], mediaTypes: [],
@ -217,6 +167,7 @@ export default {
next() next()
}, },
methods: { methods: {
...mapGetters(['color']),
loadAttachments() { loadAttachments() {
this.queryParam.page = this.pagination.page - 1 this.queryParam.page = this.pagination.page - 1
this.queryParam.size = this.pagination.size this.queryParam.size = this.pagination.size
@ -235,7 +186,11 @@ export default {
}, },
handleShowDetailDrawer(attachment) { handleShowDetailDrawer(attachment) {
this.selectAttachment = attachment this.selectAttachment = attachment
this.drawerVisible = true if (this.supportMultipleSelection) {
this.drawerVisible = false
} else {
this.drawerVisible = true
}
}, },
handlePaginationChange(page, size) { handlePaginationChange(page, size) {
this.$log.debug(`Current: ${page}, PageSize: ${size}`) this.$log.debug(`Current: ${page}, PageSize: ${size}`)
@ -274,7 +229,58 @@ export default {
} }
// false // false
return false return false
},
handleMultipleSelection() {
this.supportMultipleSelection = true
//
this.drawerVisible = false
},
handleCancelMultipleSelection() {
this.supportMultipleSelection = false
this.drawerVisible = false
// TODO
this.$router.go(0)
},
handleAttachmentSelectionChanged(e, item) {
var isChecked = e.target.checked || false
var $parentNode = e.currentTarget.parentNode.parentNode || {}
if (isChecked) {
this.batchSelectedAttachments.push(item.id)
this.$set($parentNode.style, 'border', `2px solid ${this.color()}`)
} else {
// idid
var index = this.batchSelectedAttachments.indexOf(item.id)
this.batchSelectedAttachments.splice(index, 1)
//
this.$set($parentNode.style, 'border', '')
}
},
handleDeleteAttachmentInBatch() {
var that = this
this.$confirm({
title: '确定要批量删除选中的附件吗?',
content: '一旦删除不可恢复,请谨慎操作',
onOk() {
attachmentApi.deleteInBatch(that.batchSelectedAttachments).then(res => {
that.handleCancelMultipleSelection()
that.$message.success('删除成功')
})
},
onCancel() { }
})
} }
} }
} }
</script> </script>
<style lang="less" scoped>
.select-attachment-checkbox {
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0;
bottom: 0;
left: 0;
z-index: 10;
}
</style>