zy-react-library 2.2.1 → 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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FC } from "react";
|
|
1
|
+
import type { CSSProperties, FC, ReactNode } from "react";
|
|
2
2
|
|
|
3
3
|
export interface ExcelProps {
|
|
4
4
|
/** 是否显示弹窗 */
|
|
@@ -13,8 +13,10 @@ export interface ExcelProps {
|
|
|
13
13
|
inline?: boolean;
|
|
14
14
|
/** 弹窗标题 */
|
|
15
15
|
title?: string;
|
|
16
|
-
/**
|
|
17
|
-
style?:
|
|
16
|
+
/** 内联模式下的样式 */
|
|
17
|
+
style?: CSSProperties;
|
|
18
|
+
/** 弹窗底部额外的按钮 */
|
|
19
|
+
extraButtons?: ReactNode;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
declare const Excel: FC<ExcelProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Modal as e,Button as t,message as r,Spin as n}from"antd";import
|
|
1
|
+
import{Modal as e,Button as t,message as r,Spin as n}from"antd";import o from"exceljs";import{useRef as i,useState as l,useEffect as c}from"react";import a from"x-data-spreadsheet";import u from"../../hooks/useDownloadFile/index.js";import{getFileUrl as s}from"../../utils/index.js";import"x-data-spreadsheet/dist/xspreadsheet.css";import{jsx as d}from"react/jsx-runtime";function h(h){const{visible:x=!1,onCancel:w,file:p,name:v,inline:g=!1,title:y="Excel预览",style:C={},extraButtons:E}=h,k=i(null),I=i(null),T=i(!1),b=s(),[j,S]=l(!1),{downloadFile:D}=u();c(()=>{if(!x&&!g||!p)return;T.current=!1;const e=setTimeout(()=>{(async()=>{S(!0),k.current.innerHTML="";try{const e=await fetch(p.includes(b)?p:b+p);if(!e.ok)throw new Error("加载 Excel 文件失败");const t=await e.arrayBuffer(),r=new o.Workbook;if(await r.xlsx.load(t),T.current)return;new a(k.current,{mode:"read",showToolbar:!1,showContextmenu:!1,view:{height:()=>k.current?.clientHeight||520,width:()=>k.current?.clientWidth||800}}).loadData(function(e){const t=[];return e.worksheets.forEach(e=>{t.push(function(e){const t={name:e.name,rows:{},cols:{len:e.columnCount||26},merges:e.model?.merges||[]};return e.columns.forEach((e,r)=>{e.width&&(t.cols[r]={width:Math.round(8*e.width)})}),e.eachRow({includeEmpty:!0},(e,r)=>{const n={cells:{}};e.height&&(n.height=Math.round(1.4*e.height)),e.eachCell({includeEmpty:!0},(e,t)=>{n.cells[t-1]={text:m(e)}}),t.rows[r-1]=n}),(t.merges||[]).forEach(e=>{const r=function(e){const[t,r=t]=e.split(":"),n=f(t),o=f(r);return{sri:n.rowIndex,sci:n.colIndex,eri:o.rowIndex,eci:o.colIndex}}(e),n=t.rows[r.sri]?.cells?.[r.sci];n&&(n.merge=[r.eri-r.sri,r.eci-r.sci])}),t}(e))}),t.length>0?t:[{name:"Sheet1",rows:{}}]}(r))}catch{r.error("加载 Excel 文件失败"),!g&&w&&w()}finally{T.current||S(!1)}})()},100);return()=>{T.current=!0,k.current&&(k.current.innerHTML=""),e&&clearTimeout(e)}},[x,g,p]);const M=()=>d(n,{spinning:j,children:d("div",{style:{height:"72vh",overflow:"hidden",...C},children:d("div",{ref:k,style:{width:"100%",height:"100%"}})})});return g?M():d("div",{ref:I,children:d(e,{style:{top:100,maxWidth:"calc(100vw - 32px)",paddingBottom:24},open:x,mask:{closable:!1},width:1e3,title:y,onCancel:()=>{w()},getContainer:!1,footer:[d(t,{onClick:()=>{w()},children:"关闭"},"cancel"),d(t,{type:"primary",onClick:()=>{D({url:p,name:v})},children:"下载"},"download"),...E||[]],children:M()})})}function m(e){if(null===e.value||void 0===e.value)return"";if(e.formula)return null===e.result||void 0===e.result?`=${e.formula}`:String(e.result);if(e.text)return e.text;if(e.value instanceof Date)return e.value.toLocaleDateString();if("object"==typeof e.value){if(e.value.text)return e.value.text;if(e.value.richText)return e.value.richText.map(e=>e.text).join("");if(void 0!==e.value.result)return String(e.value.result)}return String(e.value)}function f(e){const t=/^([A-Z]+)(\d+)$/i.exec(e);return t?{rowIndex:Number(t[2])-1,colIndex:(r=t[1],r.toUpperCase().split("").reduce((e,t)=>26*e+t.charCodeAt(0)-64,0)-1)}:{rowIndex:0,colIndex:0};var r}h.displayName="Excel";export{h as default};
|
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
import type { CSSProperties, FC } 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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import type { FC } from "react";
|
|
1
|
+
import type { CSSProperties, FC, ReactNode } from "react";
|
|
2
2
|
|
|
3
3
|
export interface WordProps {
|
|
4
4
|
/** 是否显示弹窗 */
|
|
@@ -13,8 +13,10 @@ export interface WordProps {
|
|
|
13
13
|
inline?: boolean;
|
|
14
14
|
/** 弹窗标题 */
|
|
15
15
|
title?: string;
|
|
16
|
-
/**
|
|
17
|
-
style?:
|
|
16
|
+
/** 内联模式下的样式 */
|
|
17
|
+
style?: CSSProperties;
|
|
18
|
+
/** 弹窗底部额外的按钮 */
|
|
19
|
+
extraButtons?: ReactNode;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
declare const Word: FC<WordProps>;
|
package/components/Word/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Modal as r,Button as e,message as n,Spin as t}from"antd";import{renderAsync as i}from"docx-preview";import{useRef as o,useState as
|
|
1
|
+
import{Modal as r,Button as e,message as n,Spin as t}from"antd";import{renderAsync as i}from"docx-preview";import{useRef as o,useState as a,useEffect as l}from"react";import c from"../../hooks/useDownloadFile/index.js";import{getFileUrl as d}from"../../utils/index.js";import{jsx as u}from"react/jsx-runtime";function s(s){const{visible:f=!1,onCancel:m,file:p,name:h,inline:w=!1,title:g="Word预览",style:x={},extraButtons:y}=s,v=o(null),k=o(null),W=o(!1),C=d(),[b,T]=a(!1),{downloadFile:j}=c();l(()=>{if(!f&&!w||!p)return;W.current=!1;const r=setTimeout(()=>{(async()=>{T(!0),v.current.innerHTML="";try{const r=await fetch(p.includes(C)?p:C+p);if(!r.ok)throw new Error("加载 Word 文件失败");const e=await r.arrayBuffer();if(W.current)return;await i(e,v.current,null,{className:"docx-preview",inWrapper:!0,ignoreWidth:!1,ignoreHeight:!1,breakPages:!0})}catch{n.error("加载 Word 文件失败"),!w&&m&&m()}finally{W.current||T(!1)}})()},100);return()=>{W.current=!0,v.current&&(v.current.innerHTML=""),r&&clearTimeout(r)}},[f,w,p]);const B=()=>u(t,{spinning:b,children:u("div",{style:{height:"72vh",overflowY:"auto",padding:"24px",background:"#f5f5f5",...x},children:u("div",{ref:v})})});return w?B():u("div",{ref:k,children:u(r,{style:{top:100,maxWidth:"calc(100vw - 32px)",paddingBottom:24},open:f,mask:{closable:!1},width:900,title:g,onCancel:()=>{m()},getContainer:!1,footer:[u(e,{onClick:()=>{m()},children:"关闭"},"cancel"),u(e,{type:"primary",onClick:()=>{j({url:p,name:h})},children:"下载"},"download"),...y||[]],children:B()})})}s.displayName="Word";export{s as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zy-react-library",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "",
|
|
7
7
|
"author": "LiuJiaNan",
|
|
@@ -75,5 +75,9 @@
|
|
|
75
75
|
"antd": ">=6.4.4 <7",
|
|
76
76
|
"react": ">=18.3.1 <19",
|
|
77
77
|
"zy-react-data": ">=1.0.0"
|
|
78
|
+
},
|
|
79
|
+
"publishConfig": {
|
|
80
|
+
"access": "public",
|
|
81
|
+
"registry": "https://registry.npmjs.org/"
|
|
78
82
|
}
|
|
79
83
|
}
|