zy-react-library 2.0.9 → 2.0.11
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/README.md +480 -363
- package/components/Excel/index.d.ts +22 -0
- package/components/Excel/index.js +1 -0
- package/components/PreviewExcel/index.d.ts +18 -0
- package/components/PreviewExcel/index.js +1 -0
- package/components/PreviewWord/index.d.ts +18 -0
- package/components/PreviewWord/index.js +1 -0
- package/components/Word/index.d.ts +22 -0
- package/components/Word/index.js +1 -0
- package/package.json +5 -2
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FC } from "react";
|
|
2
|
+
|
|
3
|
+
export interface ExcelProps {
|
|
4
|
+
/** 是否显示弹窗 */
|
|
5
|
+
visible?: boolean;
|
|
6
|
+
/** 关闭回调 */
|
|
7
|
+
onCancel?: () => void;
|
|
8
|
+
/** xlsx 文件地址 */
|
|
9
|
+
file?: string;
|
|
10
|
+
/** xlsx 文件名 */
|
|
11
|
+
name?: string;
|
|
12
|
+
/** 是否内联展示 */
|
|
13
|
+
inline?: boolean;
|
|
14
|
+
/** 弹窗标题 */
|
|
15
|
+
title?: string;
|
|
16
|
+
/** 内容样式 */
|
|
17
|
+
style?: Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare const Excel: FC<ExcelProps>;
|
|
21
|
+
|
|
22
|
+
export default Excel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Modal as e,Button as t,message as r,Spin as n}from"antd";import i from"exceljs";import{useRef as o,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={}}=h,E=o(null),k=o(null),I=o(!1),T=s(),[b,j]=l(!1),{downloadFile:S}=u();c(()=>{if(!x&&!g||!p)return;I.current=!1;const e=setTimeout(()=>{(async()=>{j(!0),E.current.innerHTML="";try{const e=await fetch(p.includes(T)?p:T+p);if(!e.ok)throw new Error("加载 Excel 文件失败");const t=await e.arrayBuffer(),r=new i.Workbook;if(await r.xlsx.load(t),I.current)return;new a(E.current,{mode:"read",showToolbar:!1,showContextmenu:!1,view:{height:()=>E.current?.clientHeight||520,width:()=>E.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),i=f(r);return{sri:n.rowIndex,sci:n.colIndex,eri:i.rowIndex,eci:i.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{I.current||j(!1)}})()},100);return()=>{I.current=!0,E.current&&(E.current.innerHTML=""),e&&clearTimeout(e)}},[x,g,p]);const D=()=>d(n,{spinning:b,children:d("div",{style:{height:"72vh",overflow:"hidden",...C},children:d("div",{ref:E,style:{width:"100%",height:"100%"}})})});return g?D():d("div",{ref:k,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:()=>{S({url:p,name:v})},children:"下载"},"download")],children:D()})})}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};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FC } from "react";
|
|
2
|
+
|
|
3
|
+
export interface PreviewExcelProps {
|
|
4
|
+
/** 文件列表,和 name、url 冲突 */
|
|
5
|
+
files?: { filePath?: string; fileName?: string; name?: string; url?: string; [key: string]: string }[];
|
|
6
|
+
/** 文件名字段名,传入 files 时会优先查找是否存在 name、fileName */
|
|
7
|
+
nameKey?: string;
|
|
8
|
+
/** 文件路径字段名,传入 files 时会优先查找是否存在 filePath、url */
|
|
9
|
+
urlKey?: string;
|
|
10
|
+
/** 单个文件名,和 files 冲突 */
|
|
11
|
+
name?: string;
|
|
12
|
+
/** 单个文件路径,和 files 冲突 */
|
|
13
|
+
url?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare const PreviewExcel: FC<PreviewExcelProps>;
|
|
17
|
+
|
|
18
|
+
export default PreviewExcel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Space as e,Button as l}from"antd";import{useState as i}from"react";import{getFileName as r}from"../../utils/index.js";import n from"../Excel/index.js";import{jsxs as a,Fragment as m,jsx as t}from"react/jsx-runtime";const c=c=>{const{files:o=[],nameKey:s="",urlKey:d="",name:p="",url:h=""}=c,[f,u]=i(!1),[y,x]=i(""),[v,C]=i(""),g=(e,l)=>{u(!0),x(e),C(l)},j=()=>{u(!1),x(""),C("")},P=e=>e.name||e.fileName||e[s]||r(e.filePath||e.url||e[d]),b=e=>e.filePath||e.url||e[d];return 0===o.length&&p&&h?a(m,{children:[a(e,{children:[t("span",{children:p}),t(l,{type:"primary",size:"small",onClick:()=>g(h,p),children:"预览"})]}),t(n,{visible:f,file:y,name:v,onCancel:j})]}):o.length>0&&!p&&!h?a(m,{children:[o.map(i=>t("div",{style:{marginTop:5},children:a(e,{children:[t("span",{children:P(i)}),t(l,{type:"primary",size:"small",onClick:()=>g(b(i),P(i)),children:"预览"})]})},b(i))),t(n,{visible:f,file:y,name:v,onCancel:j})]}):null};c.displayName="PreviewExcel";export{c as default};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FC } from "react";
|
|
2
|
+
|
|
3
|
+
export interface PreviewWordProps {
|
|
4
|
+
/** 文件列表,和 name、url 冲突 */
|
|
5
|
+
files?: { filePath?: string; fileName?: string; name?: string; url?: string; [key: string]: string }[];
|
|
6
|
+
/** 文件名字段名,传入 files 时会优先查找是否存在 name、fileName */
|
|
7
|
+
nameKey?: string;
|
|
8
|
+
/** 文件路径字段名,传入 files 时会优先查找是否存在 filePath、url */
|
|
9
|
+
urlKey?: string;
|
|
10
|
+
/** 单个文件名,和 files 冲突 */
|
|
11
|
+
name?: string;
|
|
12
|
+
/** 单个文件路径,和 files 冲突 */
|
|
13
|
+
url?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare const PreviewWord: FC<PreviewWordProps>;
|
|
17
|
+
|
|
18
|
+
export default PreviewWord;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Space as e,Button as i}from"antd";import{useState as l}from"react";import{getFileName as r}from"../../utils/index.js";import n from"../Word/index.js";import{jsxs as a,Fragment as m,jsx as t}from"react/jsx-runtime";const o=o=>{const{files:s=[],nameKey:c="",urlKey:d="",name:p="",url:h=""}=o,[f,u]=l(!1),[y,v]=l(""),[x,C]=l(""),g=(e,i)=>{u(!0),v(e),C(i)},j=()=>{u(!1),v(""),C("")},P=e=>e.name||e.fileName||e[c]||r(e.filePath||e.url||e[d]),b=e=>e.filePath||e.url||e[d];return 0===s.length&&p&&h?a(m,{children:[a(e,{children:[t("span",{children:p}),t(i,{type:"primary",size:"small",onClick:()=>g(h,p),children:"预览"})]}),t(n,{visible:f,file:y,name:x,onCancel:j})]}):s.length>0&&!p&&!h?a(m,{children:[s.map(l=>t("div",{style:{marginTop:5},children:a(e,{children:[t("span",{children:P(l)}),t(i,{type:"primary",size:"small",onClick:()=>g(b(l),P(l)),children:"预览"})]})},b(l))),t(n,{visible:f,file:y,name:x,onCancel:j})]}):null};o.displayName="PreviewWord";export{o as default};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FC } from "react";
|
|
2
|
+
|
|
3
|
+
export interface WordProps {
|
|
4
|
+
/** 是否显示弹窗 */
|
|
5
|
+
visible?: boolean;
|
|
6
|
+
/** 关闭回调 */
|
|
7
|
+
onCancel?: () => void;
|
|
8
|
+
/** docx 文件地址 */
|
|
9
|
+
file?: string;
|
|
10
|
+
/** docx 文件名 */
|
|
11
|
+
name?: string;
|
|
12
|
+
/** 是否内联展示 */
|
|
13
|
+
inline?: boolean;
|
|
14
|
+
/** 弹窗标题 */
|
|
15
|
+
title?: string;
|
|
16
|
+
/** 内容样式 */
|
|
17
|
+
style?: Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare const Word: FC<WordProps>;
|
|
21
|
+
|
|
22
|
+
export default Word;
|
|
@@ -0,0 +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 l,useEffect as a}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:y={}}=s,v=o(null),x=o(null),k=o(!1),W=d(),[C,b]=l(!1),{downloadFile:T}=c();a(()=>{if(!f&&!w||!p)return;k.current=!1;const r=setTimeout(()=>{(async()=>{b(!0),v.current.innerHTML="";try{const r=await fetch(p.includes(W)?p:W+p);if(!r.ok)throw new Error("加载 Word 文件失败");const e=await r.arrayBuffer();if(k.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{k.current||b(!1)}})()},100);return()=>{k.current=!0,v.current&&(v.current.innerHTML=""),r&&clearTimeout(r)}},[f,w,p]);const j=()=>u(t,{spinning:C,children:u("div",{style:{height:"72vh",overflowY:"auto",padding:"24px",background:"#f5f5f5",...y},children:u("div",{ref:v})})});return w?j():u("div",{ref:x,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:()=>{T({url:p,name:h})},children:"下载"},"download")],children:j()})})}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.0.
|
|
4
|
+
"version": "2.0.11",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "",
|
|
7
7
|
"author": "LiuJiaNan",
|
|
@@ -38,12 +38,15 @@
|
|
|
38
38
|
"ahooks": "^3.9.5",
|
|
39
39
|
"antd": "^6.4.4",
|
|
40
40
|
"dayjs": "^1.11.18",
|
|
41
|
+
"docx-preview": "^0.3.7",
|
|
42
|
+
"exceljs": "^4.4.0",
|
|
41
43
|
"lodash-es": "^4.17.21",
|
|
42
44
|
"react": "^18.3.1",
|
|
43
45
|
"react-pdf": "^10.2.0",
|
|
44
46
|
"react-signature-canvas": "^1.1.0-alpha.2",
|
|
45
47
|
"throttle-debounce": "^5.0.2",
|
|
46
|
-
"use-antd-resizable-header": "^3.2.2"
|
|
48
|
+
"use-antd-resizable-header": "^3.2.2",
|
|
49
|
+
"x-data-spreadsheet": "^1.1.9"
|
|
47
50
|
},
|
|
48
51
|
"devDependencies": {
|
|
49
52
|
"@antfu/eslint-config": "^5.4.1",
|