zy-react-library 2.2.5 → 2.2.7

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
@@ -202,11 +202,13 @@ import { FORM_ITEM_RENDER_ENUM } from "zy-react-library/enum/formItemRender";
202
202
  | `ImportFile` | `title="导入"`、`labelCol={ span: 4 }`、`exportTemplateButtonText="导出模板"`;弹窗宽度 `600`,内置附件上传 `accept=".xls,.xlsx"`、`listType="text"`、`maxCount=1`。 |
203
203
  | `PreviewImg` | `files=[]`、`fileUrlKey="filePath"`;图片固定 `width=100`、`height=100`,图片间距 `marginRight=10`、`marginBottom=10`。 |
204
204
  | `PreviewPdf` | `files=[]`、`nameKey=""`、`urlKey=""`、`name=""`、`url=""`。 |
205
- | `Pdf` | `visible=false`、`inline=false`、`title="PDF预览"`、`style={}`。 |
205
+ | `Pdf` | `visible=false`、`inline=false`、`title="PDF预览"`、`style={}`、`usePrint=false`。 |
206
206
  | `PreviewExcel` | `files=[]`、`nameKey=""`、`urlKey=""`、`name=""`、`url=""`。 |
207
- | `Excel` | `visible=false`、`inline=false`、`title="Excel预览"`、`style={}`;弹窗宽度 `1000`,内容高度 `72vh`。 |
207
+ | `Excel` | `visible=false`、`inline=false`、`title="Excel预览"`、`style={}`、`extraButtons` 不传;弹窗宽度 `1000`,内容高度 `72vh`。 |
208
208
  | `PreviewWord` | `files=[]`、`nameKey=""`、`urlKey=""`、`name=""`、`url=""`。 |
209
- | `Word` | `visible=false`、`inline=false`、`title="Word预览"`、`style={}`;弹窗宽度 `900`,内容高度 `72vh`,默认背景 `#f5f5f5`、内边距 `24px`。 |
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,9 +433,91 @@ import PreviewImg from "zy-react-library/components/PreviewImg";
431
433
 
432
434
  | 参数 | 类型 | 必填 | 默认值 | 说明 |
433
435
  | --- | --- | --- | --- | --- |
434
- | `files` | `string[] \| { filePath?: string; [key: string]: string }[]` | 是 | `[]` | 图片地址数组,或包含图片地址字段的对象数组。 |
436
+ | `files` | `string[] \| { filePath?: string; [key: string]: string }[]` | 否 | `[]` | 图片地址数组,或包含图片地址字段的对象数组。 |
435
437
  | `fileUrlKey` | `string` | 否 | `"filePath"` | 对象数组中图片地址字段名。 |
436
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
+
437
521
  ### TooltipPreviewImg
438
522
 
439
523
  引入:
@@ -481,6 +565,8 @@ PDF 展示组件。
481
565
  | `onCancel` | `() => void` | 否 | - | 关闭弹窗回调。 |
482
566
  | `inline` | `boolean` | 否 | `false` | 是否内联展示。 |
483
567
  | `style` | `CSSProperties` | 否 | `{}` | 外层样式。 |
568
+ | `extraButtons` | `ReactNode` | 否 | - | 弹窗底部额外按钮。 |
569
+ | `usePrint` | `boolean` | 否 | `false` | 是否显示打印按钮。 |
484
570
 
485
571
  ### PreviewExcel
486
572
 
@@ -518,7 +604,8 @@ Excel 展示组件,使用 `exceljs` 解析 `xlsx`,再通过 `x-data-spreadsh
518
604
  | `name` | `string` | 否 | - | 文件名,用于下载。 |
519
605
  | `inline` | `boolean` | 否 | `false` | 是否内联展示。 |
520
606
  | `title` | `string` | 否 | `"Excel预览"` | 弹窗标题。 |
521
- | `style` | `Record<string, any>` | 否 | `{}` | 内容区域样式,会合并到高度为 `72vh` 的外层容器。 |
607
+ | `style` | `CSSProperties` | 否 | `{}` | 内容区域样式,会合并到高度为 `72vh` 的外层容器。 |
608
+ | `extraButtons` | `ReactNode` | 否 | - | 弹窗底部额外按钮。 |
522
609
 
523
610
  ### PreviewWord
524
611
 
@@ -556,7 +643,8 @@ Word 展示组件,使用 `docx-preview` 渲染 `docx` 文件。
556
643
  | `name` | `string` | 否 | - | 文件名,用于下载。 |
557
644
  | `inline` | `boolean` | 否 | `false` | 是否内联展示。 |
558
645
  | `title` | `string` | 否 | `"Word预览"` | 弹窗标题。 |
559
- | `style` | `Record<string, any>` | 否 | `{}` | 内容区域样式,会合并到默认高度 `72vh`、背景 `#f5f5f5`、内边距 `24px` 的外层容器。 |
646
+ | `style` | `CSSProperties` | 否 | `{}` | 内容区域样式,会合并到默认高度 `72vh`、背景 `#f5f5f5`、内边距 `24px` 的外层容器。 |
647
+ | `extraButtons` | `ReactNode` | 否 | - | 弹窗底部额外按钮。 |
560
648
 
561
649
  ### Video
562
650
 
@@ -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};
@@ -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};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zy-react-library",
3
3
  "private": false,
4
- "version": "2.2.5",
4
+ "version": "2.2.7",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",