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

139 lines
5.0 KiB
JavaScript
Raw Normal View History

2026-01-07 13:51:33 +08:00
import { useContext, useEffect, useState } from "react";
2026-01-05 14:53:49 +08:00
import { CSSTransition, SwitchTransition } from "react-transition-group";
2026-01-07 16:38:01 +08:00
import collapseMenuImg1 from "~/assets/images/map_bi/content/collapse_menu1.png";
import collapseMenuImg2 from "~/assets/images/map_bi/content/collapse_menu2.png";
import collapseMenuBg1 from "~/assets/images/map_bi/content/collapse_menu_bg1.png";
import collapseMenuBg2 from "~/assets/images/map_bi/content/collapse_menu_bg2.png";
import { branchOfficeUtilsList } from "~/pages/Container/Map/components/BottomUtils/branchOfficeUtilsList";
2026-01-06 13:33:01 +08:00
import { portUtilsList } from "~/pages/Container/Map/components/BottomUtils/portUtilsList";
2026-01-07 16:38:01 +08:00
import BranchOfficeIndex from "~/pages/Container/Map/components/Content/branchOffice/Index";
import IndexInfo from "~/pages/Container/Map/components/Content/IndexInfo";
2026-01-07 14:03:14 +08:00
import PortFengBi from "~/pages/Container/Map/components/Content/port/FengBi";
2026-01-07 16:38:01 +08:00
import PortIndex from "~/pages/Container/Map/components/Content/port/Index";
2026-01-07 14:03:14 +08:00
import PortMenJin from "~/pages/Container/Map/components/Content/port/MenJin";
import PortQiXiang from "~/pages/Container/Map/components/Content/port/QiXiang";
import PortRenYuan from "~/pages/Container/Map/components/Content/port/RenYuan";
import PortWeiXian from "~/pages/Container/Map/components/Content/port/WeiXian";
import PortXiaoFang from "~/pages/Container/Map/components/Content/port/XiaoFang";
import PortZhongDian from "~/pages/Container/Map/components/Content/port/ZhongDian";
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 { changeContentAnimationKeyMittKey } from "~/pages/Container/Map/js/mittKey";
import "./index.less";
function Content() {
const { currentPort, currentBranchOffice, pureMap, bottomUtilsCurrentIndex } = useContext(Context);
const [animationKey, setAnimationKey] = useState(0);
const [collapse, setCollapse] = useState(false);
2026-01-07 13:51:33 +08:00
useEffect(() => {
2026-01-05 14:53:49 +08:00
setAnimationKey(Math.random());
mitt.on(changeContentAnimationKeyMittKey, () => {
setAnimationKey(Math.random());
setCollapse(false);
});
2026-01-07 13:51:33 +08:00
return () => {
mitt.off(changeContentAnimationKeyMittKey);
};
}, []);
2026-01-05 14:53:49 +08:00
const onChangeCollapse = () => {
setAnimationKey(Math.random());
setCollapse(!collapse);
};
const renderPortContent = () => {
2026-01-07 16:38:01 +08:00
const bottomUtilsCurrentType = bottomUtilsCurrentIndex !== -1 ? portUtilsList[bottomUtilsCurrentIndex].type : "";
if (bottomUtilsCurrentType === "" || bottomUtilsCurrentType === "camera")
return <PortIndex />;
if (bottomUtilsCurrentType === "door")
return <PortMenJin />;
if (bottomUtilsCurrentType === "fire")
return <PortXiaoFang />;
if (bottomUtilsCurrentType === "danger")
return <PortWeiXian />;
if (bottomUtilsCurrentType === "weather")
return <PortQiXiang />;
if (bottomUtilsCurrentType === "people")
return <PortRenYuan />;
if (bottomUtilsCurrentType === "project")
return <PortZhongDian />;
if (bottomUtilsCurrentType === "closedArea")
return <PortFengBi />;
};
const renderBranchOfficeContent = () => {
const bottomUtilsCurrentType = bottomUtilsCurrentIndex !== -1 ? branchOfficeUtilsList[bottomUtilsCurrentIndex].type : "";
if (bottomUtilsCurrentType === "")
return <BranchOfficeIndex />;
2026-01-05 14:53:49 +08:00
};
const renderContent = () => {
if (pureMap || collapse)
2026-01-07 13:51:33 +08:00
return null;
2026-01-05 14:53:49 +08:00
return (
<div className="map_content_container__content">
{!currentPort && <IndexInfo />}
2026-01-07 16:38:01 +08:00
{(currentPort === "00003" && !currentBranchOffice) && renderPortContent()}
{currentBranchOffice && renderBranchOfficeContent()}
2026-01-05 14:53:49 +08:00
</div>
);
};
2026-01-07 13:51:33 +08:00
const renderCollapseMenu = () => {
if (pureMap)
return null;
2026-01-07 16:38:01 +08:00
if (currentPort === "00003" && !currentBranchOffice) {
return (
<div
className={`collapse_menu port ${collapse ? "active" : ""}`}
style={{ backgroundImage: `url(${collapseMenuBg1})` }}
onClick={onChangeCollapse}
>
<img src={collapseMenuImg1} alt="" />
</div>
);
}
if (currentBranchOffice) {
2026-01-07 13:51:33 +08:00
return (
<div
2026-01-07 16:38:01 +08:00
className={`collapse_menu branch_office ${collapse ? "active" : ""}`}
style={{ backgroundImage: `url(${collapseMenuBg2})` }}
2026-01-07 13:51:33 +08:00
onClick={onChangeCollapse}
>
2026-01-07 16:38:01 +08:00
<img src={collapseMenuImg2} alt="" />
2026-01-07 13:51:33 +08:00
</div>
);
}
};
2026-01-05 14:53:49 +08:00
return (
<div className="map_content_container">
<SwitchTransition>
<CSSTransition
timeout={500}
classNames={{
enter: "animate__animated animate__faster",
enterActive: "animate__animated animate__faster animate__fadeInLeft",
exit: "animate__animated animate__faster",
exitActive: "animate__animated animate__faster animate__fadeOutLeft",
}}
unmountOnExit
key={animationKey}
>
<div>
{renderContent()}
2026-01-07 13:51:33 +08:00
{renderCollapseMenu()}
2026-01-05 14:53:49 +08:00
</div>
</CSSTransition>
</SwitchTransition>
</div>
);
}
export default Content;