import { produce } from "immer"; import { AnimatePresence, motion } from "motion/react"; import { useContext, useEffect, useState } from "react"; 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 { deletePeoplePositionPointMittKey, resetAllBottomUtilsCheckMittKey, resetBottomCurrentIndexMittKey, } from "~/pages/Container/Map/js/mittKey"; import { portUtilsList } from "./portUtilsList"; import { useBottomUtilsAnimation } from "./useBottomUtilsAnimation"; import { useBranchOfficeUtilsAnimation } from "./useBranchOfficeUtilsAnimation"; import { usePortUtilsAnimation } from "./usePortUtilsAnimation"; import "./index.less"; function BottomUtils(props) { const { currentPort, pureMap, currentBranchOffice, bottomUtilsCurrentIndex } = useContext(Context); const [list, setList] = useState([]); const { controls: bottomUtilsControls, displayedMode: bottomUtilsDisplayedMode, isVisible: bottomUtilsIsVisible, } = useBottomUtilsAnimation( !pureMap && currentPort && !currentBranchOffice, !pureMap && currentPort && currentBranchOffice, ); const { containerVariants: branchOfficeUtilsContainerVariants, itemVariants: branchOfficeUtilsChildItemVariants, } = useBranchOfficeUtilsAnimation(); const { parentControls: portUtilsParentControls, childControls: portUtilsChildControls, optionRefs: portUtilsOptionRefs, isAnimating: portUtilsIsAnimating, hasInteracted: portUtilsHasInteracted, shouldHideInactive: portUtilsShouldHideInactive, animationConfig: portUtilsAnimationConfig, } = usePortUtilsAnimation( portUtilsList.length, bottomUtilsCurrentIndex, bottomUtilsDisplayedMode === "port", ); const resetAllCheck = () => { setList(produce((draft) => { draft.forEach((item) => { item.list.forEach((item1) => { item1.check = false; }); }); })); }; useEffect(() => { if (bottomUtilsDisplayedMode === "port") { setList(portUtilsList); } else if (bottomUtilsDisplayedMode === "branchOffice") { setList(branchOfficeUtilsList); } else { setList([]); } }, [bottomUtilsDisplayedMode]); useEffect(() => { mitt.on(resetBottomCurrentIndexMittKey, () => { props.setBottomUtilsCurrentIndex(-1); }); mitt.on(resetAllBottomUtilsCheckMittKey, () => { resetAllCheck(); }); mitt.on(deletePeoplePositionPointMittKey, () => { }); return () => { mitt.off(resetBottomCurrentIndexMittKey); mitt.off(resetAllBottomUtilsCheckMittKey); mitt.off(deletePeoplePositionPointMittKey); }; }, []); const optionsClick = (index) => { props.setBottomUtilsCurrentIndex(bottomUtilsCurrentIndex === index ? -1 : index); }; const optionsItemsClick = (index, index1, item, item1) => { // 子选项点击处理 setList(produce((draft) => { draft[index].list[index1].check = !draft[index].list[index1].check; })); }; const renderPortUtils = () => { if (bottomUtilsDisplayedMode === "port") { return list.map((item, index) => { const isCurrentActive = bottomUtilsCurrentIndex === index; const hasActiveChildren = bottomUtilsCurrentIndex !== -1; const isAllowClick = hasActiveChildren && !isCurrentActive && portUtilsShouldHideInactive; return ( (portUtilsOptionRefs.current[index] = el)} className="option" animate={portUtilsHasInteracted ? portUtilsParentControls[index] : false} onClick={() => !portUtilsIsAnimating && !isAllowClick && optionsClick(index)} style={{ cursor: isAllowClick ? "default" : "pointer", zIndex: isAllowClick ? -1 : 0, }} >
{item.label}
{isCurrentActive && ( {item.list?.map((item1, index1) => { return ( { e.stopPropagation(); optionsItemsClick(index, index1, item, item1); }} >
{item1.label}
); })}
)}
); }); } }; const renderBranchOfficeUtils = () => { if (bottomUtilsDisplayedMode === "branchOffice") { return ( list.map((item, index) => { const isCurrentActive = bottomUtilsCurrentIndex === index; return (
optionsClick(index)} >
{item.label}
{(isCurrentActive && item.list?.length > 0) && ( {item.list?.map((item1, index1) => { return ( { e.stopPropagation(); optionsItemsClick(index, index1, item, item1); }} variants={branchOfficeUtilsChildItemVariants} >
{item1.label}
); })}
)}
); }) ); } }; return (
{bottomUtilsIsVisible && ( <> {renderPortUtils()} {renderBranchOfficeUtils()} )}
); } export default BottomUtils;