diff --git a/src/views/notice/Template/Detail/components/Attachments.vue b/src/views/notice/Template/Detail/components/Attachments.vue index a3dbe211..25dafe88 100644 --- a/src/views/notice/Template/Detail/components/Attachments.vue +++ b/src/views/notice/Template/Detail/components/Attachments.vue @@ -1,4 +1,4 @@ - + - + { - if (info.file.status === 'done') { - const result = info.file.response?.result; - console.log('result: ', result); - } -}; +// const fileList = computed({ +// get: () => props.attachments.map((m) => ({ id: fileId(), ...m })), +// set: (val) => +// emit( +// 'update:attachments', +// val.map(({ name, location }) => ({ name, location })), +// ), +// }); const fileList = ref([]); + watch( () => props.attachments, (val) => { - fileList.value = val; + fileList.value = val.map((m) => ({ + id: fileId(), + ...m, + })); }, { deep: true }, ); -const handleDelete = (id: number) => { - const idx = fileList.value.findIndex((f) => f.id === id); - fileList.value.splice(idx, 1); - emit('update:attachments', fileList.value); +const handleChange = (info: UploadChangeParam, id: string | undefined) => { + if (info.file.status === 'done') { + const targetFileIdx = fileList.value.findIndex((f) => f.id === id); + fileList.value[targetFileIdx].name = info.file.name; + fileList.value[targetFileIdx].location = info.file.response?.result; + emit( + 'update:attachments', + fileList.value.map(({ name, location }) => ({ name, location })), + ); + } }; + +/** + * 删除附件 + * @param id + */ +const handleDelete = (id: string | undefined) => { + const idx = fileList.value.findIndex((f) => f.id === id); + + fileList.value.splice(idx, 1); +}; + +/** + * 添加附件 + */ const handleAdd = () => { fileList.value.push({ - id: fileList.value.length, + id: fileId(), name: '', location: '', }); - emit('update:attachments', fileList.value); }; + +/** + * 附件标识 + */ +const fileId = () => String(new Date().getTime() + Math.random() * 9);