Commit c9c0d6b8 authored by chenshouchao's avatar chenshouchao

feat: 数据管理新建文件夹重构

parent 3dc486a5
import React, { useState, useImperativeHandle } from "react"; import React, { useState, useEffect } from "react";
import { TextField } from "@mui/material"; import { TextField, Button } from "@mui/material";
import MyDialog from "@/components/mui/MyDialog"; import MyDialog from "@/components/mui/Dialog";
import { checkIsNumberLetterChinese } from "@/utils/util"; import { checkIsNumberLetterChinese } from "@/utils/util";
import { useMessage } from "@/components/MySnackbar"; import { useMessage } from "@/components/MySnackbar";
import CloudEController from "@/api/fileserver/CloudEController"; import CloudEController from "@/api/fileserver/CloudEController";
import InputAdornment from '@mui/material/InputAdornment'; import usePass from "@/hooks/usePass";
import InputAdornment from "@mui/material/InputAdornment";
const AddFolder = (props: any) => { type IAddFolderProps = {
const { list, path, projectId, fileToken, refresh } = props; list: Array<any>;
const Message = useMessage(); path: string;
let addFolderDialogRef: any = React.createRef(); projectId: string;
const [fileName, setFileName] = useState(""); fileToken: string;
const [fileNameCheck, setFileNameCheck] = useState({ refresh: any;
error: false, selectIds: Array<any>;
help: "", };
});
const showDialog = () => {
addFolderDialogRef.current.handleClickOpen();
initData()
};
const initData = () => { const AddFolder = (props: IAddFolderProps) => {
setFileName('') const { list, path, projectId, fileToken, refresh, selectIds } = props;
setFileNameCheck({ const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
error: false, const isPass = usePass();
help: "", const Message = useMessage();
}) const [fileName, setFileName] = useState("");
} const [fileNameCheck, setFileNameCheck] = useState({
error: false,
help: "",
});
useImperativeHandle(props.onRef, () => { useEffect(() => {
return { if (deleteDialogOpen) {
showDialog: showDialog, setFileName("");
}; setFileNameCheck({
}); error: false,
help: "",
});
}
}, [deleteDialogOpen]);
const handleAddSubmit = () => { const handleAddSubmit = () => {
if (fileName && !fileNameCheck.error) { if (fileName && !fileNameCheck.error) {
const newFolderPath = const newFolderPath =
path === "/" ? `${path}${fileName}` : `${path}/${fileName}`; path === "/" ? `${path}${fileName}` : `${path}/${fileName}`;
// 请求接口 // 请求接口
CloudEController.JobFileNewFolder( CloudEController.JobFileNewFolder(
newFolderPath, newFolderPath,
fileToken, fileToken,
projectId projectId
)?.then((res) => { )?.then((res) => {
Message.success("新建成功"); Message.success("新建成功");
addFolderDialogRef.current.handleClose(); setDeleteDialogOpen(false);
refresh() refresh();
}); });
} else { } else {
Message.info(fileNameCheck.help || "请输入文件夹名称"); Message.info(fileNameCheck.help || "请输入文件夹名称");
} }
}; };
const addFolderSubmitloading = false; const handleFileNameChange = (e: any) => {
const handleFileNameChange = (e: any) => { const fileName = e.target.value;
const fileName = e.target.value; setFileName(fileName);
setFileName(fileName); if (!fileName) {
if (!fileName) { setFileNameCheck({
setFileNameCheck({ error: true,
error: true, help: "文件夹名称不能为空",
help: "文件夹名称不能为空", });
}); } else if (!checkIsNumberLetterChinese(fileName) || fileName.length > 30) {
} else if (!checkIsNumberLetterChinese(fileName) || fileName.length > 30) { setFileNameCheck({
setFileNameCheck({ error: true,
error: true, help: "格式不正确,必须在30字符以内,仅限大小写字母、数字、中文",
help: "格式不正确,必须在30字符以内,仅限大小写字母、数字、中文", });
}); } else if (isRepeat(fileName)) {
} else if (isRepeat(fileName)) { setFileNameCheck({
setFileNameCheck({ error: true,
error: true, help: "已存在同名文件夹",
help: "已存在同名文件夹", });
}); } else {
} else { setFileNameCheck({
setFileNameCheck({ error: false,
error: false, help: "",
help: "", });
}); }
} };
};
const isRepeat = (fileName: string) => { const isRepeat = (fileName: string) => {
return list.some((item: any) => { return list.some((item: any) => {
return item.name === fileName; return item.name === fileName;
}); });
}; };
return ( return (
<MyDialog <>
handleSubmit={handleAddSubmit} <Button
onRef={addFolderDialogRef} color="neutral"
title="新建文件夹" variant="outlined"
submitloading={addFolderSubmitloading} size="small"
> onClick={() => setDeleteDialogOpen(true)}
<TextField disabled={
sx={{ selectIds.length !== 0 || !isPass("PROJECT_DATA_ADDDIR", "USER")
width: "388px", }
border: "1px solide #E6E8EB", >
marginTop: "12px", 新建文件夹
}} </Button>
required <MyDialog
error={fileNameCheck.error} open={deleteDialogOpen}
id="fileName" onClose={() => setDeleteDialogOpen(false)}
label="名称" onConfirm={handleAddSubmit}
variant="outlined" title="新建文件夹"
value={fileName} >
onChange={handleFileNameChange} <TextField
helperText={fileNameCheck.help} sx={{
InputProps={{ width: "388px",
endAdornment: <InputAdornment position="end">{fileName.length}/30</InputAdornment>, border: "1px solide #E6E8EB",
}} marginTop: "12px",
size="small" }}
/> required
</MyDialog> error={fileNameCheck.error}
); id="fileName"
label="名称"
variant="outlined"
value={fileName}
onChange={handleFileNameChange}
helperText={fileNameCheck.help}
InputProps={{
endAdornment: (
<InputAdornment position="end">
{fileName.length}/30
</InputAdornment>
),
}}
size="small"
/>
</MyDialog>
</>
);
}; };
export default AddFolder; export default AddFolder;
...@@ -37,6 +37,12 @@ ...@@ -37,6 +37,12 @@
font-weight: 600; font-weight: 600;
} }
.projectDataTabsAndBtton {
display: flex;
justify-content: flex-end;
align-items: center;
}
.folderIconBox { .folderIconBox {
display: flex; display: flex;
justify-content: flex-start; justify-content: flex-start;
......
...@@ -60,14 +60,12 @@ const ProjectData = observer(() => { ...@@ -60,14 +60,12 @@ const ProjectData = observer(() => {
/** 路由信息 */ /** 路由信息 */
const location = useLocation(); const location = useLocation();
// 当前文件路径 // 当前文件路径
const [path, setPath] = useState<String>("/"); const [path, setPath] = useState<string>("/");
const [tableLoadding, setTableLoadding] = useState(false);
// 防止用户连续点击文件夹造成路径显示错误 // 防止用户连续点击文件夹造成路径显示错误
const [debounce, setDebounce] = useState(false); const [debounce, setDebounce] = useState(false);
// 点击操作列中的按钮 会设置当前点击的文件 // 点击操作列中的按钮 会设置当前点击的文件
const [currentOperateFile, setCurrentOperateFile] = useState<any>(null); const [currentOperateFile, setCurrentOperateFile] = useState<any>(null);
// 文件file 数据集dataset // 文件file 数据集dataset
// const [activeTab, setActiveTab] = useState(1);
const [activeTab, setActiveTab] = useState("file"); const [activeTab, setActiveTab] = useState("file");
// 复选框选中的文件名称数组 // 复选框选中的文件名称数组
const [selectIds, setSelectIds] = useState<Array<string>>([]); const [selectIds, setSelectIds] = useState<Array<string>>([]);
...@@ -188,14 +186,12 @@ const ProjectData = observer(() => { ...@@ -188,14 +186,12 @@ const ProjectData = observer(() => {
return; return;
} else if (fileToken && projectId) { } else if (fileToken && projectId) {
if (fileServerEndPoint) { if (fileServerEndPoint) {
setTableLoadding(true);
return CloudEController.JobOutFileList( return CloudEController.JobOutFileList(
path, path,
fileToken, fileToken,
projectId, projectId,
false false
)?.then((res) => { )?.then((res) => {
setTableLoadding(false);
if (Array.isArray(res.data)) { if (Array.isArray(res.data)) {
setList(res.data); setList(res.data);
} else { } else {
...@@ -219,7 +215,6 @@ const ProjectData = observer(() => { ...@@ -219,7 +215,6 @@ const ProjectData = observer(() => {
getList(); getList();
} else { } else {
if (fileToken && projectId) { if (fileToken && projectId) {
setTableLoadding(true);
setPath("/"); setPath("/");
return CloudEController.JobSearchFileList( return CloudEController.JobSearchFileList(
keyWord, keyWord,
...@@ -228,7 +223,6 @@ const ProjectData = observer(() => { ...@@ -228,7 +223,6 @@ const ProjectData = observer(() => {
projectId, projectId,
false false
)?.then((res) => { )?.then((res) => {
setTableLoadding(false);
if (Array.isArray(res.data)) { if (Array.isArray(res.data)) {
setList(res.data); setList(res.data);
} else { } else {
...@@ -273,7 +267,6 @@ const ProjectData = observer(() => { ...@@ -273,7 +267,6 @@ const ProjectData = observer(() => {
} }
}; };
// todo name sort
// table配置 // table配置
const versionsHeadCells = useMemo(() => { const versionsHeadCells = useMemo(() => {
if (showCheckBox) { if (showCheckBox) {
...@@ -441,13 +434,6 @@ const ProjectData = observer(() => { ...@@ -441,13 +434,6 @@ const ProjectData = observer(() => {
UpLoaderFileRef.current.showDialog(); UpLoaderFileRef.current.showDialog();
}; };
// 新增文件
let addFolderRef: any = React.createRef();
const hanleShowAddFolderDialog = () => {
addFolderRef.current.showDialog();
};
// 下载文件 // 下载文件
const hanleDownloadFile = (item: any) => { const hanleDownloadFile = (item: any) => {
const downloadPath = const downloadPath =
...@@ -577,18 +563,14 @@ const ProjectData = observer(() => { ...@@ -577,18 +563,14 @@ const ProjectData = observer(() => {
> >
上传文件 上传文件
</Button> </Button>
<Button <AddFolder
color="neutral" selectIds={selectIds}
variant="outlined" list={allList}
size="small" path={path}
onClick={hanleShowAddFolderDialog} refresh={handleRefresh}
disabled={ fileToken={fileToken as string}
selectIds.length !== 0 || projectId={projectId as string}
!isPass("PROJECT_DATA_ADDDIR", "USER") ></AddFolder>
}
>
新建文件夹
</Button>
</div> </div>
<div className={style.projectDataSearch}> <div className={style.projectDataSearch}>
<InputBase <InputBase
...@@ -631,6 +613,7 @@ const ProjectData = observer(() => { ...@@ -631,6 +613,7 @@ const ProjectData = observer(() => {
size="small" size="small"
onClick={handleRefresh} onClick={handleRefresh}
disabled={!isPass("PROJECT_DATA_REFRESH", "USER")} disabled={!isPass("PROJECT_DATA_REFRESH", "USER")}
sx={{ marginLeft: "17px" }}
> >
<RefreshIcon /> <RefreshIcon />
</IconButton> </IconButton>
...@@ -643,7 +626,6 @@ const ProjectData = observer(() => { ...@@ -643,7 +626,6 @@ const ProjectData = observer(() => {
onRef={tableRef} onRef={tableRef}
nopadding={true} nopadding={true}
stickyheader={true} stickyheader={true}
load={tableLoadding}
initSelected={selectIds} initSelected={selectIds}
headCells={versionsHeadCells} headCells={versionsHeadCells}
rowsPerPage={"99"} rowsPerPage={"99"}
...@@ -704,14 +686,6 @@ const ProjectData = observer(() => { ...@@ -704,14 +686,6 @@ const ProjectData = observer(() => {
path={path} path={path}
list={allList} list={allList}
></UpLoaderFile> ></UpLoaderFile>
<AddFolder
onRef={addFolderRef}
list={allList}
path={path}
refresh={handleRefresh}
fileToken={fileToken}
projectId={projectId}
></AddFolder>
<MoveFile <MoveFile
onRef={moveFileRef} onRef={moveFileRef}
path={path} path={path}
......
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