zcloud-gbs-bi-react/src/pages/Container/Map/components/RightUtils/index.js

197 lines
6.3 KiB
JavaScript
Raw Normal View History

2026-01-05 14:53:49 +08:00
import { message } from "antd";
2026-01-07 13:51:33 +08:00
import { useContext, useEffect, useState } from "react";
import { CSSTransition, SwitchTransition } from "react-transition-group";
import tooltipImg2 from "~/assets/images/map_bi/right_utils/branch_office/bg11.png";
import buttonBg from "~/assets/images/map_bi/right_utils/branch_office/button.png";
import tooltipImg1 from "~/assets/images/map_bi/right_utils/port/tooltip.png";
2026-01-05 14:53:49 +08:00
import { Context } from "~/pages/Container/Map/js/context";
import mitt from "~/pages/Container/Map/js/mitt";
import {
changeBottomUtilsAnimationMittKey,
changeContentAnimationKeyMittKey,
changePeopleTrajectorySelectVisibleMittKey,
clickBackMittKey,
clickMarkPointMittKey,
deletePeoplePositionPointMittKey,
2026-01-07 13:51:33 +08:00
initRightUtilsMittKey,
2026-01-05 14:53:49 +08:00
resetAllBottomUtilsCheckMittKey,
} from "~/pages/Container/Map/js/mittKey";
2026-01-07 13:51:33 +08:00
import { branchOfficeUtilsList } from "./branchOfficeUtilsList";
import { portUtilsList } from "./portUtilsList";
2026-01-05 14:53:49 +08:00
import "./index.less";
function RightUtils(props) {
2026-01-07 13:51:33 +08:00
const { currentPort, mapMethods, pureMap, currentBranchOffice } = useContext(Context);
2026-01-05 14:53:49 +08:00
2026-01-07 13:51:33 +08:00
const [list, setList] = useState(portUtilsList);
const [isShowChildLevel, setIsShowChildLevel] = useState(true);
2026-01-05 14:53:49 +08:00
2026-01-07 13:51:33 +08:00
useEffect(() => {
mitt.on(initRightUtilsMittKey, () => {
mapMethods.current?.removeFourColorDiagram();
mapMethods.current?.removeWall();
setList(!currentBranchOffice ? portUtilsList : branchOfficeUtilsList);
});
2026-01-05 14:53:49 +08:00
2026-01-07 13:51:33 +08:00
return () => {
mitt.off(initRightUtilsMittKey);
};
}, [currentBranchOffice]);
2026-01-05 14:53:49 +08:00
2026-01-07 13:51:33 +08:00
useEffect(() => {
2026-01-05 14:53:49 +08:00
mitt.on(clickBackMittKey, () => {
setList(list.map((item, index) => index === 7 || index === 8 ? { ...item, check: false } : item));
});
return () => {
mitt.off(clickBackMittKey);
};
2026-01-07 13:51:33 +08:00
}, []);
2026-01-05 14:53:49 +08:00
useEffect(() => {
setList(list.map((item, index) => index === 1 ? { ...item, check: props.isFullscreen } : item));
}, [props.isFullscreen]);
2026-01-06 13:33:01 +08:00
const clickRightTools = (index, type) => {
2026-01-05 14:53:49 +08:00
let check;
2026-01-07 13:51:33 +08:00
if (list[index].check !== undefined) {
2026-01-05 14:53:49 +08:00
check = !list[index].check;
setList(list.map((item, i) => index === i ? { ...item, check: !item.check } : item));
}
2026-01-06 13:33:01 +08:00
switch (type) {
case "back":
2026-01-05 14:53:49 +08:00
// router.push("/");
break;
2026-01-06 13:33:01 +08:00
case "full":
2026-01-05 14:53:49 +08:00
props.toggleFullscreen();
break;
2026-01-06 13:33:01 +08:00
case "return":
2026-01-05 14:53:49 +08:00
mapMethods.current.returnCurrentCenterPoint();
break;
2026-01-06 13:33:01 +08:00
case "scene":
2026-01-05 14:53:49 +08:00
mapMethods.current.changeSceneMode(check ? "2d" : "3d");
break;
2026-01-06 13:33:01 +08:00
case "del":
2026-01-05 14:53:49 +08:00
mapMethods.current.removeMarkPoint();
mitt.emit(resetAllBottomUtilsCheckMittKey);
mitt.emit(deletePeoplePositionPointMittKey);
mitt.emit(changePeopleTrajectorySelectVisibleMittKey, false);
break;
2026-01-06 13:33:01 +08:00
case "pureMap":
2026-01-05 14:53:49 +08:00
props.setPureMap(!pureMap);
mitt.emit(changeBottomUtilsAnimationMittKey);
mitt.emit(changeContentAnimationKeyMittKey);
break;
2026-01-06 13:33:01 +08:00
case "weather":
2026-01-05 14:53:49 +08:00
mitt.emit(clickMarkPointMittKey, {
mapType: "_右侧_METEOROLOGICAL",
});
break;
2026-01-06 13:33:01 +08:00
case "fourColor":
2026-01-05 14:53:49 +08:00
if (!currentPort) {
message.warning("请选择要查看的港口");
setList(list.map((item, i) => index === i ? { ...item, check: false } : item));
return;
}
if (check) {
mapMethods.current.addFourColorDiagram(
currentPort,
2026-01-07 13:51:33 +08:00
currentBranchOffice,
2026-01-05 14:53:49 +08:00
);
}
else {
mapMethods.current.removeFourColorDiagram();
}
break;
2026-01-06 13:33:01 +08:00
case "wall":
2026-01-05 14:53:49 +08:00
if (!currentPort) {
message.warning("请选择要查看的港口");
setList(list.map((item, i) => index === i ? { ...item, check: false } : item));
return;
}
if (check)
2026-01-07 13:51:33 +08:00
mapMethods.current.addWall(currentPort, currentBranchOffice);
2026-01-05 14:53:49 +08:00
else mapMethods.current.removeWall();
break;
}
};
2026-01-07 13:51:33 +08:00
const renderPortUtils = () => {
return (
<div className="right_utils port">
{
list.map((item, index) => (
<div
key={index}
className="option"
onClick={() => clickRightTools(index, item.type)}
>
<div style={{ backgroundImage: `url(${tooltipImg1})` }} className="tooltip">{item.label}</div>
<img src={item.check ? item.checkImg : item.img} alt="" />
</div>
))
}
</div>
);
};
const renderBranchOfficeUtils = () => {
return (
<div className="right_utils branch_office">
<CSSTransition
in={isShowChildLevel}
timeout={500}
classNames={{
enter: "animate__animated",
enterActive: "animate__animated animate__fadeInUp",
exit: "animate__animated",
exitActive: "animate__animated animate__fadeOutDown",
}}
unmountOnExit
>
<div className="options">
{
list.map((item, index) => (
<div
key={index}
className={`option ${item.check ? "active" : ""}`}
onClick={() => clickRightTools(index, item.type)}
>
<div style={{ backgroundImage: `url(${tooltipImg2})` }} className="tooltip">{item.label}</div>
<img src={item.img} alt="" />
</div>
))
}
</div>
</CSSTransition>
<div className={`bg ${isShowChildLevel ? "active" : ""}`} onClick={() => setIsShowChildLevel(!isShowChildLevel)}>
<img src={buttonBg} alt="" />
</div>
</div>
);
};
2026-01-05 14:53:49 +08:00
return (
<div className="right_utils_container">
2026-01-07 13:51:33 +08:00
<SwitchTransition>
<CSSTransition
timeout={1000}
classNames={{
enter: "animate__animated",
enterActive: `animate__animated ${!currentBranchOffice ? "animate__fadeInRight" : "animate__fadeInUp"}`,
exit: "animate__animated",
exitActive: `animate__animated ${!currentBranchOffice ? "animate__fadeOutRight" : "animate__fadeOutDown"}`,
}}
unmountOnExit
key={currentBranchOffice || 1}
>
{!currentBranchOffice ? renderPortUtils() : renderBranchOfficeUtils()}
</CSSTransition>
</SwitchTransition>
2026-01-05 14:53:49 +08:00
</div>
);
}
export default RightUtils;