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 style from "./index.module.css";
import MyDialog from "@/components/mui/MyDialog"; import MyDialog from "@/components/mui/MyDialog";
...@@ -23,34 +28,68 @@ const UpLoaderFile = observer((props: any) => { ...@@ -23,34 +28,68 @@ const UpLoaderFile = observer((props: any) => {
// list 是项目数据table的数据 // list 是项目数据table的数据
const { path, list } = props; const { path, list } = props;
// 集合当前路径下的文件、文件夹、数据集 和已选择要上传的文件列表
const nowNameList = useMemo(() => {
return [...list, ...fileList];
}, [list, fileList]);
const onDrop = useCallback( const onDrop = useCallback(
(acceptedFiles: any) => { (acceptedFiles: any) => {
// 判断是否有文件名重复 // 获取重复的项目文件列表和要上传(名称不重复就上传)的文件
const fileListRepeatName = getRepeatName(fileList, acceptedFiles); const getRepeatFileAndGetUploderFileList = (
const listRepeatName = getRepeatName(list, acceptedFiles); acceptedFiles: Array<any>
if (fileListRepeatName || listRepeatName) { ) => {
message.error(`${fileListRepeatName || listRepeatName}文件已存在`); let repeatFileList: any = [];
return; 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; const popLength = 10 - fileList.length;
let newFileList = [...acceptedFiles.slice(0, popLength), ...fileList]; let newFileList = [
...repeatAndUploaderFileList.uploderFileList.slice(0, popLength),
...fileList,
];
setFileList(newFileList); setFileList(newFileList);
}, },
[fileList, list, message] [fileList, message, nowNameList]
); );
const getRepeatName = (fList: Array<any>, Alist: Array<any>) => { // const getRepeatName = (fList: Array<any>, Alist: Array<any>) => {
let repeatName = ""; // let repeatName = "";
Alist.forEach((aItem) => { // Alist.forEach((aItem) => {
fList.forEach((fItem: any) => { // fList.forEach((fItem: any) => {
if (fItem.name === aItem.name) { // if (fItem.name === aItem.name) {
repeatName = fItem.name; // repeatName = fItem.name;
} // }
}); // });
}); // });
return repeatName; // return repeatName;
}; // };
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop }); const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });
......
...@@ -116,6 +116,11 @@ const ProjectData = observer(() => { ...@@ -116,6 +116,11 @@ const ProjectData = observer(() => {
} }
}, [list, dataSetList, activeTab]); }, [list, dataSetList, activeTab]);
// 全(文件、文件夹、数据集)列表
const allList = useMemo(() => {
return [...list, ...dataSetList];
}, [list, dataSetList]);
// 获取文件token // 获取文件token
// const { run: getDataFileTokenRun } = useMyRequest(getDataFileToken, { // const { run: getDataFileTokenRun } = useMyRequest(getDataFileToken, {
// onSuccess: (res: any) => { // onSuccess: (res: any) => {
...@@ -799,11 +804,11 @@ const ProjectData = observer(() => { ...@@ -799,11 +804,11 @@ const ProjectData = observer(() => {
<UpLoaderFile <UpLoaderFile
onRef={UpLoaderFileRef} onRef={UpLoaderFileRef}
path={path} path={path}
list={list} list={allList}
></UpLoaderFile> ></UpLoaderFile>
<AddFolder <AddFolder
onRef={addFolderRef} onRef={addFolderRef}
list={list} list={allList}
path={path} path={path}
refresh={handleRefresh} refresh={handleRefresh}
fileToken={fileToken} 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