refactor(notification): 优化公告编辑组件中的附件处理逻辑
-将 formData 中的 attachments 属性改为 attachmentIds,以更准确地表示附件 ID 列表 - 在编辑公告时,将附件列表转换为附件 ID 列表 - 更新附件上传和删除逻辑,以适应新的附件 ID 列表结构 - 移除 BulletinRecord接口中的 closeTime 属性,简化数据结构
This commit is contained in:
parent
c4e5dbbe9f
commit
dfd9d165ca
@ -26,7 +26,6 @@ export interface BulletinRecord extends BulletinCreateRecord {
|
|||||||
publishUserId: number;
|
publishUserId: number;
|
||||||
publishTime: string;
|
publishTime: string;
|
||||||
closeUserId: number;
|
closeUserId: number;
|
||||||
closeTime: string;
|
|
||||||
attachments?: AttachmentRecord[];
|
attachments?: AttachmentRecord[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@
|
|||||||
>
|
>
|
||||||
<!-- v-if="isCreate"-->
|
<!-- v-if="isCreate"-->
|
||||||
<a-upload
|
<a-upload
|
||||||
v-model="formData.attachments"
|
v-model="formData.attachmentIds"
|
||||||
show-file-list
|
show-file-list
|
||||||
:file-list="fileList"
|
:file-list="fileList"
|
||||||
:custom-request="customRequest"
|
:custom-request="customRequest"
|
||||||
@ -103,7 +103,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import useVisible from '@/hooks/visible';
|
import useVisible from '@/hooks/visible';
|
||||||
import { computed, defineEmits, ref, shallowRef,onBeforeUnmount } from 'vue';
|
import { computed, defineEmits, ref, shallowRef,onBeforeUnmount } from 'vue';
|
||||||
import { BulletinRecord } from '@/api/bulletin-mgmt';
|
import { BulletinRecord } from '@/api/bulletin-mgmt';
|
||||||
import { FormInstance } from '@arco-design/web-vue/es/form';
|
import { FormInstance } from '@arco-design/web-vue/es/form';
|
||||||
import { Message } from '@arco-design/web-vue';
|
import { Message } from '@arco-design/web-vue';
|
||||||
import { useBulletinStore } from '@/store';
|
import { useBulletinStore } from '@/store';
|
||||||
@ -130,6 +130,7 @@ const formData = ref<BulletinRecord>({
|
|||||||
id: -1,
|
id: -1,
|
||||||
title: '',
|
title: '',
|
||||||
top: false,
|
top: false,
|
||||||
|
attachmentIds: [],
|
||||||
content: '',
|
content: '',
|
||||||
remark: '',
|
remark: '',
|
||||||
createTime: '',
|
createTime: '',
|
||||||
@ -140,7 +141,6 @@ const formData = ref<BulletinRecord>({
|
|||||||
publishUserId: 0,
|
publishUserId: 0,
|
||||||
publishTime: '',
|
publishTime: '',
|
||||||
closeUserId: 0,
|
closeUserId: 0,
|
||||||
closeTime: '',
|
|
||||||
attachments: [],
|
attachments: [],
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -188,6 +188,9 @@ const handleClick = () => {
|
|||||||
if(!props.isCreate){
|
if(!props.isCreate){
|
||||||
bulletinStore.queryBulletinDetail(props.id).then((res: any) => {
|
bulletinStore.queryBulletinDetail(props.id).then((res: any) => {
|
||||||
formData.value = res.data;
|
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);
|
const res = await bulletinStore.addAttachments(formDataFile);
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
onSuccess(res.data);
|
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 {
|
} else {
|
||||||
onError(res.data);
|
onError(res.data);
|
||||||
}
|
}
|
||||||
@ -251,7 +256,11 @@ const customRequest = async (option: any) => {
|
|||||||
|
|
||||||
// 删除附件
|
// 删除附件
|
||||||
const beforeRemove = async (file: any) => {
|
const beforeRemove = async (file: any) => {
|
||||||
const res = await bulletinStore.deleteAttachment(file.response.id);
|
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;
|
return res.status === 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user