Commit 1eef0ac1 authored by chenshouchao's avatar chenshouchao

refactor: 优化代码结构 增加一些注释

parent c68589b0
import { Box, List } from "@mui/material"; import { Box, List } from "@mui/material";
// import CurrentProject from "./CurrentProject";
import CurrentProject from "../Project/components/CurrentProject"; import CurrentProject from "../Project/components/CurrentProject";
import React from "react"; import React from "react";
import { Outlet, useNavigate } from "react-router-dom"; import { Outlet, useNavigate } from "react-router-dom";
......
.loadingBox {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
height: 300px;
}
.projectInfoList { .projectInfoList {
background-color: #fff; background-color: #fff;
position: relative; position: relative;
......
...@@ -55,6 +55,8 @@ const BaseInfo = observer(() => { ...@@ -55,6 +55,8 @@ const BaseInfo = observer(() => {
}, [currentProjectStore.currentProjectInfo.id, run]); }, [currentProjectStore.currentProjectInfo.id, run]);
const [zoneIdMap, setZoneIdMap] = useState<Map<string, string>>(new Map()); const [zoneIdMap, setZoneIdMap] = useState<Map<string, string>>(new Map());
const [zoneIdOptions, setZoneIdOptions] = useState<Array<zoneIdOption>>([]); const [zoneIdOptions, setZoneIdOptions] = useState<Array<zoneIdOption>>([]);
// 获取计算区信息
const { run: getZone } = useMyRequest(hpczone, { const { run: getZone } = useMyRequest(hpczone, {
onSuccess: (result: any) => { onSuccess: (result: any) => {
setZoneIdOptions(result); setZoneIdOptions(result);
...@@ -65,9 +67,12 @@ const BaseInfo = observer(() => { ...@@ -65,9 +67,12 @@ const BaseInfo = observer(() => {
setZoneIdMap(zoneMap); setZoneIdMap(zoneMap);
}, },
}); });
useEffect(() => { useEffect(() => {
getZone(); getZone();
}, [getZone]); }, [getZone]);
// 项目信息展示数据转换
const infoList = useMemo(() => { const infoList = useMemo(() => {
return [ return [
{ {
...@@ -112,13 +117,14 @@ const BaseInfo = observer(() => { ...@@ -112,13 +117,14 @@ const BaseInfo = observer(() => {
{ {
onSuccess: async (result: any) => { onSuccess: async (result: any) => {
message.success("修改成功"); message.success("修改成功");
const projectList = await getProjectList() const projectList = await getProjectList();
currentProjectStore.setProjectList(projectList) currentProjectStore.setProjectList(projectList);
currentProjectStore.changeProject(projectInfo) currentProjectStore.changeProject(projectInfo);
}, },
} }
); );
// 修改项目
const handleClickUpdate = () => { const handleClickUpdate = () => {
if (projectInfo.name) { if (projectInfo.name) {
if (reg.test(projectInfo.name)) { if (reg.test(projectInfo.name)) {
...@@ -139,15 +145,16 @@ const BaseInfo = observer(() => { ...@@ -139,15 +145,16 @@ const BaseInfo = observer(() => {
onSuccess: async (result: any) => { onSuccess: async (result: any) => {
message.success("删除成功"); message.success("删除成功");
DialogRef.current.handleClose(); DialogRef.current.handleClose();
const projectList = await getProjectList() const projectList = await getProjectList();
currentProjectStore.setProjectList(projectList) currentProjectStore.setProjectList(projectList);
currentProjectStore.changeProject(projectList[0]) currentProjectStore.changeProject(projectList[0]);
setProjectInfo(projectList[0]) setProjectInfo(projectList[0]);
}, },
} }
); );
let DialogRef: any = React.createRef(); let DialogRef: any = React.createRef();
// 显示删除弹窗
const handleClickDelete = () => { const handleClickDelete = () => {
DialogRef.current.handleClickOpen(); DialogRef.current.handleClickOpen();
}; };
...@@ -156,7 +163,8 @@ const BaseInfo = observer(() => { ...@@ -156,7 +163,8 @@ const BaseInfo = observer(() => {
setDeleteProjectName(e.target.value); setDeleteProjectName(e.target.value);
}; };
const handleSubmit = () => { // 删除项目
const handleSubmitDelete = () => {
if ( if (
deleteProjectName === toJS(currentProjectStore.currentProjectInfo.name) deleteProjectName === toJS(currentProjectStore.currentProjectInfo.name)
) { ) {
...@@ -166,11 +174,17 @@ const BaseInfo = observer(() => { ...@@ -166,11 +174,17 @@ const BaseInfo = observer(() => {
} }
}; };
// return <Loading></Loading>; if (loading) {
if (currentUserName === projectInfo.owner) { return (
<div className={style.loadingBox}>
<Loading />
</div>
);
} else if (currentUserName !== projectInfo.owner) {
return <InformationDisplay infoList={infoList} />;
} else {
return ( return (
<div className={style.projectInfoList}> <div className={style.projectInfoList}>
{loading && <Loading></Loading>}
<div className={style.projectInfoListLi}> <div className={style.projectInfoListLi}>
<div <div
className={classnames({ className={classnames({
...@@ -270,7 +284,7 @@ const BaseInfo = observer(() => { ...@@ -270,7 +284,7 @@ const BaseInfo = observer(() => {
</Button> </Button>
</div> </div>
<MyDialog <MyDialog
handleSubmit={handleSubmit} handleSubmit={handleSubmitDelete}
onRef={DialogRef} onRef={DialogRef}
title="删除项目" title="删除项目"
submitloading={deleteLoading} submitloading={deleteLoading}
...@@ -301,12 +315,6 @@ const BaseInfo = observer(() => { ...@@ -301,12 +315,6 @@ const BaseInfo = observer(() => {
</MyDialog> </MyDialog>
</div> </div>
); );
} else {
return loading ? (
<Loading></Loading>
) : (
<InformationDisplay infoList={infoList} />
);
} }
}); });
......
...@@ -16,8 +16,8 @@ type zoneIdOption = { ...@@ -16,8 +16,8 @@ type zoneIdOption = {
}; };
const AddProject = (props: any) => { const AddProject = (props: any) => {
const { currentProjectStore } = useStores() const { currentProjectStore } = useStores();
const message = useMessage() const message = useMessage();
let DialogRef: any = React.createRef(); let DialogRef: any = React.createRef();
useImperativeHandle(props.onRef, () => { useImperativeHandle(props.onRef, () => {
return { return {
...@@ -27,6 +27,7 @@ const AddProject = (props: any) => { ...@@ -27,6 +27,7 @@ const AddProject = (props: any) => {
const [zoneId, setZoneId] = useState(""); const [zoneId, setZoneId] = useState("");
const [zoneIdOptions, setZoneIdOptions] = useState<Array<zoneIdOption>>([]); const [zoneIdOptions, setZoneIdOptions] = useState<Array<zoneIdOption>>([]);
// 设置计算区
const { run } = useMyRequest(hpczone, { const { run } = useMyRequest(hpczone, {
onSuccess: (result: any) => { onSuccess: (result: any) => {
setZoneIdOptions(result); setZoneIdOptions(result);
...@@ -42,9 +43,9 @@ const AddProject = (props: any) => { ...@@ -42,9 +43,9 @@ const AddProject = (props: any) => {
if (result.data) { if (result.data) {
setSubmitloading(false); setSubmitloading(false);
DialogRef.current.handleClose(); DialogRef.current.handleClose();
message.success('新建项目成功') message.success("新建项目成功");
const projectList = await getProjectList() const projectList = await getProjectList();
currentProjectStore.setProjectList(projectList) currentProjectStore.setProjectList(projectList);
} }
}, },
onError: () => { onError: () => {
...@@ -70,6 +71,7 @@ const AddProject = (props: any) => { ...@@ -70,6 +71,7 @@ const AddProject = (props: any) => {
error: false, error: false,
help: "", help: "",
}); });
const checkName = (name: string) => { const checkName = (name: string) => {
if (name) { if (name) {
if (name.length > 30) { if (name.length > 30) {
...@@ -95,6 +97,7 @@ const AddProject = (props: any) => { ...@@ -95,6 +97,7 @@ const AddProject = (props: any) => {
}); });
} }
}; };
const handleNameChange = (e: any) => { const handleNameChange = (e: any) => {
const name = e.target.value; const name = e.target.value;
setName(name); setName(name);
...@@ -104,6 +107,7 @@ const AddProject = (props: any) => { ...@@ -104,6 +107,7 @@ const AddProject = (props: any) => {
const handleZoneIdChange = (e: any) => { const handleZoneIdChange = (e: any) => {
setZoneId(e.target.value); setZoneId(e.target.value);
}; };
const handleDescChange = (e: any) => { const handleDescChange = (e: any) => {
const desc = e.target.value; const desc = e.target.value;
setDesc(desc); setDesc(desc);
...@@ -135,8 +139,8 @@ const AddProject = (props: any) => { ...@@ -135,8 +139,8 @@ const AddProject = (props: any) => {
}; };
const handleFromBox = (e: React.SyntheticEvent) => { const handleFromBox = (e: React.SyntheticEvent) => {
e.nativeEvent.stopImmediatePropagation() e.nativeEvent.stopImmediatePropagation();
} };
return ( return (
<MyDialog <MyDialog
......
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