Commit 5ae002f7 authored by chenshouchao's avatar chenshouchao

feat: 新增项目后 当前项目变为新增的项目, 切换项目后同时获取filetoken

parent 454f109e
...@@ -8,7 +8,10 @@ import NotFound from "@/views/404"; ...@@ -8,7 +8,10 @@ import NotFound from "@/views/404";
import useMyRequest from "@/hooks/useMyRequest"; import useMyRequest from "@/hooks/useMyRequest";
import { useEffect } from "react"; import { useEffect } from "react";
import { menu } from "@/api/routes_api"; import { menu } from "@/api/routes_api";
import { setFileServerEndPointLocalStorage } from "@/views/Project/project"; import {
setFileServerEndPointLocalStorage,
getFiletokenAccordingToId,
} from "@/views/Project/project";
const useMyRouter = () => { const useMyRouter = () => {
const { permissionStore, menuStore, currentProjectStore } = useStores(); const { permissionStore, menuStore, currentProjectStore } = useStores();
...@@ -53,6 +56,10 @@ const useMyRouter = () => { ...@@ -53,6 +56,10 @@ const useMyRouter = () => {
currentProjectStore.setProjectList(list); currentProjectStore.setProjectList(list);
currentProjectStore.changeProject(list[0]); currentProjectStore.changeProject(list[0]);
setFileServerEndPointLocalStorage(list[0].zoneId); setFileServerEndPointLocalStorage(list[0].zoneId);
getFiletokenAccordingToId(list[0].id).then((res) => {
list[0].filetoken = res;
currentProjectStore.changeProject(list[0]);
});
} }
} }
......
...@@ -4,6 +4,7 @@ type projectInfo = { ...@@ -4,6 +4,7 @@ type projectInfo = {
name?: string; name?: string;
desc?: string; desc?: string;
projectRole?: string; projectRole?: string;
filetoken?: string;
}; };
type productInfo = { type productInfo = {
......
...@@ -28,6 +28,7 @@ import DialogActions from "@mui/material/DialogActions"; ...@@ -28,6 +28,7 @@ import DialogActions from "@mui/material/DialogActions";
import DialogContent from "@mui/material/DialogContent"; import DialogContent from "@mui/material/DialogContent";
import DialogContentText from "@mui/material/DialogContentText"; import DialogContentText from "@mui/material/DialogContentText";
import DialogTitle from "@mui/material/DialogTitle"; import DialogTitle from "@mui/material/DialogTitle";
import NoProject from "@/components/NoProject";
import usePass from "@/hooks/usePass"; import usePass from "@/hooks/usePass";
import { import {
getDataFind, getDataFind,
...@@ -63,9 +64,18 @@ const ProjectData = observer(() => { ...@@ -63,9 +64,18 @@ const ProjectData = observer(() => {
const isPass = usePass(); const isPass = usePass();
const Message = useMessage(); const Message = useMessage();
const { currentProjectStore } = useStores(); const { currentProjectStore } = useStores();
const projectId = useMemo(() => { // const [fileToken, setFileToken] = useState("");
return toJS(currentProjectStore.currentProjectInfo.id); const fileToken = toJS(currentProjectStore.currentProjectInfo.filetoken);
}, [currentProjectStore]); console.log(fileToken);
const projectId = toJS(currentProjectStore.currentProjectInfo.id);
console.log(projectId);
// const projectId = useMemo(() => {
// console.log(
// toJS(currentProjectStore.currentProjectInfo.id),
// "toJS(currentProjectStore.currentProjectInfo.id)"
// );
// return toJS(currentProjectStore.currentProjectInfo.id);
// }, [currentProjectStore]);
// 当前文件路径 // 当前文件路径
const [path, setPath] = useState("/"); const [path, setPath] = useState("/");
const [tableLoadding, setTableLoadding] = useState(false); const [tableLoadding, setTableLoadding] = useState(false);
...@@ -80,7 +90,6 @@ const ProjectData = observer(() => { ...@@ -80,7 +90,6 @@ const ProjectData = observer(() => {
// 复选框选中的文件名称数组 // 复选框选中的文件名称数组
const [selectIds, setSelectIds] = useState<Array<string>>([]); const [selectIds, setSelectIds] = useState<Array<string>>([]);
const [keyWord, setKeyWord] = useState(""); const [keyWord, setKeyWord] = useState("");
const [fileToken, setFileToken] = useState("");
// 文件夹、文件列表 // 文件夹、文件列表
const [list, setList] = useState<any>([]); const [list, setList] = useState<any>([]);
// 数据集列表 不带文件 // 数据集列表 不带文件
...@@ -109,11 +118,11 @@ const ProjectData = observer(() => { ...@@ -109,11 +118,11 @@ const ProjectData = observer(() => {
}, [list, dataSetList, activeTab]); }, [list, dataSetList, activeTab]);
// 获取文件token // 获取文件token
const { run: getDataFileTokenRun } = useMyRequest(getDataFileToken, { // const { run: getDataFileTokenRun } = useMyRequest(getDataFileToken, {
onSuccess: (res: any) => { // onSuccess: (res: any) => {
setFileToken(res.data); // setFileToken(res.data);
}, // },
}); // });
// 全局搜索数据集 // 全局搜索数据集
const { run: getDataFileSearchRun } = useMyRequest(getDataFileSearch, { const { run: getDataFileSearchRun } = useMyRequest(getDataFileSearch, {
...@@ -149,7 +158,7 @@ const ProjectData = observer(() => { ...@@ -149,7 +158,7 @@ const ProjectData = observer(() => {
// 获取某路径下的数据集 // 获取某路径下的数据集
const getDataSetList = useCallback(() => { const getDataSetList = useCallback(() => {
if (keyWord) { if (keyWord && projectId) {
return; return;
} else { } else {
return getDataFindRun({ return getDataFindRun({
...@@ -161,7 +170,7 @@ const ProjectData = observer(() => { ...@@ -161,7 +170,7 @@ const ProjectData = observer(() => {
// 全局搜索数据集 // 全局搜索数据集
const getDataSetListSearch = useCallback(() => { const getDataSetListSearch = useCallback(() => {
if (keyWord) { if (keyWord && projectId) {
return getDataFileSearchRun({ return getDataFileSearchRun({
projectId: projectId as string, projectId: projectId as string,
name: keyWord, name: keyWord,
...@@ -246,11 +255,11 @@ const ProjectData = observer(() => { ...@@ -246,11 +255,11 @@ const ProjectData = observer(() => {
}; };
// 项目切换时重新获取文件token // 项目切换时重新获取文件token
useEffect(() => { // useEffect(() => {
getDataFileTokenRun({ // getDataFileTokenRun({
id: currentProjectStore.currentProjectInfo.id as string, // id: currentProjectStore.currentProjectInfo.id as string,
}); // });
}, [getDataFileTokenRun, currentProjectStore]); // }, [getDataFileTokenRun, currentProjectStore]);
// 搜索值改变 // 搜索值改变
const handleKeyWordChange = (e: any) => { const handleKeyWordChange = (e: any) => {
...@@ -468,7 +477,7 @@ const ProjectData = observer(() => { ...@@ -468,7 +477,7 @@ const ProjectData = observer(() => {
: `${path}/${currentOperateFile.name}`; : `${path}/${currentOperateFile.name}`;
CloudEController.JobOutFileDel( CloudEController.JobOutFileDel(
deletePath, deletePath,
fileToken, fileToken as string,
projectId as string projectId as string
)?.then((res) => { )?.then((res) => {
Message.success("删除成功"); Message.success("删除成功");
...@@ -499,7 +508,7 @@ const ProjectData = observer(() => { ...@@ -499,7 +508,7 @@ const ProjectData = observer(() => {
.join(" "); .join(" ");
CloudEController.JobOutFileDel( CloudEController.JobOutFileDel(
deletePath, deletePath,
fileToken, fileToken as string,
projectId as string projectId as string
)?.then((res) => { )?.then((res) => {
Message.success("删除成功"); Message.success("删除成功");
...@@ -512,7 +521,7 @@ const ProjectData = observer(() => { ...@@ -512,7 +521,7 @@ const ProjectData = observer(() => {
} else { } else {
CloudEController.JobOutFileDel( CloudEController.JobOutFileDel(
deletePath, deletePath,
fileToken, fileToken as string,
projectId as string projectId as string
)?.then((res) => { )?.then((res) => {
Message.success("删除成功"); Message.success("删除成功");
...@@ -601,217 +610,221 @@ const ProjectData = observer(() => { ...@@ -601,217 +610,221 @@ const ProjectData = observer(() => {
} }
}, [path]); }, [path]);
return ( if (currentProjectStore.currentProjectInfo.name) {
<ThemeProvider theme={theme}> return (
<div className={style.projectData}> <ThemeProvider theme={theme}>
<div className={style.projectDataStickyTop}> <div className={style.projectData}>
<div className={style.projectDataTitle}>项目数据</div> <div className={style.projectDataStickyTop}>
<div className={style.projectDataHeader}> <div className={style.projectDataTitle}>项目数据</div>
<div className={style.projectDataButtonAndSearch}> <div className={style.projectDataHeader}>
<div className={style.projectDataButtonBox}> <div className={style.projectDataButtonAndSearch}>
<Button <div className={style.projectDataButtonBox}>
color="neutral" <Button
variant="contained" color="neutral"
size="small" variant="contained"
style={{ marginRight: "12px" }} size="small"
onClick={hanleShowUpLoaderFileDialog} style={{ marginRight: "12px" }}
disabled={ onClick={hanleShowUpLoaderFileDialog}
selectIds.length !== 0 || disabled={
!isPass("PROJECT_DATA_UPLOAD", "USER") selectIds.length !== 0 ||
} !isPass("PROJECT_DATA_UPLOAD", "USER")
> }
上传文件 >
</Button> 上传文件
<Button </Button>
color="neutral" <Button
variant="outlined" color="neutral"
size="small" variant="outlined"
onClick={hanleShowAddFolderDialog} size="small"
disabled={ onClick={hanleShowAddFolderDialog}
selectIds.length !== 0 || disabled={
!isPass("PROJECT_DATA_ADDDIR", "USER") selectIds.length !== 0 ||
} !isPass("PROJECT_DATA_ADDDIR", "USER")
> }
新建文件夹 >
</Button> 新建文件夹
</div> </Button>
<div className={style.projectDataSearch}> </div>
<InputBase <div className={style.projectDataSearch}>
className={style.searchInput} <InputBase
placeholder="输入关键词搜索" className={style.searchInput}
inputProps={{ "aria-label": "输入关键词搜索" }} placeholder="输入关键词搜索"
value={keyWord} inputProps={{ "aria-label": "输入关键词搜索" }}
onChange={handleKeyWordChange} value={keyWord}
style={{ width: "280px", fontSize: "14px" }} onChange={handleKeyWordChange}
onKeyUp={handleKeyWordChangeKeyUp} style={{ width: "280px", fontSize: "14px" }}
/> onKeyUp={handleKeyWordChangeKeyUp}
<IconButton
type="submit"
className={style.searchButton}
aria-label="search"
size="small"
style={{ padding: "4px" }}
onClick={searchFileList}
>
<SearchIcon
className={style.searchIcon}
style={{ color: "#999" }}
/> />
</IconButton> <IconButton
</div> type="submit"
</div> className={style.searchButton}
<div className={style.projectDataPathAndTabs}> aria-label="search"
<div className={style.projectDataPath}>{showPath}</div> size="small"
<div className={style.projectDataTabsAndBtton}> style={{ padding: "4px" }}
<div className={style.projectDataTabs}> onClick={searchFileList}
<div
className={classnames({
[style.projectDataTab]: true,
[style.projectDataTabActive]: activeTab === 1,
})}
// onClick={() => setActiveTab(1)}
onClick={() => handleChangeListType(1)}
> >
文件 <SearchIcon
className={style.searchIcon}
style={{ color: "#999" }}
/>
</IconButton>
</div>
</div>
<div className={style.projectDataPathAndTabs}>
<div className={style.projectDataPath}>{showPath}</div>
<div className={style.projectDataTabsAndBtton}>
<div className={style.projectDataTabs}>
<div
className={classnames({
[style.projectDataTab]: true,
[style.projectDataTabActive]: activeTab === 1,
})}
// onClick={() => setActiveTab(1)}
onClick={() => handleChangeListType(1)}
>
文件
</div>
<div
className={classnames({
[style.projectDataTab]: true,
[style.projectDataTabActive]: activeTab !== 1,
})}
// onClick={() => setActiveTab(2)}
onClick={() => handleChangeListType(2)}
>
数据集
</div>
</div> </div>
<div <IconButton
className={classnames({ aria-label="refreshIcon"
[style.projectDataTab]: true, size="small"
[style.projectDataTabActive]: activeTab !== 1, onClick={handleRefresh}
})} disabled={!isPass("PROJECT_DATA_REFRESH", "USER")}
// onClick={() => setActiveTab(2)}
onClick={() => handleChangeListType(2)}
> >
数据集 <RefreshIcon />
</div> </IconButton>
</div> </div>
<IconButton
aria-label="refreshIcon"
size="small"
onClick={handleRefresh}
disabled={!isPass("PROJECT_DATA_REFRESH", "USER")}
>
<RefreshIcon />
</IconButton>
</div> </div>
</div> </div>
<Table
footer={false}
rowHover={true}
onRef={tableRef}
nopadding={true}
stickyheader={true}
load={tableLoadding}
initSelected={selectIds}
headCells={versionsHeadCells}
checkboxData={(e: any) => {
hanldeCheckbox(e);
}}
rows={showList.map((item: any, index: number) => ({
...item,
id: `name=${item.name}&index=${index}`,
name: renderName(item),
size: renderSize(item),
mtime: renderMtime(item),
caozuo: renderButtons(item),
}))}
></Table>
{showList.length === 0 && (
<div className={style.noDataBox}>
<img className={style.noDataImg} src={noFile} alt="" />
<span className={style.noDataText}>暂未开启模板</span>
</div>
)}
</div> </div>
<Table {selectIds.length > 1 && (
footer={false} <div className={style.projectDataStickyBox}>
rowHover={true} <Button
onRef={tableRef} color="error"
nopadding={true} variant="outlined"
stickyheader={true} size="small"
load={tableLoadding} style={{ marginRight: "12px" }}
initSelected={selectIds} onClick={handleBatchDelete}
headCells={versionsHeadCells} disabled={!isPass("PROJECT_DATA_DELETE", "USER")}
checkboxData={(e: any) => { >
hanldeCheckbox(e); 批量删除({selectIds.length}
}} </Button>
rows={showList.map((item: any, index: number) => ({ <Button
...item, color="neutral"
id: `name=${item.name}&index=${index}`, variant="contained"
name: renderName(item), size="small"
size: renderSize(item), style={{ marginRight: "24px" }}
mtime: renderMtime(item), onClick={handleBatchMove}
caozuo: renderButtons(item), disabled={!isPass("PROJECT_DATA_MOVE", "USER")}
}))} >
></Table> 批量移动({selectIds.length}
{showList.length === 0 && ( </Button>
<div className={style.noDataBox}>
<img className={style.noDataImg} src={noFile} alt="" />
<span className={style.noDataText}>暂未开启模板</span>
</div> </div>
)} )}
<Dialog
open={deleteDialogOpen}
onClose={handleDeleteDialogClose}
aria-labelledby="提示"
aria-describedby="确认要删除吗"
>
<DialogTitle id="alert-dialog-title">{"提示"}</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
确认要删除“
{currentOperateFile
? currentOperateFile.name
: selectIds.join("”,“")}
”吗?
</DialogContentText>
</DialogContent>
<DialogActions>
<Button
onClick={handleDeleteDialogClose}
color="inherit"
variant="contained"
style={{ color: "#1E2633", backgroundColor: "#fff" }}
size="small"
>
取消
</Button>
<LoadingButton
loading={deleteloading}
onClick={handleDelete}
color="primary"
variant="contained"
size="small"
>
确认
</LoadingButton>
</DialogActions>
</Dialog>
<UpLoaderFile
onRef={UpLoaderFileRef}
path={path}
list={list}
></UpLoaderFile>
<AddFolder
onRef={addFolderRef}
list={list}
path={path}
refresh={handleRefresh}
fileToken={fileToken}
projectId={projectId}
></AddFolder>
<MoveFile
onRef={moveFileRef}
path={path}
fileToken={fileToken}
projectId={projectId}
currentOperateFile={currentOperateFile}
selectIds={selectIds}
refresh={handleRefresh}
activeTab={activeTab}
showList={showList}
></MoveFile>
</div> </div>
{selectIds.length > 1 && ( </ThemeProvider>
<div className={style.projectDataStickyBox}> );
<Button } else {
color="error" return <NoProject />;
variant="outlined" }
size="small"
style={{ marginRight: "12px" }}
onClick={handleBatchDelete}
disabled={!isPass("PROJECT_DATA_DELETE", "USER")}
>
批量删除({selectIds.length}
</Button>
<Button
color="neutral"
variant="contained"
size="small"
style={{ marginRight: "24px" }}
onClick={handleBatchMove}
disabled={!isPass("PROJECT_DATA_MOVE", "USER")}
>
批量移动({selectIds.length}
</Button>
</div>
)}
<Dialog
open={deleteDialogOpen}
onClose={handleDeleteDialogClose}
aria-labelledby="提示"
aria-describedby="确认要删除吗"
>
<DialogTitle id="alert-dialog-title">{"提示"}</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
确认要删除“
{currentOperateFile
? currentOperateFile.name
: selectIds.join("”,“")}
”吗?
</DialogContentText>
</DialogContent>
<DialogActions>
<Button
onClick={handleDeleteDialogClose}
color="inherit"
variant="contained"
style={{ color: "#1E2633", backgroundColor: "#fff" }}
size="small"
>
取消
</Button>
<LoadingButton
loading={deleteloading}
onClick={handleDelete}
color="primary"
variant="contained"
size="small"
>
确认
</LoadingButton>
</DialogActions>
</Dialog>
<UpLoaderFile
onRef={UpLoaderFileRef}
path={path}
list={list}
></UpLoaderFile>
<AddFolder
onRef={addFolderRef}
list={list}
path={path}
refresh={handleRefresh}
fileToken={fileToken}
projectId={projectId}
></AddFolder>
<MoveFile
onRef={moveFileRef}
path={path}
fileToken={fileToken}
projectId={projectId}
currentOperateFile={currentOperateFile}
selectIds={selectIds}
refresh={handleRefresh}
activeTab={activeTab}
showList={showList}
></MoveFile>
</div>
</ThemeProvider>
);
}); });
export default ProjectData; export default ProjectData;
...@@ -28,7 +28,10 @@ import Loading from "@/views/Loading"; ...@@ -28,7 +28,10 @@ import Loading from "@/views/Loading";
import MyDialog from "@/components/mui/MyDialog"; import MyDialog from "@/components/mui/MyDialog";
import { getProjectList } from "../../project"; import { getProjectList } from "../../project";
import { checkIsNumberLetterChinese } from "@/utils/util"; import { checkIsNumberLetterChinese } from "@/utils/util";
import { setFileServerEndPointLocalStorage } from "@/views/Project/project"; import {
setFileServerEndPointLocalStorage,
getFiletokenAccordingToId,
} from "@/views/Project/project";
type zoneIdOption = { type zoneIdOption = {
id: string; id: string;
...@@ -190,8 +193,15 @@ const BaseInfo = observer(() => { ...@@ -190,8 +193,15 @@ const BaseInfo = observer(() => {
localStorage.setItem("fileServerEndPoint", ""); localStorage.setItem("fileServerEndPoint", "");
setProjectInfo({}); setProjectInfo({});
} else { } else {
projectList[0].filetoken = getFiletokenAccordingToId(
projectList[0].id
);
currentProjectStore.changeProject(projectList[0]); currentProjectStore.changeProject(projectList[0]);
setFileServerEndPointLocalStorage(projectList[0].zoneId); setFileServerEndPointLocalStorage(projectList[0].zoneId);
getFiletokenAccordingToId(projectList[0].id).then((res) => {
projectList[0].filetoken = res;
currentProjectStore.changeProject(projectList[0]);
});
setProjectInfo(projectList[0]); setProjectInfo(projectList[0]);
} }
}, },
......
...@@ -8,6 +8,10 @@ import { useMessage } from "@/components/MySnackbar"; ...@@ -8,6 +8,10 @@ import { useMessage } from "@/components/MySnackbar";
import { getProjectList } from "../../project"; import { getProjectList } from "../../project";
import { useStores } from "@/store"; import { useStores } from "@/store";
import { checkIsNumberLetterChinese } from "@/utils/util"; import { checkIsNumberLetterChinese } from "@/utils/util";
import {
setFileServerEndPointLocalStorage,
getFiletokenAccordingToId,
} from "@/views/Project/project";
type zoneIdOption = { type zoneIdOption = {
id: string; id: string;
...@@ -45,6 +49,18 @@ const AddProject = (props: any) => { ...@@ -45,6 +49,18 @@ const AddProject = (props: any) => {
message.success("新建项目成功"); message.success("新建项目成功");
const projectList = await getProjectList(); const projectList = await getProjectList();
currentProjectStore.setProjectList(projectList); currentProjectStore.setProjectList(projectList);
let project: any = {};
projectList.forEach((item: any) => {
if (item.name === name) {
project = { ...item };
}
});
currentProjectStore.changeProject(project);
setFileServerEndPointLocalStorage(project.zoneId);
getFiletokenAccordingToId(project.id).then((res) => {
project.filetoken = res;
currentProjectStore.changeProject(project);
});
} }
}, },
onError: () => { onError: () => {
......
...@@ -7,7 +7,10 @@ import ProjectListPopper from "../ProjectListPopper"; ...@@ -7,7 +7,10 @@ import ProjectListPopper from "../ProjectListPopper";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import AddProject from "../AddProject"; import AddProject from "../AddProject";
import { setFileServerEndPointLocalStorage } from "@/views/Project/project"; import {
setFileServerEndPointLocalStorage,
getFiletokenAccordingToId,
} from "@/views/Project/project";
const CurrentProject = observer(() => { const CurrentProject = observer(() => {
const { currentProjectStore } = useStores(); const { currentProjectStore } = useStores();
...@@ -33,6 +36,10 @@ const CurrentProject = observer(() => { ...@@ -33,6 +36,10 @@ const CurrentProject = observer(() => {
const handleChangeCurrentProject = (project: any) => { const handleChangeCurrentProject = (project: any) => {
currentProjectStore.changeProject(project); currentProjectStore.changeProject(project);
setFileServerEndPointLocalStorage(project.zoneId); setFileServerEndPointLocalStorage(project.zoneId);
getFiletokenAccordingToId(project.id).then((res) => {
project.filetoken = res;
currentProjectStore.changeProject(project);
});
setProjectListOpen(!projectListOpen); setProjectListOpen(!projectListOpen);
}; };
......
import { product, hpczone } from "@/api/project_api"; import { product, hpczone, getDataFileToken } from "@/api/project_api";
export const getProjectList = async () => { export const getProjectList = async () => {
const res = await product({ product: "CADD" }); const res = await product({ product: "CADD" });
...@@ -18,3 +18,14 @@ export const setFileServerEndPointLocalStorage = async (zoneId: string) => { ...@@ -18,3 +18,14 @@ export const setFileServerEndPointLocalStorage = async (zoneId: string) => {
localStorage.setItem("fileServerEndPoint", fileServerEndPoint); localStorage.setItem("fileServerEndPoint", fileServerEndPoint);
} }
}; };
// 根据项目id获取文件token
export const getFiletokenAccordingToId = async (projectId: string) => {
const res = await getDataFileToken({ id: projectId });
console.log(res, "getFiletokenAccordingToId");
return res.data;
// if (res) {
// } else {
// return false;
// }
};
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