zy-react-library 2.2.6 → 2.2.8

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 CHANGED
@@ -200,15 +200,15 @@ import { FORM_ITEM_RENDER_ENUM } from "zy-react-library/enum/formItemRender";
200
200
  | `HeaderBack` | `previous=true`。 |
201
201
  | `Upload` | `value=[]`、`ratio=""`、`showTip=true`、`multiple=true`;未传 `fileType` 时根据 `accept` 推断,默认按图片;图片默认 `accept=".jpg,.jpeg,.png"`、`maxCount=4`、`size=10`;视频默认 `accept=".mp4"`、`maxCount=1`、`size=100`;文档默认 `accept=".pdf,.doc,.docx"`、`maxCount=4`、`size=10`。 |
202
202
  | `ImportFile` | `title="导入"`、`labelCol={ span: 4 }`、`exportTemplateButtonText="导出模板"`;弹窗宽度 `600`,内置附件上传 `accept=".xls,.xlsx"`、`listType="text"`、`maxCount=1`。 |
203
- | `PreviewImg` | `files=[]`、`fileUrlKey="filePath"`;图片固定 `width=100`、`height=100`,图片间距 `marginRight=10`、`marginBottom=10`。 |
204
- | `PreviewPdf` | `files=[]`、`nameKey=""`、`urlKey=""`、`name=""`、`url=""`。 |
205
- | `Pdf` | `visible=false`、`inline=false`、`title="PDF预览"`、`style={}`、`usePrint=false`。 |
206
- | `PreviewExcel` | `files=[]`、`nameKey=""`、`urlKey=""`、`name=""`、`url=""`。 |
207
- | `Excel` | `visible=false`、`inline=false`、`title="Excel预览"`、`style={}`、`extraButtons` 不传;弹窗宽度 `1000`,内容高度 `72vh`。 |
208
- | `PreviewWord` | `files=[]`、`nameKey=""`、`urlKey=""`、`name=""`、`url=""`。 |
209
- | `Word` | `visible=false`、`inline=false`、`title="Word预览"`、`style={}`、`extraButtons` 不传;弹窗宽度 `900`,内容高度 `72vh`,默认背景 `#f5f5f5`、内边距 `24px`。 |
210
- | `Descriptions` | `dataSource={}`、`items=[]`、`emptyText="-"`、`loading=false`、`column=2`;`styles.label.width=200`。 |
211
- | `FilePreview` | `files=[]`、`nameKey=""`、`urlKey=""`、`componentProps={}`;单文件 `name`、`url` 不传。 |
203
+ | `PreviewImg` | `files=[]`、`fileUrlKey="filePath"`;图片固定 `width=100`、`height=100`,图片间距 `marginRight=10`、`marginBottom=10`。 |
204
+ | `PreviewPdf` | `files=[]`、`nameKey=""`、`urlKey=""`、`name=""`、`url=""`。 |
205
+ | `Pdf` | `visible=false`、`inline=false`、`title="PDF预览"`、`style={}`、`usePrint=false`。 |
206
+ | `PreviewExcel` | `files=[]`、`nameKey=""`、`urlKey=""`、`name=""`、`url=""`。 |
207
+ | `Excel` | `visible=false`、`inline=false`、`title="Excel预览"`、`style={}`、`extraButtons` 不传;弹窗宽度 `1000`,内容高度 `72vh`。 |
208
+ | `PreviewWord` | `files=[]`、`nameKey=""`、`urlKey=""`、`name=""`、`url=""`。 |
209
+ | `Word` | `visible=false`、`inline=false`、`title="Word预览"`、`style={}`、`extraButtons` 不传;弹窗宽度 `900`,内容高度 `72vh`,默认背景 `#f5f5f5`、内边距 `24px`。 |
210
+ | `Descriptions` | `dataSource={}`、`items=[]`、`emptyText="-"`、`loading=false`、`column=2`;`styles.label.width=200`。 |
211
+ | `FilePreview` | `files=[]`、`nameKey=""`、`urlKey=""`、`componentProps={}`;单文件 `name`、`url` 不传。 |
212
212
  | `Video` | `source=""`、`vid=""`、`playAuth=""`、`cover=""`、`autoplay=true`、`showProgress=true`、`playTime=0`、`inline=false`、`isLive=false`、`width="100%"`、`height="600px"`、`title="视频"`、`visible=false`、`aliPlayerProps={}`;弹窗宽度 `800`。 |
