import { useContext, useEffect, useState } from "react"; import { CSSTransition, SwitchTransition } from "react-transition-group"; import bg7 from "~/assets/images/map_bi/bottom_utils/bg7.png"; import bg8 from "~/assets/images/map_bi/bottom_utils/bg8.png"; import titleImg from "~/assets/images/map_bi/bottom_utils/title.png"; import titleOnImg from "~/assets/images/map_bi/bottom_utils/title_on.png"; import { branchOfficeUtilsList } from "~/pages/Container/Map/components/BottomUtils/branchOfficeUtilsList"; import { Context } from "~/pages/Container/Map/js/context"; import mitt from "~/pages/Container/Map/js/mitt"; import { changeBottomUtilsAnimationMittKey, changeContentAnimationKeyMittKey, deletePeoplePositionPointMittKey, initBottomUtilsMittKey, resetAllBottomUtilsCheckMittKey, resetBottomCurrentIndexMittKey, } from "~/pages/Container/Map/js/mittKey"; import { portUtilsList } from "./portUtilsList"; import "./index.less"; function BottomUtils(props) { const { currentPort, pureMap, currentBranchOffice, bottomUtilsCurrentIndex } = useContext(Context); const [list, setList] = useState([]); const initList = () => { setList(!currentBranchOffice ? portUtilsList : branchOfficeUtilsList); }; const resetAllCheck = () => { setList((prevList) => { return prevList.map(item => ({ ...item, list: item.list.map(item1 => ({ ...item1, check: false })), })); }); }; useEffect(() => { mitt.on(initBottomUtilsMittKey, () => { initList(); }); return () => { mitt.off(initBottomUtilsMittKey); }; }, [currentBranchOffice]); useEffect(() => { mitt.on(changeBottomUtilsAnimationMittKey, () => { }); mitt.on(resetBottomCurrentIndexMittKey, () => { props.setBottomUtilsCurrentIndex(-1); }); mitt.on(resetAllBottomUtilsCheckMittKey, () => { resetAllCheck(); }); mitt.on(deletePeoplePositionPointMittKey, () => { }); return () => { mitt.off(changeBottomUtilsAnimationMittKey); mitt.off(resetBottomCurrentIndexMittKey); mitt.off(resetAllBottomUtilsCheckMittKey); mitt.off(deletePeoplePositionPointMittKey); }; }, []); const optionsClick = (index) => { props.setBottomUtilsCurrentIndex(bottomUtilsCurrentIndex === index ? -1 : index); mitt.emit(changeContentAnimationKeyMittKey); }; const optionsItemsClick = (index, index1, item, item1) => { // 子选项点击处理 setList((prevList) => { const updatedList = [...prevList]; updatedList[index].list[index1].check = !updatedList[index].list[index1].check; return updatedList; }); }; const renderBranchOfficeUtils = () => { return (
{list.map((item, index) => { const isCurrentActive = bottomUtilsCurrentIndex === index; // const hasActiveChildren = bottomUtilsCurrentIndex !== -1; // if (hasActiveChildren && !isCurrentActive) { // return null; // } return (
optionsClick(index)} >
{item.label}
0} timeout={500} classNames={{ enter: "animate__animated animate__faster", enterActive: "animate__animated animate__faster animate__fadeInUp", exit: "animate__animated animate__faster", exitActive: "animate__animated animate__faster animate__fadeOutDown", }} unmountOnExit >
{item.list?.map((item1, index1) => (
{ e.stopPropagation(); optionsItemsClick(index, index1, item, item1); }} >
{item1.label}
))}
); })}
); }; const renderPortUtils = () => { return (
{list.map((item, index) => { const isCurrentActive = bottomUtilsCurrentIndex === index; const hasActiveChildren = bottomUtilsCurrentIndex !== -1; if (hasActiveChildren && !isCurrentActive) { return null; } return (
optionsClick(index)}>
{item.label}
0} 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 >
{item.list?.map((item1, index1) => (
{ e.stopPropagation(); optionsItemsClick(index, index1, item, item1); }} >
{item1.label}
))}
); })}
); }; const renderUtils = () => { if (pureMap || !currentPort) return (
); return (!currentBranchOffice ? renderPortUtils() : renderBranchOfficeUtils()); }; return (
{renderUtils()}
); } export default BottomUtils;