zy-react-library 2.2.2 → 2.2.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.
- package/components/Pdf/index.d.ts +26 -24
- package/components/Pdf/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import type { CSSProperties, FC, ReactNode } from "react";
|
|
2
|
-
|
|
3
|
-
export interface PdfProps {
|
|
4
|
-
/** pdf 文件地址 */
|
|
5
|
-
file: string;
|
|
6
|
-
/** pdf 文件名 */
|
|
7
|
-
name?: string;
|
|
8
|
-
/** 是否显示弹窗 */
|
|
9
|
-
visible?: boolean;
|
|
10
|
-
/** 弹窗的标题,默认 ”PDF预览“ */
|
|
11
|
-
title?: string;
|
|
12
|
-
/** 关闭弹窗的方法 */
|
|
13
|
-
onCancel?: () => void;
|
|
14
|
-
/** 是否使用内联模式,true为不使用弹窗,默认 false */
|
|
15
|
-
inline?: boolean;
|
|
16
|
-
/** 内联模式下的样式 */
|
|
17
|
-
style?: CSSProperties;
|
|
18
|
-
/** 弹窗底部额外的按钮 */
|
|
19
|
-
extraButtons?: ReactNode;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
import type { CSSProperties, FC, ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
export interface PdfProps {
|
|
4
|
+
/** pdf 文件地址 */
|
|
5
|
+
file: string;
|
|
6
|
+
/** pdf 文件名 */
|
|
7
|
+
name?: string;
|
|
8
|
+
/** 是否显示弹窗 */
|
|
9
|
+
visible?: boolean;
|
|
10
|
+
/** 弹窗的标题,默认 ”PDF预览“ */
|
|
11
|
+
title?: string;
|
|
12
|
+
/** 关闭弹窗的方法 */
|
|
13
|
+
onCancel?: () => void;
|
|
14
|
+
/** 是否使用内联模式,true为不使用弹窗,默认 false */
|
|
15
|
+
inline?: boolean;
|
|
16
|
+
/** 内联模式下的样式 */
|
|
17
|
+
style?: CSSProperties;
|
|
18
|
+
/** 弹窗底部额外的按钮 */
|
|
19
|
+
extraButtons?: ReactNode;
|
|
20
|
+
/** 是否使用打印功能,默认 false */
|
|
21
|
+
usePrint?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare const Pdf: FC<PdfProps>;
|
|
25
|
+
|
|
26
|
+
export default Pdf;
|
package/components/Pdf/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useFullscreen as e}from"ahooks";import{Modal as
|
|
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 c,Document as a,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:L=!1}=h,C=p(),j=g.includes(C)?g:C+g,[P,F]=i(0),[D,R]=i(600),S=l(null),[U,{enterFullscreen:E,exitFullscreen:O}]=e(S),{downloadFile:W}=d();c.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${c.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(a,{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,mask:{closable:!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"),L&&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};
|