update:上传附件组件删除废弃文件
This commit is contained in:
@@ -46,7 +46,7 @@ import FileIcon from '@/components/common/fileIcon/index.vue';
|
||||
import FilePreview from '@/components/common/filePreview/index.vue';
|
||||
import { View, Delete, Download } from '@element-plus/icons-vue';
|
||||
import { downloadFileById } from '@/utils/file';
|
||||
import { uploadAttachmentApi, getFileBaseInfoApi } from '@/api/data/data';
|
||||
import { uploadAttachmentApi, getFileBaseInfoApi, deleteAttachmentApi } from '@/api/data/data';
|
||||
|
||||
interface Props {
|
||||
modelValue: any;
|
||||
@@ -64,6 +64,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'change', 'remove']);
|
||||
const fileList = ref<any>([]);
|
||||
const addFileIds = ref<any>([]); // 本次新增文件id
|
||||
|
||||
const loadFileFun = (fileId: any) => {
|
||||
const params = {
|
||||
@@ -132,8 +133,21 @@ const downloadFun = (data: any) => {
|
||||
};
|
||||
|
||||
const removeFun = (index: number) => {
|
||||
emit('remove', fileList.value[index]);
|
||||
const fileData = fileList.value[index];
|
||||
emit('remove', fileData);
|
||||
fileList.value.splice(index, 1);
|
||||
const fileIndex = addFileIds.value.findIndex((i: any) => i === fileData.fileId);
|
||||
if (fileIndex > -1) {
|
||||
addFileIds.value.splice(index, 1);
|
||||
delFun(fileData.fileId);
|
||||
}
|
||||
};
|
||||
|
||||
const delFun = (fileId: any) => {
|
||||
const params = {
|
||||
fileId,
|
||||
};
|
||||
deleteAttachmentApi(params);
|
||||
};
|
||||
|
||||
const uploadFun = async (file: any) => {
|
||||
@@ -142,6 +156,7 @@ const uploadFun = async (file: any) => {
|
||||
};
|
||||
const res: any = await uploadAttachmentApi(params);
|
||||
if (res.code === 200) {
|
||||
addFileIds.value.push(res.data);
|
||||
fileList.value.some((item: any) => {
|
||||
if (file.uid === item.uid && file.name === item.name) {
|
||||
item.fileId = res.data;
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
@close="closeFun"
|
||||
>
|
||||
<TableForm
|
||||
v-if="diaVisible"
|
||||
ref="FormRef"
|
||||
:tableName="formName"
|
||||
:data="formData"
|
||||
|
||||
@@ -593,6 +593,8 @@ export const removeAttachmentFileIds = (oldIds: string, newIds: any) => {
|
||||
const newSet = new Set(newList);
|
||||
const delIds: any[] = oldList.filter((id) => !newSet.has(id));
|
||||
delIds.forEach((id: any) => {
|
||||
deleteAttachmentApi({ fileId: id });
|
||||
if (id) {
|
||||
deleteAttachmentApi({ fileId: id });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user