Commit 6ee91539 authored by chenshouchao's avatar chenshouchao

feta: 文件上传选择多文件时 部分文件重复的话也要上传不重复的文件

parent ee149c72
import React, { useState, useImperativeHandle, useCallback } from "react";
import React, {
useState,
useImperativeHandle,
useCallback,
useMemo,
} from "react";
import style from "./index.module.css";
import MyDialog from "@/components/mui/MyDialog";
......@@ -23,34 +28,68 @@ const UpLoaderFile = observer((props: any) => {
// list 是项目数据table的数据
const { path, list } = props;
// 集合当前路径下的文件、文件夹、数据集 和已选择要上传的文件列表
const nowNameList = useMemo(() => {
return [...list, ...fileList];
}, [list, fileList]);
const onDrop = useCallback(
(acceptedFiles: any) => {
// 判断是否有文件名重复
const fileListRepeatName = getRepeatName(fileList, acceptedFiles);
const listRepeatName = getRepeatName(list, acceptedFiles);
if (fileListRepeatName || listRepeatName) {
message.error(`${fileListRepeatName || listRepeatName}文件已存在`);
return;
// 获取重复的项目文件列表和要上传(名称不重复就上传)的文件
const getRepeatFileAndGetUploderFileList = (
acceptedFiles: Array<any>
) => {
let repeatFileList: any = [];
let uploderFileList: any = [];
acceptedFiles.forEach((fItem: any, index: number) => {
if (
nowNameList.some((nItem: any) => {
return nItem.name === fItem.name;
})
) {
repeatFileList.push(acceptedFiles[index]);
} else {
uploderFileList.push(acceptedFiles[index]);
}
});
return {
repeatFileList,
uploderFileList,
};
};
const repeatAndUploaderFileList =
getRepeatFileAndGetUploderFileList(acceptedFiles);
console.log(repeatAndUploaderFileList);
if (repeatAndUploaderFileList.repeatFileList.length > 0) {
message.error(
`“${repeatAndUploaderFileList.repeatFileList
.map((i: any) => i.name)
.join("、")}”文件已存在`
);
}
// 插入新的文件列表
const popLength = 10 - fileList.length;
let newFileList = [...acceptedFiles.slice(0, popLength), ...fileList];
let newFileList = [
...repeatAndUploaderFileList.uploderFileList.slice(0, popLength),
...fileList,
];
setFileList(newFileList);
},
[fileList, list, message]
[fileList, message, nowNameList]
);
const getRepeatName = (fList: Array<any>, Alist: Array<any>) => {
let repeatName = "";
Alist.forEach((aItem) => {
fList.forEach((fItem: any) => {
if (fItem.name === aItem.name) {
repeatName = fItem.name;
}
});
});
return repeatName;
};
// const getRepeatName = (fList: Array<any>, Alist: Array<any>) => {
// let repeatName = "";
// Alist.forEach((aItem) => {
// fList.forEach((fItem: any) => {
// if (fItem.name === aItem.name) {
// repeatName = fItem.name;
// }
// });
// });
// return repeatName;
// };
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });
......
......@@ -116,6 +116,11 @@ const ProjectData = observer(() => {
}
}, [list, dataSetList, activeTab]);
// 全(文件、文件夹、数据集)列表
const allList = useMemo(() => {
return [...list, ...dataSetList];
}, [list, dataSetList]);
// 获取文件token
// const { run: getDataFileTokenRun } = useMyRequest(getDataFileToken, {
// onSuccess: (res: any) => {
......@@ -799,11 +804,11 @@ const ProjectData = observer(() => {
<UpLoaderFile
onRef={UpLoaderFileRef}
path={path}
list={list}
list={allList}
></UpLoaderFile>
<AddFolder
onRef={addFolderRef}
list={list}
list={allList}
path={path}
refresh={handleRefresh}
fileToken={fileToken}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment