zy-react-library 2.2.4 → 2.2.6

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,13 +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={}`。 |
206
- | `PreviewExcel` | `files=[]`、`nameKey=""`、`urlKey=""`、`name=""`、`url=""`。 |
207
- | `Excel` | `visible=false`、`inline=false`、`title="Excel预览"`、`style={}`;弹窗宽度 `1000`,内容高度 `72vh`。 |
208
- | `PreviewWord` | `files=[]`、`nameKey=""`、`urlKey=""`、`name=""`、`url=""`。 |
209
- | `Word` | `visible=false`、`inline=false`、`title="Word预览"`、`style={}`;弹窗宽度 `900`,内容高度 `72vh`,默认背景 `#f5f5f5`、内边距 `24px`。 |
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` 不传。 |
210
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`。 |
211
213
  | `AliPlayer` | `source=""`、`vid=""`、`playAuth=""`、`cover=""`、`width="100%"`、`height="600px"`、`autoplay=true`、`showProgress=true`、`isLive=false`、`playTime=0`。 |
212
214
  | `Signature` | `width=752`、`height=300`、`url=""`;签名弹窗宽度 `800`,画笔颜色 `black`,画布背景 `rgb(255,255,255)`。 |
@@ -431,10 +433,92 @@ import PreviewImg from "zy-react-library/components/PreviewImg";
431
433
 
432
434
  | 参数 | 类型 | 必填 | 默认值 | 说明 |
433
435
  | --- | --- | --- | --- | --- |
434
- | `files` | `string[] \| { filePath?: string; [key: string]: string }[]` | 是 | `[]` | 图片地址数组,或包含图片地址字段的对象数组。 |
435
- | `fileUrlKey` | `string` | 否 | `"filePath"` | 对象数组中图片地址字段名。 |
436
-
437
- ### 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
438
522
 
439
523
  引入:
440
524
 
@@ -479,8 +563,10 @@ PDF 展示组件。
479
563
  | `visible` | `boolean` | 否 | `false` | 是否以弹窗形式显示。 |
480
564
  | `title` | `string` | 否 | `"PDF预览"` | 弹窗标题。 |
481
565
  | `onCancel` | `() => void` | 否 | - | 关闭弹窗回调。 |
482
- | `inline` | `boolean` | 否 | `false` | 是否内联展示。 |
483
- | `style` | `CSSProperties` | 否 | `{}` | 外层样式。 |
566
+ | `inline` | `boolean` | 否 | `false` | 是否内联展示。 |
567
+ | `style` | `CSSProperties` | 否 | `{}` | 外层样式。 |
568
+ | `extraButtons` | `ReactNode` | 否 | - | 弹窗底部额外按钮。 |
569
+ | `usePrint` | `boolean` | 否 | `false` | 是否显示打印按钮。 |
484
570
 
485
571
  ### PreviewExcel
486
572
 
@@ -517,8 +603,9 @@ Excel 展示组件,使用 `exceljs` 解析 `xlsx`,再通过 `x-data-spreadsh
517
603
  | `file` | `string` | 否 | - | `xlsx` 文件地址;非完整文件服务地址时会自动拼接 `getFileUrl()`。 |
518
604
  | `name` | `string` | 否 | - | 文件名,用于下载。 |
519
605
  | `inline` | `boolean` | 否 | `false` | 是否内联展示。 |
520
- | `title` | `string` | 否 | `"Excel预览"` | 弹窗标题。 |
521
- | `style` | `Record<string, any>` | 否 | `{}` | 内容区域样式,会合并到高度为 `72vh` 的外层容器。 |
606
+ | `title` | `string` | 否 | `"Excel预览"` | 弹窗标题。 |
607
+ | `style` | `CSSProperties` | 否 | `{}` | 内容区域样式,会合并到高度为 `72vh` 的外层容器。 |
608
+ | `extraButtons` | `ReactNode` | 否 | - | 弹窗底部额外按钮。 |
522
609
 
523
610
  ### PreviewWord
524
611
 
@@ -555,8 +642,9 @@ Word 展示组件,使用 `docx-preview` 渲染 `docx` 文件。
555
642
  | `file` | `string` | 否 | - | `docx` 文件地址;非完整文件服务地址时会自动拼接 `getFileUrl()`。 |
556
643
  | `name` | `string` | 否 | - | 文件名,用于下载。 |
557
644
  | `inline` | `boolean` | 否 | `false` | 是否内联展示。 |
558
- | `title` | `string` | 否 | `"Word预览"` | 弹窗标题。 |
559
- | `style` | `Record<string, any>` | 否 | `{}` | 内容区域样式,会合并到默认高度 `72vh`、背景 `#f5f5f5`、内边距 `24px` 的外层容器。 |
645
+ | `title` | `string` | 否 | `"Word预览"` | 弹窗标题。 |
646
+ | `style` | `CSSProperties` | 否 | `{}` | 内容区域样式,会合并到默认高度 `72vh`、背景 `#f5f5f5`、内边距 `24px` 的外层容器。 |
647
+ | `extraButtons` | `ReactNode` | 否 | - | 弹窗底部额外按钮。 |
560
648
 
561
649
  ### Video
562
650
 
@@ -0,0 +1,31 @@
1
+ import type { DescriptionsProps as AntDescriptionsProps, DescriptionsItemType } from "antd/es/descriptions";
2
+ import type { ReactElement, ReactNode } from "react";
3
+
4
+ export type DescriptionDataIndex = string | number | (string | number)[];
5
+
6
+ export interface DescriptionItem<DataSource = Record<string, any>> extends Omit<DescriptionsItemType, "children"> {
7
+ /** 数据字段,支持嵌套路径 */
8
+ dataIndex?: DescriptionDataIndex;
9
+ /** 当前字段为空时展示的内容,默认继承组件 emptyText */
10
+ emptyText?: ReactNode;
11
+ /** 是否隐藏当前项 */
12
+ hidden?: boolean | ((dataSource: DataSource) => boolean);
13
+ /** 自定义字段内容 */
14
+ render?: (value: any, dataSource: DataSource, index: number) => ReactNode;
15
+ }
16
+
17
+ export interface DescriptionsProps<DataSource = Record<string, any>> extends Omit<AntDescriptionsProps, "items"> {
18
+ /** 详情数据,默认 {} */
19
+ dataSource?: DataSource;
20
+ /** 字段配置,默认 [] */
21
+ items?: DescriptionItem<DataSource>[];
22
+ /** 空值展示内容,默认 "-" */
23
+ emptyText?: ReactNode;
24
+ /** 是否加载中,默认 false */
25
+ loading?: boolean;
26
+ }
27
+
28
+ /**
29
+ * 配置式详情展示组件
30
+ */
31
+ export default function Descriptions<DataSource = Record<string, any>>(props: DescriptionsProps<DataSource>): ReactElement;
@@ -0,0 +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,7 +1,7 @@
1
1
  import type { CSSProperties, FC, ReactNode } from "react";
2
2
 
3
3
  export interface ExcelProps {
4
- /** 是否显示弹窗 */
4
+ /** 是否显示弹窗,默认 false */
5
5
  visible?: boolean;
6
6
  /** 关闭回调 */
7
7
  onCancel?: () => void;
@@ -9,9 +9,9 @@ export interface ExcelProps {
9
9
  file?: string;
10
10
  /** xlsx 文件名 */
11
11
  name?: string;
12
- /** 是否内联展示 */
12
+ /** 是否内联展示,默认 false */
13
13
  inline?: boolean;
14
- /** 弹窗标题 */
14
+ /** 弹窗标题,默认 "Excel预览" */
15
15
  title?: string;
16
16
  /** 内联模式下的样式 */
17
17
  style?: CSSProperties;
@@ -1 +1 @@
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
+ 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:p,file:w,name:v,inline:g=!1,title:y="Excel预览",style:C={},extraButtons:E}=h,k=o(null),I=o(null),T=o(!1),b=s(),[j,S]=l(!1),{downloadFile:D}=u();c(()=>{if(!x&&!g||!w)return;T.current=!1;const e=setTimeout(()=>{(async()=>{S(!0),k.current.innerHTML="";try{const e=await fetch(w.includes(b)?w:b+w);if(!e.ok)return void r.error("加载 Excel 文件失败");const t=await e.arrayBuffer(),n=new i.Workbook;if(await n.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),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:{}}]}(n))}catch{r.error("加载 Excel 文件失败"),p&&p()}finally{T.current||S(!1)}})()},100);return()=>{T.current=!0,k.current&&(k.current.innerHTML=""),e&&clearTimeout(e)}},[x,g,w]);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:()=>{p()},getContainer:!1,footer:[d(t,{onClick:()=>{p()},children:"关闭"},"cancel"),d(t,{type:"primary",onClick:()=>{D({url:w,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};
@@ -0,0 +1,38 @@
1
+ import type { FC } from "react";
2
+ import type { ExcelProps } from "../Excel";
3
+ import type { PdfProps } from "../Pdf";
4
+ import type { PreviewImgProps } from "../PreviewImg";
5
+ import type { VideoProps } from "../Video";
6
+ import type { WordProps } from "../Word";
7
+
8
+ export interface FilePreviewComponentProps {
9
+ /** 图片组件参数 */
10
+ image?: Omit<PreviewImgProps, "files">;
11
+ /** PDF 组件参数 */
12
+ pdf?: Omit<PdfProps, "file" | "name" | "visible" | "onCancel">;
13
+ /** Word 组件参数 */
14
+ word?: Omit<WordProps, "file" | "name" | "visible" | "onCancel">;
15
+ /** Excel 组件参数 */
16
+ excel?: Omit<ExcelProps, "file" | "name" | "visible" | "onCancel">;
17
+ /** 视频组件参数 */
18
+ video?: Omit<VideoProps, "source" | "title" | "visible" | "onCancel">;
19
+ }
20
+
21
+ export interface FilePreviewProps {
22
+ /** 文件列表,和 name、url 冲突 */
23
+ files?: { filePath?: string; fileName?: string; name?: string; [key: string]: string }[];
24
+ /** 文件名字段名,传入 files 时优先查找 name、fileName */
25
+ nameKey?: string;
26
+ /** 文件路径字段名,传入 files 时优先查找 filePath、url */
27
+ urlKey?: string;
28
+ /** 单个文件名,和 files 冲突 */
29
+ name?: string;
30
+ /** 单个文件路径,和 files 冲突 */
31
+ url?: string;
32
+ /** 各底层预览组件的额外参数 */
33
+ componentProps?: FilePreviewComponentProps;
34
+ }
35
+
36
+ declare const FilePreview: FC<FilePreviewProps>;
37
+
38
+ export default FilePreview;
@@ -0,0 +1 @@
1
+ import{Space as e,Button as i}from"antd";import{useState as r}from"react";import{getFileName as l}from"../../utils/index.js";import n from"../Excel/index.js";import m from"../Pdf/index.js";import o from"../PreviewImg/index.js";import t from"../Video/index.js";import a from"../Word/index.js";import{jsxs as d,Fragment as p,jsx as s}from"react/jsx-runtime";const c=c=>{const{files:u=[],nameKey:f="",urlKey:x="",name:v,url:g,componentProps:h={}}=c,[y,j]=r(null),w=u.length>0?u.map(e=>{const i=e.filePath||e.url||e[x];return{name:e.name||e.fileName||e[f]||l(i),url:i}}).filter(e=>e.url):v&&g?[{name:v,url:g}]:[],b=()=>{j(null)};return 0===w.length?null:d(p,{children:[s(e,{direction:"vertical",children:w.map(r=>{const l=(e=>{const i=e.url.split(/[?#]/)[0],r=i.slice(i.lastIndexOf(".")+1).toLowerCase();return["jpg","jpeg","png","gif","webp","bmp","svg"].includes(r)?"image":"pdf"===r?"pdf":"docx"===r?"word":"xlsx"===r?"excel":["mp4","webm","m3u8"].includes(r)?"video":void 0})(r),n=`${r.name}-${r.url}`;return"image"===l?s(e,{children:s(o,{...h.image,files:[r.url]})},n):d(e,{children:[s("span",{children:r.name}),l?s(i,{type:"primary",size:"small",onClick:()=>((e,i)=>{j({...e,type:i})})(r,l),children:"预览"}):s("span",{children:"暂不支持预览"})]},n)})}),"pdf"===y?.type&&s(m,{...h.pdf,visible:!0,file:y.url,name:y.name,onCancel:b}),"word"===y?.type&&s(a,{...h.word,visible:!0,file:y.url,name:y.name,onCancel:b}),"excel"===y?.type&&s(n,{...h.excel,visible:!0,file:y.url,name:y.name,onCancel:b}),"video"===y?.type&&s(t,{...h.video,visible:!0,source:y.url,title:y.name,onCancel:b})]})};c.displayName="FilePreview";export{c as default};
@@ -2,10 +2,10 @@ import type { FC } from "react";
2
2
 
3
3
  export interface PreviewExcelProps {
4
4
  /** 文件列表,和 name、url 冲突 */
5
- files?: { filePath?: string; fileName?: string; name?: string; url?: string; [key: string]: string }[];
6
- /** 文件名字段名,传入 files 时会优先查找是否存在 name、fileName */
5
+ files?: { filePath?: string; fileName?: string; name?: string; [key: string]: string }[];
6
+ /** 文件名字段名,传入 files 时优先查找 name、fileName */
7
7
  nameKey?: string;
8
- /** 文件路径字段名,传入 files 时会优先查找是否存在 filePath、url */
8
+ /** 文件路径字段名,传入 files 时优先查找 filePath、url */
9
9
  urlKey?: string;
10
10
  /** 单个文件名,和 files 冲突 */
11
11
  name?: string;
@@ -3,9 +3,9 @@ import type { FC } from "react";
3
3
  export interface PreviewPdfProps {
4
4
  /** 文件列表,和 name、url 冲突 */
5
5
  files?: { filePath?: string; fileName?: string; name?: string; [key: string]: string }[];
6
- /** 文件名字段名,传入 files 时会优先查找是否存在 name、fileName */
6
+ /** 文件名字段名,传入 files 时优先查找 name、fileName */
7
7
  nameKey?: string;
8
- /** 文件路径字段名,传入 files 时会优先查找是否存在 filePath */
8
+ /** 文件路径字段名,传入 files 时优先查找 filePath、url */
9
9
  urlKey?: string;
10
10
  /** 单个文件名,和 files 冲突 */
11
11
  name?: string;
@@ -2,10 +2,10 @@ import type { FC } from "react";
2
2
 
3
3
  export interface PreviewWordProps {
4
4
  /** 文件列表,和 name、url 冲突 */
5
- files?: { filePath?: string; fileName?: string; name?: string; url?: string; [key: string]: string }[];
6
- /** 文件名字段名,传入 files 时会优先查找是否存在 name、fileName */
5
+ files?: { filePath?: string; fileName?: string; name?: string; [key: string]: string }[];
6
+ /** 文件名字段名,传入 files 时优先查找 name、fileName */
7
7
  nameKey?: string;
8
- /** 文件路径字段名,传入 files 时会优先查找是否存在 filePath、url */
8
+ /** 文件路径字段名,传入 files 时优先查找 filePath、url */
9
9
  urlKey?: string;
10
10
  /** 单个文件名,和 files 冲突 */
11
11
  name?: string;
@@ -1 +1 @@
1
- import{PlusOutlined as e,VideoCameraAddOutlined as t,UploadOutlined as n}from"@ant-design/icons";import{Upload as i,Modal as r,Button as o,message as l}from"antd";import{useState as a,useRef as s}from"react";import{jsxs as d,Fragment as c,jsx as u}from"react/jsx-runtime";const m=m=>{const{value:p=[],onChange:h,onPreview:g,onRemove:f,onGetRemoveFile:w,beforeUpload:v,maxCount:y,listType:$,accept:x,ratio:j="",showTip:F=!0,multiple:b=!0,size:C,tipContent:T,uploadButtonText:U,fileType:R,...P}=m,[z,L]=a(!1),[O,S]=a(""),B=s(new Set),I=".jpg,.jpeg,.png",M=".pdf,.doc,.docx",A=".mp4",D=R||(()=>{if(x){if("*"===x)return"document";const e=x.split(",");return e.some(e=>A.split(",").includes(e))?"video":e.some(e=>M.split(",").includes(e))?"document":e.some(e=>I.split(",").includes(e))?"image":"document"}return"image"})(),G="image"===D,N="video"===D,W="document"===D,k=$||("*"===x?"text":"image"===D?"picture-card":"text"),q=x?"*"===x?"":x:G?I:N?A:W?M:I,E=y||(N?1:G||W?4:1),H=C||(N?100:10),J=U||(N?"上传视频":"上传附件"),K=q.replace(/\./g,"").split(",").join("、"),Q=()=>T||`${[`最多上传${E}个文件`,q?`并且只能上传${K}格式的文件`:"可以上传任意格式的文件",H?`文件大小不能超过${H}M`:"",j?`只能上传${j}分辨率的图片`:""].filter(Boolean).join(",")}。`,V=G?u("div",{children:u(e,{style:{fontSize:32}})}):u(o,{type:"primary",icon:u(N?t:n,{}),children:J});return d(c,{children:[u(i,{fileList:p,multiple:b,maxCount:E,listType:k,accept:q,onChange:({fileList:e})=>{const t=q?q.split(","):[],n=j?j.split("*"):[],i=1024*H*1024,r=new Set(p.map(e=>e.uid)),o=e.filter(e=>!r.has(e.uid));if(0===o.length)return void h?.(e);const a=e=>{const n=e.name?.substring(e.name.lastIndexOf("."),e.name.length)||"";return!(t.length>0&&!t.includes(n)&&(B.current.has(e.uid)||(B.current.add(e.uid),l.warning(`${e.name}:只能上传${K}格式的文件`)),1))},s=e=>!(i&&e.size>i&&(B.current.has(e.uid)||(B.current.add(e.uid),l.warning(`${e.name}:文件大小不能超过${H}M`)),1)),d=e=>new Promise(t=>{if(2!==n.length||!e.type?.startsWith("image/"))return void t(!0);const i=t=>new Promise(i=>{const r=new Image;r.onload=()=>{const t=r.width===+n[0]&&r.height===+n[1];t||B.current.has(e.uid)||(B.current.add(e.uid),l.warning(`${e.name}:只能上传${j}分辨率的图片`)),i(t)},r.onerror=()=>i(!1),r.src=t});if(e.url)i(e.url).then(t);else{const n=new FileReader;n.onload=e=>{i(e.target.result).then(t)},n.onerror=()=>t(!1),n.readAsDataURL(e.originFileObj)}});(async e=>{const t=[],n=[];for(const i of e)a(i)&&s(i)&&await d(i)?t.push(i):n.push(i);return{validFiles:t,invalidFiles:n}})(o).then(({validFiles:e})=>{const t=[...p,...e];h?.(t)})},onPreview:e=>{G&&(S(e.url||e.thumbUrl),L(!0)),g?.(e)},onRemove:e=>(B.current.delete(e.uid),e.originFileObj||w?.(e),f?.(e)),beforeUpload:(e,t)=>!!v&&v(e,t),...P,children:p.length>=E?null:V}),F?Q()&&u("div",{style:{marginTop:10,color:"#ff4d4f"},children:Q()}):null,u(r,{open:z,title:"查看图片",footer:null,onCancel:()=>{L(!1)},children:u("img",{alt:"preview",style:{width:"100%",objectFit:"scale-down"},src:O})})]})};m.displayName="Upload";export{m as default};
1
+ import{PlusOutlined as e,VideoCameraAddOutlined as n,UploadOutlined as t}from"@ant-design/icons";import{Upload as i,Modal as r,Image as o,Button as l,message as a}from"antd";import{useState as s,useRef as d}from"react";import{jsxs as u,Fragment as c,jsx as m}from"react/jsx-runtime";const p=p=>{const{value:h=[],onChange:g,onPreview:f,onRemove:v,onGetRemoveFile:w,beforeUpload:$,maxCount:y,listType:x,accept:j,ratio:F="",showTip:b=!0,multiple:C=!0,size:T,tipContent:U,uploadButtonText:R,fileType:P,...z}=p,[I,L]=s(!1),[O,S]=s(""),B=d(new Set),M=".jpg,.jpeg,.png",A=".pdf,.doc,.docx",D=".mp4",G=P||(()=>{if(j){if("*"===j)return"document";const e=j.split(",");return e.some(e=>D.split(",").includes(e))?"video":e.some(e=>A.split(",").includes(e))?"document":e.some(e=>M.split(",").includes(e))?"image":"document"}return"image"})(),N="image"===G,W="video"===G,k="document"===G,q=x||("*"===j?"text":"image"===G?"picture-card":"text"),E=j?"*"===j?"":j:N?M:W?D:k?A:M,H=y||(W?1:N||k?4:1),J=T||(W?100:10),K=R||(W?"上传视频":"上传附件"),Q=E.replace(/\./g,"").split(",").join("、"),V=()=>U||`${[`最多上传${H}个文件`,E?`并且只能上传${Q}格式的文件`:"可以上传任意格式的文件",J?`文件大小不能超过${J}M`:"",F?`只能上传${F}分辨率的图片`:""].filter(Boolean).join(",")}。`,X=N?m("div",{children:m(e,{style:{fontSize:32}})}):m(l,{type:"primary",icon:m(W?n:t,{}),children:K});return u(c,{children:[m(i,{fileList:h,multiple:C,maxCount:H,listType:q,accept:E,onChange:({fileList:e})=>{const n=E?E.split(","):[],t=F?F.split("*"):[],i=1024*J*1024,r=new Set(h.map(e=>e.uid)),o=e.filter(e=>!r.has(e.uid));if(0===o.length)return void g?.(e);const l=e=>{const t=e.name?.substring(e.name.lastIndexOf("."),e.name.length)||"";return!(n.length>0&&!n.includes(t)&&(B.current.has(e.uid)||(B.current.add(e.uid),a.warning(`${e.name}:只能上传${Q}格式的文件`)),1))},s=e=>!(i&&e.size>i&&(B.current.has(e.uid)||(B.current.add(e.uid),a.warning(`${e.name}:文件大小不能超过${J}M`)),1)),d=e=>new Promise(n=>{if(2!==t.length||!e.type?.startsWith("image/"))return void n(!0);const i=n=>new Promise(i=>{const r=new Image;r.onload=()=>{const n=r.width===+t[0]&&r.height===+t[1];n||B.current.has(e.uid)||(B.current.add(e.uid),a.warning(`${e.name}:只能上传${F}分辨率的图片`)),i(n)},r.onerror=()=>i(!1),r.src=n});if(e.url)i(e.url).then(n);else{const t=new FileReader;t.onload=e=>{i(e.target.result).then(n)},t.onerror=()=>n(!1),t.readAsDataURL(e.originFileObj)}});(async e=>{const n=[],t=[];for(const i of e)l(i)&&s(i)&&await d(i)?n.push(i):t.push(i);return{validFiles:n,invalidFiles:t}})(o).then(({validFiles:e})=>{const n=[...h,...e];g?.(n)})},onPreview:e=>{N&&(S(e.url||e.thumbUrl),L(!0)),f?.(e)},onRemove:e=>(B.current.delete(e.uid),e.originFileObj||w?.(e),v?.(e)),beforeUpload:(e,n)=>!!$&&$(e,n),...z,children:h.length>=H?null:X}),b?V()&&m("div",{style:{marginTop:10,color:"#ff4d4f"},children:V()}):null,m(r,{open:I,title:"查看图片",footer:null,onCancel:()=>{L(!1)},children:m(o,{alt:"preview",width:"100%",src:O})})]})};p.displayName="Upload";export{p as default};
@@ -1,7 +1,7 @@
1
1
  import type { CSSProperties, FC, ReactNode } from "react";
2
2
 
3
3
  export interface WordProps {
4
- /** 是否显示弹窗 */
4
+ /** 是否显示弹窗,默认 false */
5
5
  visible?: boolean;
6
6
  /** 关闭回调 */
7
7
  onCancel?: () => void;
@@ -9,9 +9,9 @@ export interface WordProps {
9
9
  file?: string;
10
10
  /** docx 文件名 */
11
11
  name?: string;
12
- /** 是否内联展示 */
12
+ /** 是否内联展示,默认 false */
13
13
  inline?: boolean;
14
- /** 弹窗标题 */
14
+ /** 弹窗标题,默认 "Word预览" */
15
15
  title?: string;
16
16
  /** 内联模式下的样式 */
17
17
  style?: CSSProperties;
@@ -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 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};
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:v={},extraButtons:x}=s,y=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),y.current.innerHTML="";try{const r=await fetch(p.includes(C)?p:C+p);if(!r.ok)return void n.error("加载 Word 文件失败");const e=await r.arrayBuffer();if(W.current)return;await i(e,y.current,null,{className:"docx-preview",inWrapper:!0,ignoreWidth:!1,ignoreHeight:!1,breakPages:!0})}catch{n.error("加载 Word 文件失败"),m&&m()}finally{W.current||T(!1)}})()},100);return()=>{W.current=!0,y.current&&(y.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",...v},children:u("div",{ref:y})})});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"),...x||[]],children:B()})})}s.displayName="Word";export{s as default};
@@ -1,45 +1,45 @@
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
+ /** 常见下载文件 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,20 +1,20 @@
1
- export type SetUrlCriteriaQueryFunction = (searchForm: Record<string, any>, pagination: Record<string, any>) => void;
2
-
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>;
16
-
17
- /**
18
- * 处理搜索条件缓存到 URL
19
- */
20
- export default function useUrlQueryCriteria(): { setUrlCriteriaQuery: SetUrlCriteriaQueryFunction; getUrlCriteriaQuery: GetUrlCriteriaQueryFunction };
1
+ export type SetUrlCriteriaQueryFunction = (searchForm: Record<string, any>, pagination: Record<string, any>) => void;
2
+
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>;
16
+
17
+ /**
18
+ * 处理搜索条件缓存到 URL
19
+ */
20
+ export default function useUrlQueryCriteria(): { setUrlCriteriaQuery: SetUrlCriteriaQueryFunction; getUrlCriteriaQuery: GetUrlCriteriaQueryFunction };
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",
4
+ "version": "2.2.6",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",