Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
bkunyun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sunyihao
bkunyun
Commits
6ee91539
Commit
6ee91539
authored
Jun 15, 2022
by
chenshouchao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feta: 文件上传选择多文件时 部分文件重复的话也要上传不重复的文件
parent
ee149c72
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
22 deletions
+66
-22
index.tsx
src/views/Project/ProjectData/UpLoaderFile/index.tsx
+59
-20
index.tsx
src/views/Project/ProjectData/index.tsx
+7
-2
No files found.
src/views/Project/ProjectData/UpLoaderFile/index.tsx
View file @
6ee91539
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
});
...
...
src/views/Project/ProjectData/index.tsx
View file @
6ee91539
...
@@ -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=
{
l
ist
}
list=
{
allL
ist
}
></
UpLoaderFile
>
></
UpLoaderFile
>
<
AddFolder
<
AddFolder
onRef=
{
addFolderRef
}
onRef=
{
addFolderRef
}
list=
{
l
ist
}
list=
{
allL
ist
}
path=
{
path
}
path=
{
path
}
refresh=
{
handleRefresh
}
refresh=
{
handleRefresh
}
fileToken=
{
fileToken
}
fileToken=
{
fileToken
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment