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

153 lines
4.7 KiB
JavaScript
Raw Normal View History

2026-01-05 14:53:49 +08:00
import { useMount } from "ahooks";
import { message } from "antd";
import { useContext, useEffect, useRef, useState } from "react";
import { CSSTransition } from "react-transition-group";
import tooltipImg from "~/assets/images/map_bi/right_utils/tooltip.png";
import { Context } from "~/pages/Container/Map/js/context";
import mitt from "~/pages/Container/Map/js/mitt";
import {
changeBottomUtilsAnimationMittKey,
changeContentAnimationKeyMittKey,
changePeopleTrajectorySelectVisibleMittKey,
clickBackMittKey,
clickBranchOfficePointMittKey,
clickMarkPointMittKey,
deletePeoplePositionPointMittKey,
resetAllBottomUtilsCheckMittKey,
} from "~/pages/Container/Map/js/mittKey";
import { utilsList } from "./utilsList";
import "./index.less";
function RightUtils(props) {
const { currentPort, mapMethods, pureMap } = useContext(Context);
const [list, setList] = useState(utilsList);
const [animationKey, setAnimationKey] = useState(0);
const corpinfoId = useRef("");
useMount(() => {
setAnimationKey(Math.random());
mitt.on(clickBackMittKey, () => {
setList(list.map((item, index) => index === 7 || index === 8 ? { ...item, check: false } : item));
});
mitt.on(clickBranchOfficePointMittKey, (data) => {
mapMethods.current.removeFourColorDiagram();
mapMethods.current.removeWall();
setList(list.map((item, index) => index === 7 || index === 8 ? { ...item, check: false } : item));
corpinfoId.current = data.corpinfoId ?? "";
});
return () => {
mitt.off(clickBackMittKey);
mitt.off(clickBranchOfficePointMittKey);
};
});
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;
if (list[index].check !== undefined && list[index].checkImg) {
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,
corpinfoId.current,
);
}
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)
mapMethods.current.addWall(currentPort, corpinfoId.current);
else mapMethods.current.removeWall();
break;
}
};
return (
<div className="right_utils_container">
<CSSTransition
in={animationKey !== 0}
timeout={1000}
classNames={{
enter: "animate__animated",
enterActive: "animate__animated animate__fadeInRight",
exit: "animate__animated",
exitActive: "animate__animated animate__fadeOutRight",
}}
unmountOnExit
>
<div className="right_utils">
{
list.map((item, index) => (
<div
key={index}
className="option"
2026-01-06 13:33:01 +08:00
onClick={() => clickRightTools(index, item.type)}
2026-01-05 14:53:49 +08:00
>
<div style={{ backgroundImage: `url(${tooltipImg})` }} className="tooltip">{item.label}</div>
<img src={item.check ? item.checkImg : item.img} alt="" />
</div>
))
}
</div>
</CSSTransition>
</div>
);
}
export default RightUtils;