zy-react-library/src/components/Page/index.js

77 lines
2.0 KiB
JavaScript
Raw Normal View History

2025-12-24 15:45:07 +08:00
import { Button, Space } from "antd";
2025-12-26 11:49:46 +08:00
import { useEffect, useState } from "react";
2025-12-24 15:45:07 +08:00
import HeaderBack from "../HeaderBack";
/**
* 页面布局组件
*/
function Page(props) {
const {
headerTitle,
history,
isShowHeader = true,
headerPrevious = true,
isShowFooter = true,
isShowAllAction = true,
backButtonText = "关闭",
2025-12-24 16:33:09 +08:00
contentPadding = "20px",
2025-12-24 15:45:07 +08:00
customActionButtons,
extraActionButtons,
} = props;
2025-12-26 11:49:46 +08:00
const [pageWidth, setPageWidth] = useState(window.innerWidth);
const getPageWidth = () => {
const pageDom = document.querySelector("#page");
if (!pageDom)
return;
setPageWidth(pageDom.offsetWidth);
};
useEffect(() => {
const timer = setTimeout(() => {
getPageWidth();
}, 0);
2025-12-26 13:50:59 +08:00
if (isShowAllAction && isShowFooter) {
window.addEventListener("resize", getPageWidth);
}
2025-12-26 11:49:46 +08:00
return () => {
2025-12-26 13:50:59 +08:00
if (isShowAllAction && isShowFooter) {
window.removeEventListener("resize", getPageWidth);
}
2025-12-26 11:49:46 +08:00
clearTimeout(timer);
};
2025-12-26 13:50:59 +08:00
}, [isShowAllAction, isShowFooter]);
2025-12-26 11:49:46 +08:00
2025-12-24 15:45:07 +08:00
return (
2025-12-26 11:49:46 +08:00
<div className="page" id="page">
2025-12-24 15:45:07 +08:00
{(isShowAllAction && isShowHeader) && <HeaderBack title={headerTitle} history={history} previous={headerPrevious} />}
2025-12-24 16:33:09 +08:00
<div style={{ padding: contentPadding }}>
2025-12-24 15:45:07 +08:00
{props.children}
2025-12-26 13:50:59 +08:00
{
(isShowAllAction && isShowFooter) && (
<>
<div style={{ height: "52px" }}></div>
<div style={{ textAlign: "center", backgroundColor: "rgb(241, 241, 242)", padding: "10px 0", position: "fixed", bottom: "0", width: pageWidth, margin: "0px -20px" }}>
{customActionButtons || (
<Space>
{extraActionButtons}
<Button onClick={() => history?.goBack?.() || window.history.back()}>
{backButtonText}
</Button>
</Space>
)}
</div>
</>
)
}
2025-12-24 15:45:07 +08:00
</div>
</div>
);
}
Page.displayName = "Page";
export default Page;