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,6 +610,7 @@ const ProjectData = observer(() => { ...@@ -601,6 +610,7 @@ const ProjectData = observer(() => {
} }
}, [path]); }, [path]);
if (currentProjectStore.currentProjectInfo.name) {
return ( return (
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
<div className={style.projectData}> <div className={style.projectData}>
...@@ -812,6 +822,9 @@ const ProjectData = observer(() => { ...@@ -812,6 +822,9 @@ const ProjectData = observer(() => {
</div> </div>
</ThemeProvider> </ThemeProvider>
); );
} else {
return <NoProject />;
}
}); });
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