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

175 lines
5.5 KiB
JavaScript
Raw Normal View History

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,
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 = () => {
2026-01-07 13:51:33 +08:00
setList(!currentBranchOffice ? portUtilsList : branchOfficeUtilsList);
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(() => {
mitt.on(initBottomUtilsMittKey, () => {
initList();
});
return () => {
mitt.off(initBottomUtilsMittKey);
};
}, [currentBranchOffice]);
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-07 13:51:33 +08:00
const renderBranchOfficeUtils = () => {
return (
<div className="bottom_utils branch_office">
{list.map((item, index) => {
const isCurrentActive = bottomUtilsCurrentIndex === index;
// const hasActiveChildren = bottomUtilsCurrentIndex !== -1;
// if (hasActiveChildren && !isCurrentActive) {
// return null;
// }
return (
<div
key={index}
className="option"
style={{ backgroundImage: `url(${isCurrentActive ? bg7 : bg8})` }}
onClick={() => optionsClick(index)}
>
<div className="label">{item.label}</div>
2026-01-08 14:57:25 +08:00
{(isCurrentActive && item.list?.length > 0) && (
2026-01-07 13:51:33 +08:00
<div className="items">
{item.list?.map((item1, index1) => (
<div
key={index1}
className={`item ${item1.check ? "active" : ""}`}
onClick={(e) => {
e.stopPropagation();
optionsItemsClick(index, index1, item, item1);
}}
>
<div className="child_label">{item1.label}</div>
</div>
))}
2026-01-05 14:53:49 +08:00
</div>
2026-01-08 14:57:25 +08:00
)}
2026-01-07 13:51:33 +08:00
</div>
);
})}
</div>
);
};
2026-01-05 14:53:49 +08:00
2026-01-07 13:51:33 +08:00
const renderPortUtils = () => {
return (
<div className="bottom_utils port">
{list.map((item, index) => {
const isCurrentActive = bottomUtilsCurrentIndex === index;
const hasActiveChildren = bottomUtilsCurrentIndex !== -1;
if (hasActiveChildren && !isCurrentActive) {
return null;
}
return (
<div key={index} className="option" onClick={() => optionsClick(index)}>
<img src={isCurrentActive ? item.checkImg : item.img} alt="" className="img" />
<div
className="label"
style={{ backgroundImage: `url(${isCurrentActive ? titleOnImg : titleImg})` }}
>
{item.label}
2026-01-05 14:53:49 +08:00
</div>
2026-01-08 14:57:25 +08:00
{(isCurrentActive && item.list?.length > 0) && (
2026-01-07 13:51:33 +08:00
<div className="items">
{item.list?.map((item1, index1) => (
<div
key={index1}
className="item"
onClick={(e) => {
e.stopPropagation();
optionsItemsClick(index, index1, item, item1);
}}
>
<img src={item1.check ? item1.checkImg : item1.img} alt="" className="child_img" />
<div className="child_label">{item1.label}</div>
</div>
))}
</div>
2026-01-08 14:57:25 +08:00
)}
2026-01-07 13:51:33 +08:00
</div>
);
})}
</div>
);
};
const renderUtils = () => {
if (pureMap || !currentPort)
return (<div></div>);
return (!currentBranchOffice ? renderPortUtils() : renderBranchOfficeUtils());
};
return (
2026-01-08 11:27:19 +08:00
<div className="map_content_bottom_utils_container">
2026-01-08 14:57:25 +08:00
{renderUtils()}
2026-01-05 14:53:49 +08:00
</div>
);
}
export default BottomUtils;