diff --git a/src/pages/Container/Map/components/CenterUtils/index.js b/src/pages/Container/Map/components/CenterUtils/index.js index d6e84e9..1d89206 100644 --- a/src/pages/Container/Map/components/CenterUtils/index.js +++ b/src/pages/Container/Map/components/CenterUtils/index.js @@ -101,26 +101,26 @@ function CenterUtils(props) { {(activeIndex === 0 || activeIndex === 1) && ( -
-
西港区
-
-
人数:33人
-
车辆:33辆
+
+
西港区
+
+
人数:33人
+
车辆:33辆
+
-
)} {(activeIndex === 2 || activeIndex === 1) && ( -
-
东港区
-
-
人数:33人
-
车辆:33辆
+
+
东港区
+
+
人数:33人
+
车辆:33辆
+
-
)} diff --git a/src/pages/Container/Map/components/Content/index.js b/src/pages/Container/Map/components/Content/index.js index 8fc07c1..705bbc8 100644 --- a/src/pages/Container/Map/components/Content/index.js +++ b/src/pages/Container/Map/components/Content/index.js @@ -1,5 +1,5 @@ import { AnimatePresence, motion } from "motion/react"; -import { useContext, useState } from "react"; +import { useContext, useEffect, useState } from "react"; 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"; @@ -49,7 +49,20 @@ function Content(props) { ? branchOfficeUtilsList[bottomUtilsCurrentIndex]?.type || "" : portUtilsList[bottomUtilsCurrentIndex]?.type || ""; const contentKey = `${currentPort}_${currentBranchOffice}_${bottomUtilsCurrentIndex}`; + const pageKey = `${currentPort}_${currentBranchOffice}`; const isPortContent = currentPort === "00003" && !currentBranchOffice; + const [leftButtonKey, setLeftButtonKey] = useState(bottomUtilsCurrentIndex); + const [rightButtonKey, setRightButtonKey] = useState(bottomUtilsCurrentIndex); + const leftAnimationKey = isLeftCollapsed ? leftButtonKey : bottomUtilsCurrentIndex; + const rightAnimationKey = isRightCollapsed ? rightButtonKey : bottomUtilsCurrentIndex; + + // 页面层级直接包含在 animation key 中;底部操作栏变化时,仅展开状态的按钮更新 key。 + useEffect(() => { + if (!isLeftCollapsed) + setLeftButtonKey(bottomUtilsCurrentIndex); + if (!isRightCollapsed) + setRightButtonKey(bottomUtilsCurrentIndex); + }, [bottomUtilsCurrentIndex]); const renderPortContent = () => { const contentMap = { @@ -83,9 +96,10 @@ function Content(props) { return Component ? : null; }; - const renderCollapseButton = ({ side, isCollapsed, setIsCollapsed }) => { + const renderCollapseButton = ({ side, isCollapsed, setIsCollapsed, animationKey }) => { const isPort = isPortContent; const collapsedX = side === "left" ? -465 : 465; + const hiddenX = side === "left" ? -600 : 600; const containerRotation = !isPort && side === "right" ? 180 : 0; const imageRotation = isPort ? (isCollapsed ? 180 : 0) @@ -93,10 +107,22 @@ function Content(props) { return ( setIsCollapsed(value => !value)} > - {!pureMap && isPortContent && renderCollapseButton({ - side: "left", - isCollapsed: isLeftCollapsed, - setIsCollapsed: setIsLeftCollapsed, - })} - - {!pureMap && currentBranchOffice && ( - <> - {bottomUtilsCurrentType !== "camera" && renderCollapseButton({ + + {!pureMap && (isPortContent || (currentBranchOffice && (bottomUtilsCurrentType !== "camera" || isLeftCollapsed))) + && renderCollapseButton({ side: "left", isCollapsed: isLeftCollapsed, setIsCollapsed: setIsLeftCollapsed, + animationKey: `left_${pageKey}_${leftAnimationKey}`, })} - {bottomUtilsCurrentIndex === -1 && renderCollapseButton({ + + + + {!pureMap && currentBranchOffice && bottomUtilsCurrentIndex === -1 + && renderCollapseButton({ side: "right", isCollapsed: isRightCollapsed, setIsCollapsed: setIsRightCollapsed, + animationKey: `right_${pageKey}_${rightAnimationKey}`, })} - - )} +
); }