Skip to content

Commit

Permalink
feat(basic-upload): add preview-delete event
Browse files Browse the repository at this point in the history
添加预览Modal中删除文件的事件

close: #835
  • Loading branch information
mynetfan committed Jun 30, 2021
1 parent 6f845b5 commit 49e72a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/components/Upload/src/BasicUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
:value="fileList"
@register="registerPreviewModal"
@list-change="handlePreviewChange"
@delete="handlePreviewDelete"
/>
</div>
</template>
Expand All @@ -50,7 +51,7 @@
name: 'BasicUpload',
components: { UploadModal, UploadPreviewModal, Icon, Tooltip },
props: uploadContainerProps,
emits: ['change', 'delete'],
emits: ['change', 'delete', 'preview-delete'],
setup(props, { emit, attrs }) {
const { t } = useI18n();
Expand Down Expand Up @@ -97,6 +98,10 @@
emit('delete', record);
}
function handlePreviewDelete(url: string) {
emit('preview-delete', url);
}
return {
registerUploadModal,
openUploadModal,
Expand All @@ -108,6 +113,7 @@
showPreview,
bindValue,
handleDelete,
handlePreviewDelete,
t,
};
},
Expand Down
5 changes: 3 additions & 2 deletions src/components/Upload/src/UploadPreviewModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
export default defineComponent({
components: { BasicModal, FileList },
props: previewProps,
emits: ['list-change', 'register'],
emits: ['list-change', 'register', 'delete'],
setup(props, { emit }) {
const [register, { closeModal }] = useModalInner();
const { t } = useI18n();
Expand All @@ -50,7 +50,8 @@
function handleRemove(record: PreviewFileItem) {
const index = fileListRef.value.findIndex((item) => item.url === record.url);
if (index !== -1) {
fileListRef.value.splice(index, 1);
const removed = fileListRef.value.splice(index, 1);
emit('delete', removed[0].url);
emit(
'list-change',
fileListRef.value.map((item) => item.url)
Expand Down

0 comments on commit 49e72a8

Please sign in to comment.