Compare commits

..

2 Commits

Author SHA1 Message Date
LiuJiaNan 11ebad7b4b 优化Pdf 2025-12-29 09:48:30 +08:00
LiuJiaNan 327199b6e1 1.1.8 2025-12-27 14:16:24 +08:00
2 changed files with 14 additions and 19 deletions

View File

@ -1,7 +1,7 @@
{
"name": "zy-react-library",
"private": false,
"version": "1.1.7",
"version": "1.1.8",
"type": "module",
"description": "",
"author": "LiuJiaNan",

View File

@ -25,7 +25,6 @@ function Pdf(props) {
const fileUrl = getFileUrl();
const [numPages, setNumPages] = useState(0);
const [pdfWidth, setPdfWidth] = useState(600);
const [loading, setLoading] = useState(true);
const fullscreenRef = useRef(null);
@ -36,11 +35,9 @@ function Pdf(props) {
const onDocumentLoadSuccess = ({ numPages }) => {
setNumPages(numPages);
setLoading(false);
};
const onDocumentLoadError = () => {
setLoading(false);
message.error("加载 PDF 文件失败");
if (onCancel)
onCancel();
@ -53,16 +50,16 @@ function Pdf(props) {
// 内联模式的PDF内容
const renderPdfContent = () => (
<>
{loading && (
<div style={{ display: "flex", justifyContent: "center", alignItems: "center", height: "72vh" }}>
<Spin size="large" />
</div>
)}
<div style={{ height: isFullscreen ? "calc(100vh - 40px - 24px - 8px - 32px - 12px)" : "72vh", overflowY: "auto", padding: "24px", ...style }}>
<Document
file={!file.includes(fileUrl) ? fileUrl + file : file}
onLoadSuccess={onDocumentLoadSuccess}
onLoadError={onDocumentLoadError}
loading={(
<div style={{ display: "flex", justifyContent: "center", alignItems: "center", height: "65vh" }}>
<Spin size="large" />
</div>
)}
>
{
Array.from({ length: numPages }).map((_, index) => (
@ -111,7 +108,6 @@ function Pdf(props) {
>
关闭
</Button>,
!loading && (
<Button
key="fullScreen"
onClick={() => {
@ -119,8 +115,7 @@ function Pdf(props) {
}}
>
{isFullscreen ? "退出全屏" : "全屏"}
</Button>
),
</Button>,
<Button key="download" type="primary" onClick={onDownloadFile}>下载</Button>,
]}
>