zy-react-library 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,6 +17,8 @@ export interface PdfProps {
17
17
  style?: CSSProperties;
18
18
  /** 弹窗底部额外的按钮 */
19
19
  extraButtons?: ReactNode;
20
+ /** 是否使用打印功能,默认 false */
21
+ usePrint?: boolean;
20
22
  }
21
23
 
22
24
  declare const Pdf: FC<PdfProps>;
@@ -1 +1 @@
1
- import{useFullscreen as e}from"ahooks";import{Modal as r,Button as o,Spin as i,message as n}from"antd";import{useState as t,useRef as l}from"react";import{pdfjs as a,Document as d,Page as s}from"react-pdf";import c from"../../hooks/useDownloadFile/index.js";import{getFileUrl as p}from"../../utils/index.js";import"react-pdf/dist/Page/AnnotationLayer.css";import"react-pdf/dist/Page/TextLayer.css";import"./index.less";import{jsx as m,Fragment as f}from"react/jsx-runtime";function h(h){const{visible:u=!1,onCancel:x,file:g,name:v,inline:y=!1,title:w="PDF预览",style:k={},extraButtons:C}=h,j=p(),[F,P]=t(0),[b,L]=t(600),S=l(null),[D,{enterFullscreen:A,exitFullscreen:B}]=e(S),{downloadFile:N}=c();a.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${a.version}/build/pdf.worker.min.mjs`;const W=({numPages:e})=>{P(e)},$=()=>{n.error("加载 PDF 文件失败"),x&&x()},z=({width:e})=>{L(e)},E=()=>m(f,{children:m("div",{style:{height:D?"calc(100vh - 40px - 24px - 8px - 32px - 12px)":"72vh",overflowY:"auto",padding:"24px",...k},children:m(d,{file:g.includes(j)?g:j+g,onLoadSuccess:W,onLoadError:$,loading:m("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"65vh"},children:m(i,{size:"large"})}),children:Array.from({length:F}).map((e,r)=>m(s,{pageNumber:r+1,onLoadSuccess:z},`page_${r+1}`))})})});return y?E():m("div",{ref:S,children:m(r,{style:{top:D?0:100,maxWidth:D?"100vw":"calc(100vw - 32px)",paddingBottom:D?0:24},open:u,maskClosable:!1,width:D?"100vw":b+100,title:w,onCancel:()=>{D&&B(),x()},getContainer:!1,footer:[m(o,{onClick:()=>{D&&B(),x()},children:"关闭"},"cancel"),m(o,{onClick:()=>{D?B():A()},children:D?"退出全屏":"全屏"},"fullScreen"),m(o,{type:"primary",onClick:()=>{D&&B(),N({url:g,name:v})},children:"下载"},"download"),...C||[]],children:E()})})}h.displayName="Pdf";export{h as default};
1
+ import{useFullscreen as e}from"ahooks";import{Modal as t,Button as r,Spin as o,message as n}from"antd";import{useState as i,useRef as l}from"react";import{pdfjs as a,Document as c,Page as s}from"react-pdf";import d from"../../hooks/useDownloadFile/index.js";import{getFileUrl as p}from"../../utils/index.js";import"react-pdf/dist/Page/AnnotationLayer.css";import"react-pdf/dist/Page/TextLayer.css";import"./index.less";import{jsx as m,Fragment as f}from"react/jsx-runtime";function h(h){const{visible:u=!1,onCancel:x,file:g,name:w,inline:y=!1,title:v="PDF预览",style:k={},extraButtons:b,usePrint:C=!1}=h,L=p(),j=g.includes(L)?g:L+g,[P,F]=i(0),[D,R]=i(600),S=l(null),[U,{enterFullscreen:E,exitFullscreen:O}]=e(S),{downloadFile:W}=d();a.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${a.version}/build/pdf.worker.min.mjs`;const A=({numPages:e})=>{F(e)},B=()=>{n.error("加载 PDF 文件失败"),x&&x()},N=({width:e})=>{R(e)},T=()=>m(f,{children:m("div",{style:{height:U?"calc(100vh - 40px - 24px - 8px - 32px - 12px)":"72vh",overflowY:"auto",padding:"24px",...k},children:m(c,{file:j,onLoadSuccess:A,onLoadError:B,loading:m("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"65vh"},children:m(o,{size:"large"})}),children:Array.from({length:P}).map((e,t)=>m(s,{pageNumber:t+1,onLoadSuccess:N},`page_${t+1}`))})})});return y?T():m("div",{ref:S,children:m(t,{style:{top:U?0:100,maxWidth:U?"100vw":"calc(100vw - 32px)",paddingBottom:U?0:24},open:u,maskClosable:!1,width:U?"100vw":D+100,title:v,onCancel:()=>{U&&O(),x()},getContainer:!1,footer:[m(r,{onClick:()=>{U&&O(),x()},children:"关闭"},"cancel"),m(r,{onClick:()=>{U?O():E()},children:U?"退出全屏":"全屏"},"fullScreen"),m(r,{type:"primary",onClick:()=>{U&&O(),W({url:g,name:w})},children:"下载"},"download"),C&&m(r,{type:"primary",onClick:async()=>{const e=window.open("","_blank");if(e)try{const t=await fetch(j);if(!t.ok)return void n.error("获取 PDF 文件失败");const r=URL.createObjectURL(await t.blob()),o=e.document.createElement("iframe");o.style.cssText="position:fixed;inset:0;width:100%;height:100%;border:0",o.onload=()=>{const t=o.contentWindow;t.addEventListener("afterprint",()=>{URL.revokeObjectURL(r),e.close()},{once:!0}),t.focus(),t.print()},o.src=r,e.document.body.appendChild(o)}catch(t){e.close(),n.error(t.message||"打印失败,请稍后重试")}else n.warning("请允许弹出窗口后重试")},children:"打印"},"print"),...b||[]],children:T()})})}h.displayName="Pdf";export{h as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zy-react-library",
3
3
  "private": false,
4
- "version": "1.4.2",
4
+ "version": "1.4.3",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",