update:大文件上传优化

This commit is contained in:
2026-01-21 20:22:27 +08:00
parent b48cc30d8f
commit a6e6560771
2 changed files with 31 additions and 28 deletions

View File

@@ -11,6 +11,7 @@ import { cloneDeep } from 'lodash-es';
import { CommonStore } from '@/stores/common';
import dayjs from 'dayjs';
import { FILE_TYPE } from './enum/file';
import emitter from '@/utils/eventBus';
const env = import.meta.env;
@@ -244,6 +245,24 @@ export const downloadFileByStream = async (fileId: number) => {
await systemDataDownloadFileApi({ fileId });
};
// 上传大文件
export const uploadBigFile = async (params: any, api: any) => {
const res = await api(params);
if (res.code === 200) {
res.data.forEach((item: any, index: number) => {
emitter.emit('ADD_UPLOAD_FILE', {
file: params.sourceFiles[index].raw,
data: {
...item,
isApprove: params.isApprove,
taskType: params.taskType,
callbackFlag: params.callbackFlag,
},
});
});
}
};
/**
* 根据节点id查询文件id
* @param uuid

View File

@@ -17,8 +17,7 @@ import { ref, watch } from 'vue';
import Dialog from '@/components/common/dialog/index.vue';
import TableForm from '@/components/common/table/tableForm.vue';
import { batchAddFileInfoApi } from '@/api/data/data';
import emitter from '@/utils/eventBus';
import { fileUploadAllocationTypeFun } from '@/utils/file';
import { fileUploadAllocationTypeFun, uploadBigFile } from '@/utils/file';
interface Props {
modelValue: boolean;
@@ -59,35 +58,20 @@ const submitFun = async () => {
fileType: await fileUploadAllocationTypeFun(formData.value.files[i].name),
});
}
// = formData.value.files.map((file: any) => {
// return {
// };
// });
const params = {
sourceFiles,
uploadTaskId: new Date().getTime(),
dirId: props.data.id,
projectId: props.data.relatedResourceUuid,
// 必填参数
sourceFiles, // 文件列表
uploadTaskId: new Date().getTime(), // 用时间戳作为任务id
dirId: props.data.id, // 文件目录id
projectId: props.data.relatedResourceUuid, // 项目id
type: 0,
isApprove: 0, // 0不需要审批 1需要审批
taskType: 1, // 任务类型,用于区分回调接口
callbackFlag: '/data/overview', // 回调标识
// 非必填参数,其他透传给回调接口的参数
};
batchAddFileInfoApi(params).then((res: any) => {
if (res.code === 200) {
res.data.forEach((item: any, index: number) => {
emitter.emit('ADD_UPLOAD_FILE', {
file: formData.value.files[index].raw,
data: {
...item,
isApprove: 0,
taskType: 1,
callbackFlag: '/data/overview',
},
});
});
}
closeFun();
});
await uploadBigFile(params, batchAddFileInfoApi);
closeFun();
}
};