|
7 | 7 | <Tooltip placement="bottom" v-if="showPreview"> |
8 | 8 | <template #title> |
9 | 9 | {{ t('component.upload.uploaded') }} |
10 | | - <template v-if="fileListRef.length"> |
11 | | - {{ fileListRef.length }} |
| 10 | + <template v-if="fileList.length"> |
| 11 | + {{ fileList.length }} |
12 | 12 | </template> |
13 | 13 | </template> |
14 | 14 | <a-button @click="openPreviewModal"> |
15 | 15 | <Icon icon="bi:eye" /> |
16 | | - <template v-if="fileListRef.length && showPreviewNumber"> |
17 | | - {{ fileListRef.length }} |
| 16 | + <template v-if="fileList.length && showPreviewNumber"> |
| 17 | + {{ fileList.length }} |
18 | 18 | </template> |
19 | 19 | </a-button> |
20 | 20 | </Tooltip> |
21 | 21 | </a-button-group> |
22 | 22 |
|
23 | 23 | <UploadModal |
24 | 24 | v-bind="bindValue" |
25 | | - :previewFileList="fileListRef" |
| 25 | + :previewFileList="fileList" |
26 | 26 | @register="registerUploadModal" |
27 | 27 | @change="handleChange" |
| 28 | + @delete="handleDelete" |
28 | 29 | /> |
29 | 30 |
|
30 | 31 | <UploadPreviewModal |
31 | | - :value="fileListRef" |
| 32 | + :value="fileList" |
32 | 33 | @register="registerPreviewModal" |
33 | 34 | @list-change="handlePreviewChange" |
34 | 35 | /> |
35 | 36 | </div> |
36 | 37 | </template> |
37 | 38 | <script lang="ts"> |
38 | 39 | import { defineComponent, ref, watch, unref, computed } from 'vue'; |
39 | | -
|
40 | 40 | import UploadModal from './UploadModal.vue'; |
41 | 41 | import UploadPreviewModal from './UploadPreviewModal.vue'; |
42 | | - import Icon from '/@/components/Icon'; |
| 42 | + import { Icon } from '/@/components/Icon'; |
43 | 43 | import { Tooltip } from 'ant-design-vue'; |
44 | | -
|
45 | 44 | import { useModal } from '/@/components/Modal'; |
46 | | -
|
47 | 45 | import { uploadContainerProps } from './props'; |
48 | 46 | import { omit } from 'lodash-es'; |
49 | 47 | import { useI18n } from '/@/hooks/web/useI18n'; |
|
52 | 50 | name: 'BasicUpload', |
53 | 51 | components: { UploadModal, UploadPreviewModal, Icon, Tooltip }, |
54 | 52 | props: uploadContainerProps, |
55 | | - emits: ['change'], |
| 53 | + emits: ['change', 'delete'], |
56 | 54 |
|
57 | 55 | setup(props, { emit, attrs }) { |
58 | 56 | const { t } = useI18n(); |
|
62 | 60 | // 预览modal |
63 | 61 | const [registerPreviewModal, { openModal: openPreviewModal }] = useModal(); |
64 | 62 |
|
65 | | - const fileListRef = ref<string[]>([]); |
| 63 | + const fileList = ref<string[]>([]); |
66 | 64 |
|
67 | 65 | const showPreview = computed(() => { |
68 | 66 | const { emptyHidePreview } = props; |
69 | 67 | if (!emptyHidePreview) return true; |
70 | | - return emptyHidePreview ? fileListRef.value.length > 0 : true; |
| 68 | + return emptyHidePreview ? fileList.value.length > 0 : true; |
71 | 69 | }); |
72 | 70 |
|
73 | 71 | const bindValue = computed(() => { |
|
78 | 76 | watch( |
79 | 77 | () => props.value, |
80 | 78 | (value = []) => { |
81 | | - fileListRef.value = value; |
| 79 | + fileList.value = value; |
82 | 80 | }, |
83 | 81 | { immediate: true } |
84 | 82 | ); |
85 | 83 |
|
86 | 84 | // 上传modal保存操作 |
87 | 85 | function handleChange(urls: string[]) { |
88 | | - fileListRef.value = [...unref(fileListRef), ...(urls || [])]; |
89 | | - emit('change', fileListRef.value); |
| 86 | + fileList.value = [...unref(fileList), ...(urls || [])]; |
| 87 | + emit('change', fileList.value); |
90 | 88 | } |
91 | 89 |
|
92 | 90 | // 预览modal保存操作 |
93 | 91 | function handlePreviewChange(urls: string[]) { |
94 | | - fileListRef.value = [...(urls || [])]; |
95 | | - emit('change', fileListRef.value); |
| 92 | + fileList.value = [...(urls || [])]; |
| 93 | + emit('change', fileList.value); |
| 94 | + } |
| 95 | +
|
| 96 | + function handleDelete(record: Recordable) { |
| 97 | + emit('delete', record); |
96 | 98 | } |
97 | 99 |
|
98 | 100 | return { |
|
102 | 104 | handlePreviewChange, |
103 | 105 | registerPreviewModal, |
104 | 106 | openPreviewModal, |
105 | | - fileListRef, |
| 107 | + fileList, |
106 | 108 | showPreview, |
107 | 109 | bindValue, |
| 110 | + handleDelete, |
108 | 111 | t, |
109 | 112 | }; |
110 | 113 | }, |
|
0 commit comments