zy-react-library 2.0.10 → 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 +87 -7
- 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
package/README.md
CHANGED
|
@@ -222,6 +222,10 @@ import { FORM_ITEM_RENDER_ENUM } from "zy-react-library/enum/formItemRender";
|
|
|
222
222
|
| `PreviewImg` | `files=[]`、`fileUrlKey="filePath"`;图片固定 `width=100`、`height=100`,图片间距 `marginRight=10`、`marginBottom=10`。 |
|
|
223
223
|
| `PreviewPdf` | `files=[]`、`nameKey=""`、`urlKey=""`、`name=""`、`url=""`。 |
|
|
224
224
|
| `Pdf` | `visible=false`、`inline=false`、`title="PDF预览"`、`style={}`。 |
|
|
225
|
+
| `PreviewExcel` | `files=[]`、`nameKey=""`、`urlKey=""`、`name=""`、`url=""`。 |
|
|
226
|
+
| `Excel` | `visible=false`、`inline=false`、`title="Excel预览"`、`style={}`;弹窗宽度 `1000`,内容高度 `72vh`。 |
|
|
227
|
+
| `PreviewWord` | `files=[]`、`nameKey=""`、`urlKey=""`、`name=""`、`url=""`。 |
|
|
228
|
+
| `Word` | `visible=false`、`inline=false`、`title="Word预览"`、`style={}`;弹窗宽度 `900`,内容高度 `72vh`,默认背景 `#f5f5f5`、内边距 `24px`。 |
|
|
225
229
|
| `Video` | `source=""`、`vid=""`、`playAuth=""`、`cover=""`、`autoplay=true`、`showProgress=true`、`playTime=0`、`inline=false`、`isLive=false`、`width="100%"`、`height="600px"`、`title="视频"`、`visible=false`、`aliPlayerProps={}`;弹窗宽度 `800`。 |
|
|
226
230
|
| `AliPlayer` | `source=""`、`vid=""`、`playAuth=""`、`cover=""`、`width="100%"`、`height="600px"`、`autoplay=true`、`showProgress=true`、`isLive=false`、`playTime=0`。 |
|
|
227
231
|
| `Signature` | `width=752`、`height=300`、`url=""`;签名弹窗宽度 `800`,画笔颜色 `black`,画布背景 `rgb(255,255,255)`。 |
|
|
@@ -477,9 +481,9 @@ PDF 预览入口组件。
|
|
|
477
481
|
| `name` | `string` | 否 | `""` | 单文件文件名。 |
|
|
478
482
|
| `url` | `string` | 否 | `""` | 单文件地址。 |
|
|
479
483
|
|
|
480
|
-
### Pdf
|
|
481
|
-
|
|
482
|
-
引入:
|
|
484
|
+
### Pdf
|
|
485
|
+
|
|
486
|
+
引入:
|
|
483
487
|
|
|
484
488
|
```tsx
|
|
485
489
|
import Pdf from "zy-react-library/components/Pdf";
|
|
@@ -496,10 +500,86 @@ PDF 展示组件。
|
|
|
496
500
|
| `onCancel` | `() => void` | 否 | - | 关闭弹窗回调。 |
|
|
497
501
|
| `inline` | `boolean` | 否 | `false` | 是否内联展示。 |
|
|
498
502
|
| `style` | `CSSProperties` | 否 | `{}` | 外层样式。 |
|
|
499
|
-
|
|
500
|
-
###
|
|
501
|
-
|
|
502
|
-
引入:
|
|
503
|
+
|
|
504
|
+
### PreviewExcel
|
|
505
|
+
|
|
506
|
+
引入:
|
|
507
|
+
|
|
508
|
+
```tsx
|
|
509
|
+
import PreviewExcel from "zy-react-library/components/PreviewExcel";
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
Excel 预览入口组件,使用方式和 `PreviewPdf` 一致,负责展示文件名和预览按钮。
|
|
513
|
+
|
|
514
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
|
515
|
+
| --- | --- | --- | --- | --- |
|
|
516
|
+
| `files` | `{ filePath?: string; fileName?: string; name?: string; url?: string; [key: string]: string }[]` | 否 | `[]` | Excel 文件对象数组;和 `name`、`url` 单文件模式互斥。 |
|
|
517
|
+
| `nameKey` | `string` | 否 | `""` | 文件名字段名;不传时优先取 `name`、`fileName`。 |
|
|
518
|
+
| `urlKey` | `string` | 否 | `""` | 文件地址字段名;不传时优先取 `filePath`、`url`。 |
|
|
519
|
+
| `name` | `string` | 否 | `""` | 单文件文件名;和 `files` 互斥。 |
|
|
520
|
+
| `url` | `string` | 否 | `""` | 单文件地址;和 `files` 互斥。 |
|
|
521
|
+
|
|
522
|
+
### Excel
|
|
523
|
+
|
|
524
|
+
引入:
|
|
525
|
+
|
|
526
|
+
```tsx
|
|
527
|
+
import Excel from "zy-react-library/components/Excel";
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
Excel 展示组件,使用 `exceljs` 解析 `xlsx`,再通过 `x-data-spreadsheet` 渲染表格预览。
|
|
531
|
+
|
|
532
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
|
533
|
+
| --- | --- | --- | --- | --- |
|
|
534
|
+
| `visible` | `boolean` | 否 | `false` | 是否以弹窗形式显示。 |
|
|
535
|
+
| `onCancel` | `() => void` | 否 | - | 关闭弹窗回调。 |
|
|
536
|
+
| `file` | `string` | 否 | - | `xlsx` 文件地址;非完整文件服务地址时会自动拼接 `getFileUrl()`。 |
|
|
537
|
+
| `name` | `string` | 否 | - | 文件名,用于下载。 |
|
|
538
|
+
| `inline` | `boolean` | 否 | `false` | 是否内联展示。 |
|
|
539
|
+
| `title` | `string` | 否 | `"Excel预览"` | 弹窗标题。 |
|
|
540
|
+
| `style` | `Record<string, any>` | 否 | `{}` | 内容区域样式,会合并到高度为 `72vh` 的外层容器。 |
|
|
541
|
+
|
|
542
|
+
### PreviewWord
|
|
543
|
+
|
|
544
|
+
引入:
|
|
545
|
+
|
|
546
|
+
```tsx
|
|
547
|
+
import PreviewWord from "zy-react-library/components/PreviewWord";
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
Word 预览入口组件,使用方式和 `PreviewPdf` 一致,负责展示文件名和预览按钮。
|
|
551
|
+
|
|
552
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
|
553
|
+
| --- | --- | --- | --- | --- |
|
|
554
|
+
| `files` | `{ filePath?: string; fileName?: string; name?: string; url?: string; [key: string]: string }[]` | 否 | `[]` | Word 文件对象数组;和 `name`、`url` 单文件模式互斥。 |
|
|
555
|
+
| `nameKey` | `string` | 否 | `""` | 文件名字段名;不传时优先取 `name`、`fileName`。 |
|
|
556
|
+
| `urlKey` | `string` | 否 | `""` | 文件地址字段名;不传时优先取 `filePath`、`url`。 |
|
|
557
|
+
| `name` | `string` | 否 | `""` | 单文件文件名;和 `files` 互斥。 |
|
|
558
|
+
| `url` | `string` | 否 | `""` | 单文件地址;和 `files` 互斥。 |
|
|
559
|
+
|
|
560
|
+
### Word
|
|
561
|
+
|
|
562
|
+
引入:
|
|
563
|
+
|
|
564
|
+
```tsx
|
|
565
|
+
import Word from "zy-react-library/components/Word";
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
Word 展示组件,使用 `docx-preview` 渲染 `docx` 文件。
|
|
569
|
+
|
|
570
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
|
571
|
+
| --- | --- | --- | --- | --- |
|
|
572
|
+
| `visible` | `boolean` | 否 | `false` | 是否以弹窗形式显示。 |
|
|
573
|
+
| `onCancel` | `() => void` | 否 | - | 关闭弹窗回调。 |
|
|
574
|
+
| `file` | `string` | 否 | - | `docx` 文件地址;非完整文件服务地址时会自动拼接 `getFileUrl()`。 |
|
|
575
|
+
| `name` | `string` | 否 | - | 文件名,用于下载。 |
|
|
576
|
+
| `inline` | `boolean` | 否 | `false` | 是否内联展示。 |
|
|
577
|
+
| `title` | `string` | 否 | `"Word预览"` | 弹窗标题。 |
|
|
578
|
+
| `style` | `Record<string, any>` | 否 | `{}` | 内容区域样式,会合并到默认高度 `72vh`、背景 `#f5f5f5`、内边距 `24px` 的外层容器。 |
|
|
579
|
+
|
|
580
|
+
### Video
|
|
581
|
+
|
|
582
|
+
引入:
|
|
503
583
|
|
|
504
584
|
```tsx
|
|
505
585
|
import Video from "zy-react-library/components/Video";
|
|
@@ -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",
|