refactor(notification): 优化公告编辑组件中的附件处理逻辑

-将 formData 中的 attachments 属性改为 attachmentIds,以更准确地表示附件 ID 列表
- 在编辑公告时,将附件列表转换为附件 ID 列表
- 更新附件上传和删除逻辑,以适应新的附件 ID 列表结构
- 移除 BulletinRecord接口中的 closeTime 属性,简化数据结构
This commit is contained in:
Kven 2025-01-18 19:55:31 +08:00
parent c4e5dbbe9f
commit dfd9d165ca
2 changed files with 14 additions and 6 deletions

View File

@ -26,7 +26,6 @@ export interface BulletinRecord extends BulletinCreateRecord {
publishUserId: number;
publishTime: string;
closeUserId: number;
closeTime: string;
attachments?: AttachmentRecord[];
}

View File

@ -64,7 +64,7 @@
>
<!-- v-if="isCreate"-->
<a-upload
v-model="formData.attachments"
v-model="formData.attachmentIds"
show-file-list
:file-list="fileList"
:custom-request="customRequest"
@ -130,6 +130,7 @@ const formData = ref<BulletinRecord>({
id: -1,
title: '',
top: false,
attachmentIds: [],
content: '',
remark: '',
createTime: '',
@ -140,7 +141,6 @@ const formData = ref<BulletinRecord>({
publishUserId: 0,
publishTime: '',
closeUserId: 0,
closeTime: '',
attachments: [],
});
@ -188,6 +188,9 @@ const handleClick = () => {
if(!props.isCreate){
bulletinStore.queryBulletinDetail(props.id).then((res: any) => {
formData.value = res.data;
formData.value.attachmentIds = res.data.attachments?.map((item: any) => {
return item.id;
});
})
}
};
@ -243,7 +246,9 @@ const customRequest = async (option: any) => {
const res = await bulletinStore.addAttachments(formDataFile);
if (res.status === 200) {
onSuccess(res.data);
formData.value.attachments?.push(res.data);
formData.value.attachmentIds?.push(res.data.id);
console.log(res.data.id);
console.log(formData.value);
} else {
onError(res.data);
}
@ -251,9 +256,13 @@ const customRequest = async (option: any) => {
//
const beforeRemove = async (file: any) => {
if(!file.uid){
const res = await bulletinStore.deleteAttachment(file.response.id);
return res.status === 200;
}
const res = await bulletinStore.deleteAttachment(file.uid);
return res.status === 200;
}
//
onBeforeUnmount(() => {