213
213
  | `AliPlayer` | `source=""`、`vid=""`、`playAuth=""`、`cover=""`、`width="100%"`、`height="600px"`、`autoplay=true`、`showProgress=true`、`isLive=false`、`playTime=0`。 |
214
214
  | `Signature` | `width=752`、`height=300`、`url=""`;签名弹窗宽度 `800`,画笔颜色 `black`,画布背景 `rgb(255,255,255)`。 |
@@ -433,92 +433,92 @@ import PreviewImg from "zy-react-library/components/PreviewImg";
433
433
 
434
434
  | 参数 | 类型 | 必填 | 默认值 | 说明 |
435
435
  | --- | --- | --- | --- | --- |
436
- | `files` | `string[] \| { filePath?: string; [key: string]: string }[]` | 否 | `[]` | 图片地址数组,或包含图片地址字段的对象数组。 |
437
- | `fileUrlKey` | `string` | 否 | `"filePath"` | 对象数组中图片地址字段名。 |
438
-
439
- ### Descriptions
440
-
441
- 引入:
442
-
443
- ```tsx
444
- import Descriptions from "zy-react-library/components/Descriptions";
445
- ```
446
-
447
- 配置式详情展示组件,基于 antd `Descriptions`,支持字段取值、嵌套路径、动态隐藏、自定义渲染、空值和加载状态。其余参数继承并透传给 antd `Descriptions`。
448
-
449
- ```tsx
450
- <Descriptions
451
- dataSource={{ user: { name: "张三" }, status: 1 }}
452
- items={[
453
- { label: "姓名", dataIndex: ["user", "name"] },
454
- { label: "状态", dataIndex: "status", render: value => value === 1 ? "启用" : "停用" },
455
- ]}
456
- />
457
- ```
458
-
459
- | 参数 | 类型 | 必填 | 默认值 | 说明 |
460
- | --- | --- | --- | --- | --- |
461
- | `dataSource` | `DataSource` | 否 | `{}` | 详情数据。 |
462
- | `items` | `DescriptionItem<DataSource>[]` | 否 | `[]` | 详情字段配置,继承 antd `DescriptionsItemType`。 |
463
- | `emptyText` | `ReactNode` | 否 | `"-"` | 字段值为空时展示的内容。 |
464
- | `loading` | `boolean` | 否 | `false` | 是否显示加载状态。 |
465
- | `column` | `number \| Partial<Record<Breakpoint, number>>` | 否 | `2` | 每行显示的字段数量,透传给 antd `Descriptions`。 |
466
- | `styles` | `DescriptionsProps["styles"]` | 否 | `label.width=200` | 语义化样式;自定义 `styles.label.width` 时会覆盖默认值。 |
467
-
468
- `DescriptionItem` 在 antd `DescriptionsItemType` 基础上扩展以下参数:
469
-
470
- | 参数 | 类型 | 必填 | 默认值 | 说明 |
471
- | --- | --- | --- | --- | --- |
472
- | `dataIndex` | `string \| number \| (string \| number)[]` | 否 | - | 数据字段路径,支持字符串、数字和数组路径。 |
473
- | `emptyText` | `ReactNode` | 否 | 继承组件 `emptyText` | 当前字段为空时展示的内容。 |
474
- | `hidden` | `boolean \| ((dataSource) => boolean)` | 否 | `false` | 是否隐藏当前字段,支持根据数据动态判断。 |
475
- | `render` | `(value, dataSource, index) => ReactNode` | 否 | - | 自定义字段内容。 |
476
-
477
- ### FilePreview
478
-
479
- 引入:
480
-
481
- ```tsx
482
- import FilePreview from "zy-react-library/components/FilePreview";
483
- ```
484
-
485
- 文件预览组合组件,根据 URL 后缀将附件交给已有的 `PreviewImg`、`Pdf`、`Word`、`Excel` 或 `Video` 组件处理。支持 `files` 多文件模式,以及 `name + url` 单文件模式;两种模式不建议同时传入,组件优先使用 `files`。
486
-
487
- 支持的 URL 后缀:图片 `jpg`、`jpeg`、`png`、`gif`、`webp`、`bmp`、`svg`,PDF `pdf`,Word `docx`,Excel `xlsx`,视频 `mp4`、`webm`、`m3u8`。无法识别的后缀只显示文件名和“暂不支持预览”。
488
-
489
- ```tsx
490
- <FilePreview
491
- files={[
492
- { filePath: "/files/photo.jpg", fileName: "现场照片.jpg" },
493
- { filePath: "/files/report.docx", fileName: "检查报告.docx" },
494
- ]}
495
- componentProps={{
496
- pdf: { usePrint: true },
497
- video: { autoplay: false },
498
- }}
499
- />
500
- ```
501
-
502
- | 参数 | 类型 | 必填 | 默认值 | 说明 |
503
- | --- | --- | --- | --- | --- |
504
- | `files` | `{ filePath?: string; fileName?: string; name?: string; [key: string]: string }[]` | 否 | `[]` | 多文件数据;和 `name`、`url` 单文件模式冲突。默认从 `filePath`、`url` 读取地址,从 `name`、`fileName` 读取文件名。 |
505
- | `nameKey` | `string` | 否 | `""` | 自定义文件名字段名,优先级低于 `name`、`fileName`。 |
506
- | `urlKey` | `string` | 否 | `""` | 自定义文件地址字段名,优先级低于 `filePath`、`url`。 |
507
- | `name` | `string` | 否 | - | 单文件文件名,和 `url` 配合使用。 |
508
- | `url` | `string` | 否 | - | 单文件地址,和 `name` 配合使用。 |
509
- | `componentProps` | `FilePreviewComponentProps` | 否 | `{}` | 各底层预览组件的额外参数。 |
510
-
511
- `FilePreviewComponentProps` 参数如下,受控参数由 `FilePreview` 内部传入,不应通过 `componentProps` 覆盖:
512
-
513
- | 参数 | 类型 | 说明 |
514
- | --- | --- | --- |
515
- | `image` | `Omit<PreviewImgProps, "files">` | 透传给 `PreviewImg`,`files` 由 `FilePreview` 根据当前附件传入。 |
516
- | `pdf` | `Omit<PdfProps, "file" \| "name" \| "visible" \| "onCancel">` | 透传给 `Pdf`。 |
517
- | `word` | `Omit<WordProps, "file" \| "name" \| "visible" \| "onCancel">` | 透传给 `Word`。 |
518
- | `excel` | `Omit<ExcelProps, "file" \| "name" \| "visible" \| "onCancel">` | 透传给 `Excel`。 |
519
- | `video` | `Omit<VideoProps, "source" \| "title" \| "visible" \| "onCancel">` | 透传给 `Video`。 |
520
-
521
- ### TooltipPreviewImg
436
+ | `files` | `string[] \| { filePath?: string; [key: string]: string }[]` | 否 | `[]` | 图片地址数组,或包含图片地址字段的对象数组。 |
437
+ | `fileUrlKey` | `string` | 否 | `"filePath"` | 对象数组中图片地址字段名。 |
438
+
439
+ ### Descriptions
440
+
441
+ 引入:
442
+
443
+ ```tsx
444
+ import Descriptions from "zy-react-library/components/Descriptions";
445
+ ```
446
+
447
+ 配置式详情展示组件,基于 antd `Descriptions`,支持字段取值、嵌套路径、动态隐藏、自定义渲染、空值和加载状态。其余参数继承并透传给 antd `Descriptions`。
448
+
449
+ ```tsx
450
+ <Descriptions
451
+ dataSource={{ user: { name: "张三" }, status: 1 }}
452
+ items={[
453
+ { label: "姓名", dataIndex: ["user", "name"] },
454
+ { label: "状态", dataIndex: "status", render: value => value === 1 ? "启用" : "停用" },
455
+ ]}
456
+ />
457
+ ```
458
+
459
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
460
+ | --- | --- | --- | --- | --- |
461
+ | `dataSource` | `DataSource` | 否 | `{}` | 详情数据。 |
462
+ | `items` | `DescriptionItem<DataSource>[]` | 否 | `[]` | 详情字段配置,继承 antd `DescriptionsItemType`。 |
463
+ | `emptyText` | `ReactNode` | 否 | `"-"` | 字段值为空时展示的内容。 |
464
+ | `loading` | `boolean` | 否 | `false` | 是否显示加载状态。 |
465
+ | `column` | `number \| Partial<Record<Breakpoint, number>>` | 否 | `2` | 每行显示的字段数量,透传给 antd `Descriptions`。 |
466
+ | `styles` | `DescriptionsProps["styles"]` | 否 | `label.width=200` | 语义化样式;自定义 `styles.label.width` 时会覆盖默认值。 |
467
+
468
+ `DescriptionItem` 在 antd `DescriptionsItemType` 基础上扩展以下参数:
469
+
470
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
471
+ | --- | --- | --- | --- | --- |
472
+ | `dataIndex` | `string \| number \| (string \| number)[]` | 否 | - | 数据字段路径,支持字符串、数字和数组路径。 |
473
+ | `emptyText` | `ReactNode` | 否 | 继承组件 `emptyText` | 当前字段为空时展示的内容。 |
474
+ | `hidden` | `boolean \| ((dataSource) => boolean)` | 否 | `false` | 是否隐藏当前字段,支持根据数据动态判断。 |
475
+ | `render` | `(value, dataSource, index) => ReactNode` | 否 | - | 自定义字段内容。 |
476
+
477
+ ### FilePreview
478
+
479
+ 引入:
480
+
481
+ ```tsx
482
+ import FilePreview from "zy-react-library/components/FilePreview";
483
+ ```
484
+
485
+ 文件预览组合组件,根据 URL 后缀将附件交给已有的 `PreviewImg`、`Pdf`、`Word`、`Excel` 或 `Video` 组件处理。支持 `files` 多文件模式,以及 `name + url` 单文件模式;两种模式不建议同时传入,组件优先使用 `files`。
486
+
487
+ 支持的 URL 后缀:图片 `jpg`、`jpeg`、`png`、`gif`、`webp`、`bmp`、`svg`,PDF `pdf`,Word `docx`,Excel `xlsx`,视频 `mp4`、`webm`、`m3u8`。无法识别的后缀只显示文件名和“暂不支持预览”。
488
+
489
+ ```tsx
490
+ <FilePreview
491
+ files={[
492
+ { filePath: "/files/photo.jpg", fileName: "现场照片.jpg" },
493
+ { filePath: "/files/report.docx", fileName: "检查报告.docx" },
494
+ ]}
495
+ componentProps={{
496
+ pdf: { usePrint: true },
497
+ video: { autoplay: false },
498
+ }}
499
+ />
500
+ ```
501
+
502
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
503
+ | --- | --- | --- | --- | --- |
504
+ | `files` | `{ filePath?: string; fileName?: string; name?: string; [key: string]: string }[]` | 否 | `[]` | 多文件数据;和 `name`、`url` 单文件模式冲突。默认从 `filePath`、`url` 读取地址,从 `name`、`fileName` 读取文件名。 |
505
+ | `nameKey` | `string` | 否 | `""` | 自定义文件名字段名,优先级低于 `name`、`fileName`。 |
506
+ | `urlKey` | `string` | 否 | `""` | 自定义文件地址字段名,优先级低于 `filePath`、`url`。 |
507
+ | `name` | `string` | 否 | - | 单文件文件名,和 `url` 配合使用。 |
508
+ | `url` | `string` | 否 | - | 单文件地址,和 `name` 配合使用。 |
509
+ | `componentProps` | `FilePreviewComponentProps` | 否 | `{}` | 各底层预览组件的额外参数。 |
510
+
511
+ `FilePreviewComponentProps` 参数如下,受控参数由 `FilePreview` 内部传入,不应通过 `componentProps` 覆盖:
512
+
513
+ | 参数 | 类型 | 说明 |
514
+ | --- | --- | --- |
515
+ | `image` | `Omit<PreviewImgProps, "files">` | 透传给 `PreviewImg`,`files` 由 `FilePreview` 根据当前附件传入。 |
516
+ | `pdf` | `Omit<PdfProps, "file" \| "name" \| "visible" \| "onCancel">` | 透传给 `Pdf`。 |
517
+ | `word` | `Omit<WordProps, "file" \| "name" \| "visible" \| "onCancel">` | 透传给 `Word`。 |
518
+ | `excel` | `Omit<ExcelProps, "file" \| "name" \| "visible" \| "onCancel">` | 透传给 `Excel`。 |
519
+ | `video` | `Omit<VideoProps, "source" \| "title" \| "visible" \| "onCancel">` | 透传给 `Video`。 |
520
+
521
+ ### TooltipPreviewImg
522
522
 
523
523
  引入:
524
524
 
@@ -563,10 +563,10 @@ PDF 展示组件。
563
563
  | `visible` | `boolean` | 否 | `false` | 是否以弹窗形式显示。 |
564
564
  | `title` | `string` | 否 | `"PDF预览"` | 弹窗标题。 |
565
565
  | `onCancel` | `() => void` | 否 | - | 关闭弹窗回调。 |
566
- | `inline` | `boolean` | 否 | `false` | 是否内联展示。 |
567
- | `style` | `CSSProperties` | 否 | `{}` | 外层样式。 |
568
- | `extraButtons` | `ReactNode` | 否 | - | 弹窗底部额外按钮。 |
569
- | `usePrint` | `boolean` | 否 | `false` | 是否显示打印按钮。 |
566
+ | `inline` | `boolean` | 否 | `false` | 是否内联展示。 |
567
+ | `style` | `CSSProperties` | 否 | `{}` | 外层样式。 |
568
+ | `extraButtons` | `ReactNode` | 否 | - | 弹窗底部额外按钮。 |
569
+ | `usePrint` | `boolean` | 否 | `false` | 是否显示打印按钮。 |
570
570
 
571
571
  ### PreviewExcel
572
572
 
@@ -603,9 +603,9 @@ Excel 展示组件,使用 `exceljs` 解析 `xlsx`,再通过 `x-data-spreadsh
603
603
  | `file` | `string` | 否 | - | `xlsx` 文件地址;非完整文件服务地址时会自动拼接 `getFileUrl()`。 |
604
604
  | `name` | `string` | 否 | - | 文件名,用于下载。 |
605
605
  | `inline` | `boolean` | 否 | `false` | 是否内联展示。 |
606
- | `title` | `string` | 否 | `"Excel预览"` | 弹窗标题。 |
607
- | `style` | `CSSProperties` | 否 | `{}` | 内容区域样式,会合并到高度为 `72vh` 的外层容器。 |
608
- | `extraButtons` | `ReactNode` | 否 | - | 弹窗底部额外按钮。 |
606
+ | `title` | `string` | 否 | `"Excel预览"` | 弹窗标题。 |
607
+ | `style` | `CSSProperties` | 否 | `{}` | 内容区域样式,会合并到高度为 `72vh` 的外层容器。 |
608
+ | `extraButtons` | `ReactNode` | 否 | - | 弹窗底部额外按钮。 |
609
609
 
610
610
  ### PreviewWord
611
611
 
@@ -642,9 +642,9 @@ Word 展示组件,使用 `docx-preview` 渲染 `docx` 文件。
642
642
  | `file` | `string` | 否 | - | `docx` 文件地址;非完整文件服务地址时会自动拼接 `getFileUrl()`。 |
643
643
  | `name` | `string` | 否 | - | 文件名,用于下载。 |
644
644
  | `inline` | `boolean` | 否 | `false` | 是否内联展示。 |
645
- | `title` | `string` | 否 | `"Word预览"` | 弹窗标题。 |
646
- | `style` | `CSSProperties` | 否 | `{}` | 内容区域样式,会合并到默认高度 `72vh`、背景 `#f5f5f5`、内边距 `24px` 的外层容器。 |
647
- | `extraButtons` | `ReactNode` | 否 | - | 弹窗底部额外按钮。 |
645
+ | `title` | `string` | 否 | `"Word预览"` | 弹窗标题。 |
646
+ | `style` | `CSSProperties` | 否 | `{}` | 内容区域样式,会合并到默认高度 `72vh`、背景 `#f5f5f5`、内边距 `24px` 的外层容器。 |
647
+ | `extraButtons` | `ReactNode` | 否 | - | 弹窗底部额外按钮。 |
648
648
 
