zy-react-library 2.2.2 → 2.2.4
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.
|
@@ -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};
|
|
@@ -1,16 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
/** 常见下载文件 MIME 类型,同时允许传入其他合法 MIME 字符串 */
|
|
2
|
+
export type DownloadBlobMimeType
|
|
3
|
+
= | "application/pdf"
|
|
4
|
+
| "application/msword"
|
|
5
|
+
| "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
|
6
|
+
| "application/vnd.ms-excel"
|
|
7
|
+
| "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
8
|
+
| "application/vnd.ms-powerpoint"
|
|
9
|
+
| "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
|
10
|
+
| "text/csv"
|
|
11
|
+
| "text/plain"
|
|
12
|
+
| "application/json"
|
|
13
|
+
| "application/zip"
|
|
14
|
+
| "application/x-rar-compressed"
|
|
15
|
+
| "application/x-7z-compressed"
|
|
16
|
+
| "application/gzip"
|
|
17
|
+
| "image/jpeg"
|
|
18
|
+
| "image/png"
|
|
19
|
+
| "image/gif"
|
|
20
|
+
| "image/webp"
|
|
21
|
+
| "image/svg+xml"
|
|
22
|
+
| "image/bmp"
|
|
23
|
+
| "audio/mpeg"
|
|
24
|
+
| "audio/wav"
|
|
25
|
+
| "video/mp4"
|
|
26
|
+
| "video/webm"
|
|
27
|
+
| "application/octet-stream"
|
|
28
|
+
| (string & {});
|
|
29
|
+
|
|
30
|
+
interface UseDownloadBlobOptions {
|
|
31
|
+
/** 下载文件的自定义文件名(不含后缀),默认为当前时间戳 */
|
|
32
|
+
name?: string;
|
|
33
|
+
/** Blob 对象的 MIME 类型,默认为 application/vnd.ms-excel 类型 */
|
|
34
|
+
type?: DownloadBlobMimeType;
|
|
35
|
+
/** 请求时携带的查询参数对象 */
|
|
36
|
+
params?: Record<string, any>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type DownloadBlobFunction = (url: string, options?: UseDownloadBlobOptions) => Promise<{ data: Blob }>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 下载Blob流文件
|
|
43
|
+
*/
|
|
44
|
+
export default function useDownloadBlob(returnType: "array"): [boolean, DownloadBlobFunction];
|
|
45
|
+
export default function useDownloadBlob(returnType?: "object"): { loading: boolean; downloadBlob: DownloadBlobFunction };
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
export type SetUrlCriteriaQueryFunction = (searchForm: Record<string, any>, pagination: Record<string, any>) => void;
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/** URL 中存储字段名列表的参数名,同时允许传入自定义参数名 */
|
|
4
|
+
export type UrlCriteriaKeysKey
|
|
5
|
+
= | "searchFormKeys"
|
|
6
|
+
| "paginationKeys"
|
|
7
|
+
| (string & {});
|
|
8
|
+
|
|
9
|
+
/** URL 中存储字段值列表的参数名,同时允许传入自定义参数名 */
|
|
10
|
+
export type UrlCriteriaValuesKey
|
|
11
|
+
= | "searchFormValues"
|
|
12
|
+
| "paginationValues"
|
|
13
|
+
| (string & {});
|
|
14
|
+
|
|
15
|
+
export type GetUrlCriteriaQueryFunction = (keysStr: UrlCriteriaKeysKey, valuesStr: UrlCriteriaValuesKey) => Record<string, any>;
|
|
4
16
|
|
|
5
17
|
/**
|
|
6
18
|
* 处理搜索条件缓存到 URL
|