Commit ef0601fd authored by chenshouchao's avatar chenshouchao

feat: 上传文件弹窗重构

parent 829ec90b
import React, { import React, { useState, useCallback, useMemo, useEffect } from "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/Dialog";
import { Button } from "@mui/material"; import { Button } from "@mui/material";
import { uuid } from "@/utils/util"; import { uuid } from "@/utils/util";
import { useMessage } from "@/components/MySnackbar"; import { useMessage } from "@/components/MySnackbar";
...@@ -24,13 +19,20 @@ import useGlobalStore from "@/hooks/useGlobalStore"; ...@@ -24,13 +19,20 @@ import useGlobalStore from "@/hooks/useGlobalStore";
import { APIOPTION, urlToken } from "@/api/fileserver/raysyncApi"; import { APIOPTION, urlToken } from "@/api/fileserver/raysyncApi";
import UseTusUpload from "@/utils/Upload/tusUpload"; import UseTusUpload from "@/utils/Upload/tusUpload";
const UpLoaderFile = observer((props: any) => { type IMoveFileProps = {
uploaderDialogOpen: any;
setUploaderDialogOpen: any;
path: string;
list: Array<any>;
};
const UpLoaderFile = observer((props: IMoveFileProps) => {
const { path, list, uploaderDialogOpen, setUploaderDialogOpen } = props;
const { fileListStore } = useStores(); const { fileListStore } = useStores();
const message = useMessage(); const message = useMessage();
const [fileList, setFileList] = useState<any>([]); const [fileList, setFileList] = useState<any>([]);
// list 是项目数据table的数据 // list 是项目数据table的数据
const { path, list } = props;
// 集合当前路径下的文件、文件夹、数据集 和已选择要上传的文件列表 // 集合当前路径下的文件、文件夹、数据集 和已选择要上传的文件列表
const nowNameList = useMemo(() => { const nowNameList = useMemo(() => {
...@@ -94,10 +96,6 @@ const UpLoaderFile = observer((props: any) => { ...@@ -94,10 +96,6 @@ const UpLoaderFile = observer((props: any) => {
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop }); const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });
const submitloading = false;
let dialogRef: any = React.createRef();
const getFileToken = useCallback( const getFileToken = useCallback(
(newFileList: any) => { (newFileList: any) => {
let url = let url =
...@@ -140,23 +138,14 @@ const UpLoaderFile = observer((props: any) => { ...@@ -140,23 +138,14 @@ const UpLoaderFile = observer((props: any) => {
if (newFileList?.length) { if (newFileList?.length) {
getFileToken(newFileList); getFileToken(newFileList);
} }
dialogRef.current.handleClose(); setUploaderDialogOpen(false);
}; };
const showDialog = () => { useEffect(() => {
dialogRef.current.handleClickOpen(); if (uploaderDialogOpen) {
initData();
};
const initData = () => {
setFileList([]); setFileList([]);
}; }
}, [uploaderDialogOpen]);
useImperativeHandle(props.onRef, () => {
return {
showDialog: showDialog,
};
});
const fileListHeadCells = [ const fileListHeadCells = [
{ id: "name", numeric: false, label: "名称", width: "60%" }, { id: "name", numeric: false, label: "名称", width: "60%" },
...@@ -172,7 +161,6 @@ const UpLoaderFile = observer((props: any) => { ...@@ -172,7 +161,6 @@ const UpLoaderFile = observer((props: any) => {
</span> </span>
); );
}; };
// 1,048,576
const renderSize = (item: any) => { const renderSize = (item: any) => {
return <span>{item.size ? storageUnitFromB(Number(item.size)) : "-"}</span>; return <span>{item.size ? storageUnitFromB(Number(item.size)) : "-"}</span>;
}; };
...@@ -200,18 +188,16 @@ const UpLoaderFile = observer((props: any) => { ...@@ -200,18 +188,16 @@ const UpLoaderFile = observer((props: any) => {
return ( return (
<MyDialog <MyDialog
handleSubmit={handleSubmit}
onRef={dialogRef}
title="上传文件" title="上传文件"
submitloading={submitloading} okText="开始上传"
submitText="开始上传" showCancel={false}
showCloseButton={false} open={uploaderDialogOpen}
onClose={() => setUploaderDialogOpen(false)}
onConfirm={handleSubmit}
> >
<div className={style.uploderBox}> <div className={style.uploderBox}>
<div className={style.uploderBoxLeft}> <div className={style.uploderBoxLeft}>
<div className={style.dropTitle}>添加文件</div> <div className={style.dropTitle}>添加文件</div>
{/* <div {...getRootProps()} className={style.dropBox}> */}
<div <div
{...getRootProps()} {...getRootProps()}
className={classnames({ className={classnames({
...@@ -219,7 +205,6 @@ const UpLoaderFile = observer((props: any) => { ...@@ -219,7 +205,6 @@ const UpLoaderFile = observer((props: any) => {
[style.dropBoxDragActive]: isDragActive, [style.dropBoxDragActive]: isDragActive,
})} })}
> >
{/* isDragActive */}
<input {...getInputProps()} multiple /> <input {...getInputProps()} multiple />
<img className={style.uploaderIcon} src={uploaderIcon} alt="" /> <img className={style.uploaderIcon} src={uploaderIcon} alt="" />
<div className={style.uploderText1}> <div className={style.uploderText1}>
......
...@@ -83,6 +83,7 @@ const ProjectData = observer(() => { ...@@ -83,6 +83,7 @@ const ProjectData = observer(() => {
const [moveDialogOpen, setMoveDialogOpen] = useState(false); const [moveDialogOpen, setMoveDialogOpen] = useState(false);
// 文件删除弹窗控制 // 文件删除弹窗控制
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
const [uploaderDialogOpen, setUploaderDialogOpen] = useState(false);
useEffect(() => { useEffect(() => {
const locationInfo: any = location?.state; const locationInfo: any = location?.state;
...@@ -432,12 +433,6 @@ const ProjectData = observer(() => { ...@@ -432,12 +433,6 @@ const ProjectData = observer(() => {
); );
}; };
// 文件上传
let UpLoaderFileRef: any = React.createRef();
const hanleShowUpLoaderFileDialog = () => {
UpLoaderFileRef.current.showDialog();
};
// 下载文件 // 下载文件
const hanleDownloadFile = (item: any) => { const hanleDownloadFile = (item: any) => {
const downloadPath = const downloadPath =
...@@ -556,7 +551,7 @@ const ProjectData = observer(() => { ...@@ -556,7 +551,7 @@ const ProjectData = observer(() => {
variant="contained" variant="contained"
size="small" size="small"
style={{ marginRight: "12px" }} style={{ marginRight: "12px" }}
onClick={hanleShowUpLoaderFileDialog} onClick={() => setUploaderDialogOpen(true)}
disabled={ disabled={
selectIds.length !== 0 || selectIds.length !== 0 ||
!isPass("PROJECT_DATA_UPLOAD", "USER") !isPass("PROJECT_DATA_UPLOAD", "USER")
...@@ -685,11 +680,14 @@ const ProjectData = observer(() => { ...@@ -685,11 +680,14 @@ const ProjectData = observer(() => {
showList={showList} showList={showList}
></DeleteDialog> ></DeleteDialog>
)} )}
{uploaderDialogOpen && (
<UpLoaderFile <UpLoaderFile
onRef={UpLoaderFileRef} uploaderDialogOpen={uploaderDialogOpen}
setUploaderDialogOpen={setUploaderDialogOpen}
path={path} path={path}
list={allList} list={allList}
></UpLoaderFile> ></UpLoaderFile>
)}
{moveDialogOpen && ( {moveDialogOpen && (
<MoveFile <MoveFile
moveDialogOpen={moveDialogOpen} moveDialogOpen={moveDialogOpen}
......
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