649
649
  ### Video
650
650
 
@@ -23,6 +23,8 @@ export interface DescriptionsProps<DataSource = Record<string, any>> extends Omi
23
23
  emptyText?: ReactNode;
24
24
  /** 是否加载中,默认 false */
25
25
  loading?: boolean;
26
+ /** 是否展示边框,默认 true */
27
+ bordered?: boolean;
26
28
  }
27
29
 
28
30
  /**
@@ -1 +1 @@
1
- import{Spin as e,Descriptions as t}from"antd";import{get as r}from"lodash-es";import{isEmpty as n}from"../../utils/index.js";import{jsx as i}from"react/jsx-runtime";const o=o=>{const{dataSource:s={},items:a=[],emptyText:l="-",loading:m=!1,column:d=2,styles:c,...p}=o,u=a.map((e,t)=>{const{dataIndex:i,hidden:o,render:a,emptyText:m,...d}=e;if("function"==typeof o?o(s):o)return null;const c=((e,t)=>{if(void 0!==t)return r(e,t)})(s,i),p=a?a(c,s,t):c;return{...d,key:d.key??(Array.isArray(i)?i.join("."):i)??t,children:n(p)?m??l:p}}).filter(Boolean);return i(e,{spinning:m,children:i(t,{...p,column:d,items:u,styles:{...c,label:{width:200,...c?.label}}})})};o.displayName="Descriptions";export{o as default};
1
+ import{Spin as e,Descriptions as r}from"antd";import{get as t}from"lodash-es";import{isEmpty as n}from"../../utils/index.js";import{jsx as i}from"react/jsx-runtime";const o=o=>{const{dataSource:s={},items:d=[],emptyText:a="-",loading:l=!1,bordered:m=!0,column:c=2,styles:p,...u}=o,f=d.map((e,r)=>{const{dataIndex:i,hidden:o,render:d,emptyText:l,...m}=e;if("function"==typeof o?o(s):o)return null;const c=((e,r)=>{if(void 0!==r)return t(e,r)})(s,i),p=d?d(c,s,r):c;return{...m,key:m.key??(Array.isArray(i)?i.join("."):i)??r,children:n(p)?l??a:p}}).filter(Boolean);return i(e,{spinning:l,children:i(r,{...u,bordered:m,column:c,items:f,styles:{...p,label:{width:200,...p?.label}}})})};o.displayName="Descriptions";export{o as default};
@@ -1 +1 @@
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
+ import{useFullscreen as e}from"ahooks";import{Modal as r,Button as t,Spin as o,message as n}from"antd";import{useState as i,useRef as a}from"react";import{pdfjs as c,Document as l,Page as d}from"react-pdf";import s 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:g,file:x,name:y,inline:v=!1,title:w="PDF预览",style:k={},extraButtons:b,usePrint:L=!1}=h,C=p(),j=x.includes(C)?x:C+x,[P,F]=i(0),[D,R]=i(600),S=a(null),[U,{enterFullscreen:E,exitFullscreen:O}]=e(S),{downloadFile:W}=s();c.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${c.version}/build/pdf.worker.min.mjs`;const A=({numPages:e})=>{F(e)},B=()=>{n.error("加载 PDF 文件失败"),g&&g()},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(l,{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,r)=>m(d,{pageNumber:r+1,onLoadSuccess:N},`page_${r+1}`))})})});return v?T():m("div",{ref:S,children:m(r,{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:w,onCancel:()=>{U&&O(),g()},getContainer:!1,footer:[m(t,{onClick:()=>{U&&O(),g()},children:"关闭"},"cancel"),m(t,{onClick:()=>{U?O():E()},children:U?"退出全屏":"全屏"},"fullScreen"),m(t,{type:"primary",onClick:()=>{U&&O(),W({url:x,name:y})},children:"下载"},"download"),L&&m(t,{type:"primary",onClick:async()=>{try{const e=await fetch(j);if(!e.ok)return void n.warning("获取 PDF 文件失败");const r=URL.createObjectURL(await e.blob()),t=document.createElement("iframe");t.style.cssText="position:fixed;width:0;height:0;border:0",t.onload=()=>{const e=t.contentWindow,o=()=>{URL.revokeObjectURL(r),t.remove()};e.addEventListener("afterprint",o,{once:!0});try{e.focus(),e.print()}catch(e){o(),n.error(e.message||"打印失败,请稍后重试")}},t.src=r,document.body.appendChild(t)}catch(e){n.error(e.message||"打印失败,请稍后重试")}},children:"打印"},"print"),...b||[]],children:T()})})}h.displayName="Pdf";export{h 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.6",
4
+ "version": "2.2.8",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",