2026-01-15 18:01:40 +08:00
|
|
|
import { AnimatePresence, motion } from "motion/react";
|
2026-01-07 13:51:33 +08:00
|
|
|
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";
|
2026-01-05 14:53:49 +08:00
|
|
|
import titleImg from "~/assets/images/map_bi/bottom_utils/title.png";
|
|
|
|
|
import titleOnImg from "~/assets/images/map_bi/bottom_utils/title_on.png";
|
2026-01-07 13:51:33 +08:00
|
|
|
import { branchOfficeUtilsList } from "~/pages/Container/Map/components/BottomUtils/branchOfficeUtilsList";
|
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 {
|
|
|
|
|
deletePeoplePositionPointMittKey,
|
|
|
|
|
resetAllBottomUtilsCheckMittKey,
|
|
|
|
|
resetBottomCurrentIndexMittKey,
|
|
|
|
|
} from "~/pages/Container/Map/js/mittKey";
|
|
|
|
|
import { portUtilsList } from "./portUtilsList";
|
2026-01-15 18:01:40 +08:00
|
|
|
import { useBottomUtilsAnimation } from "./useBottomUtilsAnimation";
|
|
|
|
|
import { useBranchOfficeUtilsAnimation } from "./useBranchOfficeUtilsAnimation";
|
|
|
|
|
import { usePortUtilsAnimation } from "./usePortUtilsAnimation";
|
2026-01-05 14:53:49 +08:00
|
|
|
import "./index.less";
|
|
|
|
|
|
|
|
|
|
function BottomUtils(props) {
|
|
|
|
|
const { currentPort, pureMap, currentBranchOffice, bottomUtilsCurrentIndex } = useContext(Context);
|
|
|
|
|
|
|
|
|
|
const [list, setList] = useState([]);
|
|
|
|
|
|
2026-01-15 18:01:40 +08:00
|
|
|
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",
|
|
|
|
|
);
|
2026-01-05 14:53:49 +08:00
|
|
|
|
|
|
|
|
const resetAllCheck = () => {
|
|
|
|
|
setList((prevList) => {
|
|
|
|
|
return prevList.map(item => ({
|
|
|
|
|
...item,
|
|
|
|
|
list: item.list.map(item1 => ({ ...item1, check: false })),
|
|
|
|
|
}));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-07 13:51:33 +08:00
|
|
|
useEffect(() => {
|
2026-01-15 18:01:40 +08:00
|
|
|
if (bottomUtilsDisplayedMode === "port") {
|
|
|
|
|
setList(portUtilsList);
|
|
|
|
|
}
|
|
|
|
|
else if (bottomUtilsDisplayedMode === "branchOffice") {
|
|
|
|
|
setList(branchOfficeUtilsList);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
setList([]);
|
|
|
|
|
}
|
|
|
|
|
}, [bottomUtilsDisplayedMode]);
|
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(resetBottomCurrentIndexMittKey, () => {
|
|
|
|
|
props.setBottomUtilsCurrentIndex(-1);
|
|
|
|
|
});
|
|
|
|
|
mitt.on(resetAllBottomUtilsCheckMittKey, () => {
|
|
|
|
|
resetAllCheck();
|
|
|
|
|
});
|
|
|
|
|
mitt.on(deletePeoplePositionPointMittKey, () => {
|
|
|
|
|
});
|
2026-01-07 13:51:33 +08:00
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
mitt.off(resetBottomCurrentIndexMittKey);
|
|
|
|
|
mitt.off(resetAllBottomUtilsCheckMittKey);
|
|
|
|
|
mitt.off(deletePeoplePositionPointMittKey);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
2026-01-05 14:53:49 +08:00
|
|
|
|
|
|
|
|
const optionsClick = (index) => {
|
|
|
|
|
props.setBottomUtilsCurrentIndex(bottomUtilsCurrentIndex === index ? -1 : index);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const optionsItemsClick = (index, index1, item, item1) => {
|
|
|
|
|
// 子选项点击处理
|
|
|
|
|
setList((prevList) => {
|
|
|
|
|
const updatedList = [...prevList];
|
|
|
|
|
updatedList[index].list[index1].check = !updatedList[index].list[index1].check;
|
|
|
|
|
return updatedList;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-15 18:01:40 +08:00
|
|
|
const renderPortUtils = () => {
|
|
|
|
|
if (bottomUtilsDisplayedMode === "port") {
|
|
|
|
|
return list.map((item, index) => {
|
|
|
|
|
const isCurrentActive = bottomUtilsCurrentIndex === index;
|
|
|
|
|
const hasActiveChildren = bottomUtilsCurrentIndex !== -1;
|
|
|
|
|
const isAllowClick = hasActiveChildren && !isCurrentActive && portUtilsShouldHideInactive;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<motion.div
|
|
|
|
|
key={index}
|
|
|
|
|
ref={el => (portUtilsOptionRefs.current[index] = el)}
|
|
|
|
|
className="option"
|
|
|
|
|
animate={portUtilsHasInteracted ? portUtilsParentControls[index] : false}
|
|
|
|
|
onClick={() => !portUtilsIsAnimating && !isAllowClick && optionsClick(index)}
|
|
|
|
|
style={{
|
|
|
|
|
cursor: isAllowClick ? "default" : "pointer",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<img src={isCurrentActive ? item.checkImg : item.img} alt="" className="img" />
|
|
|
|
|
<div className="label" style={{ backgroundImage: `url(${isCurrentActive ? titleOnImg : titleImg})` }}>
|
|
|
|
|
{item.label}
|
|
|
|
|
</div>
|
|
|
|
|
{isCurrentActive && (
|
|
|
|
|
<motion.div
|
|
|
|
|
className="child_items"
|
|
|
|
|
animate={portUtilsChildControls}
|
|
|
|
|
initial={{ opacity: 0 }}
|
2026-01-12 16:51:34 +08:00
|
|
|
>
|
2026-01-15 18:01:40 +08:00
|
|
|
{item.list?.map((item1, index1) => {
|
|
|
|
|
return (
|
|
|
|
|
<motion.div
|
2026-01-07 13:51:33 +08:00
|
|
|
key={index1}
|
2026-01-15 18:01:40 +08:00
|
|
|
className="child_item"
|
|
|
|
|
initial={{ opacity: 0 }}
|
|
|
|
|
animate={{ opacity: 1 }}
|
|
|
|
|
transition={{ delay: index1 * portUtilsAnimationConfig.staggerDelay }}
|
2026-01-07 13:51:33 +08:00
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
optionsItemsClick(index, index1, item, item1);
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-01-15 18:01:40 +08:00
|
|
|
<img src={item1.check ? item1.checkImg : item1.img} alt="" className="child_img" />
|
2026-01-07 13:51:33 +08:00
|
|
|
<div className="child_label">{item1.label}</div>
|
2026-01-15 18:01:40 +08:00
|
|
|
</motion.div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</motion.div>
|
|
|
|
|
)}
|
|
|
|
|
</motion.div>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-01-07 13:51:33 +08:00
|
|
|
};
|
2026-01-05 14:53:49 +08:00
|
|
|
|
2026-01-15 18:01:40 +08:00
|
|
|
const renderBranchOfficeUtils = () => {
|
|
|
|
|
if (bottomUtilsDisplayedMode === "branchOffice") {
|
|
|
|
|
return (
|
|
|
|
|
list.map((item, index) => {
|
2026-01-07 13:51:33 +08:00
|
|
|
const isCurrentActive = bottomUtilsCurrentIndex === index;
|
|
|
|
|
return (
|
2026-01-15 18:01:40 +08:00
|
|
|
<div
|
|
|
|
|
key={index}
|
|
|
|
|
className="option"
|
|
|
|
|
style={{ backgroundImage: `url(${isCurrentActive ? bg7 : bg8})` }}
|
|
|
|
|
onClick={() => optionsClick(index)}
|
|
|
|
|
>
|
|
|
|
|
<div className="label">{item.label}</div>
|
|
|
|
|
<AnimatePresence>
|
|
|
|
|
{(isCurrentActive && item.list?.length > 0) && (
|
|
|
|
|
<motion.div className="items" initial="hidden" animate="visible" exit="hidden" variants={branchOfficeUtilsContainerVariants}>
|
|
|
|
|
{item.list?.map((item1, index1) => {
|
|
|
|
|
return (
|
|
|
|
|
<motion.div
|
|
|
|
|
key={index1}
|
|
|
|
|
className={`item ${item1.check ? "active" : ""}`}
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
optionsItemsClick(index, index1, item, item1);
|
|
|
|
|
}}
|
|
|
|
|
variants={branchOfficeUtilsChildItemVariants}
|
|
|
|
|
>
|
|
|
|
|
<div className="child_label">{item1.label}</div>
|
|
|
|
|
</motion.div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</motion.div>
|
|
|
|
|
)}
|
|
|
|
|
</AnimatePresence>
|
2026-01-07 13:51:33 +08:00
|
|
|
</div>
|
|
|
|
|
);
|
2026-01-15 18:01:40 +08:00
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-01-07 13:51:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2026-01-08 11:27:19 +08:00
|
|
|
<div className="map_content_bottom_utils_container">
|
2026-01-15 18:01:40 +08:00
|
|
|
<motion.div className={bottomUtilsDisplayedMode === "port" ? "bottom_utils port" : "bottom_utils branch_office"} animate={bottomUtilsControls}>
|
|
|
|
|
{bottomUtilsIsVisible && (
|
|
|
|
|
<>
|
|
|
|
|
{renderPortUtils()}
|
|
|
|
|
{renderBranchOfficeUtils()}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</motion.div>
|
2026-01-05 14:53:49 +08:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default BottomUtils;
|