zy-react-library 1.1.50 → 1.1.51

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.
@@ -1 +1 @@
1
- import{PlusOutlined as e,VideoCameraAddOutlined as i,UploadOutlined as t}from"@ant-design/icons";import{Upload as n,Modal as o,Button as l,message as r}from"antd";import{useState as s}from"react";import{jsxs as a,Fragment as d,jsx as c}from"react/jsx-runtime";const p=p=>{const{value:u=[],onChange:m,onPreview:f,onRemove:g,onGetRemoveFile:h,beforeUpload:v,maxCount:w,listType:y,accept:x,ratio:$="",showTip:j=!0,multiple:b=!0,size:C,tipContent:T,uploadButtonText:U,fileType:R,...F}=p,[z,L]=s(!1),[B,I]=s(""),M=".jpg,.jpeg,.png",O=".pdf,.doc,.docx",P=".mp4",A=R||(()=>{if(x){if("*"===x)return"document";const e=x.split(",");return e.some(e=>P.split(",").includes(e))?"video":e.some(e=>O.split(",").includes(e))?"document":e.some(e=>M.split(",").includes(e))?"image":"document"}return"image"})(),D="image"===A,G="video"===A,N="document"===A,S=y||("*"===x?"text":"image"===A?"picture-card":"text"),W=x?"*"===x?"":x:D?M:G?P:N?O:M,k=w||(G?1:D||N?4:1),q=C||(G?100:10),E=U||(G?"上传视频":"上传附件"),H=W.replace(/\./g,"").split(",").join("、"),J=()=>T||`${[`最多上传${k}个文件`,W?`并且只能上传${H}格式的文件`:"可以上传任意格式的文件",q?`文件大小不能超过${q}M`:"",$?`只能上传${$}分辨率的图片`:""].filter(Boolean).join(",")}。`,K=D?c("div",{children:c(e,{style:{fontSize:32}})}):c(l,{type:"primary",icon:c(G?i:t,{}),children:E});return a(d,{children:[c(n,{fileList:u,multiple:b,maxCount:k,listType:S,accept:W,onChange:({file:e,fileList:i})=>{const t=W?W.split(","):[],n=$?$.split("*"):[],o=e.name.substring(e.name.lastIndexOf("."),e.name.length),l=1024*q*1024;if(t.length>0&&!t.includes(o)){r.warning(`只能上传${H}格式的文件`);const t=i.filter(i=>i.uid!==e.uid);return void m?.(t)}if(l&&e.size>l){r.warning(`文件大小不能超过${q}M`);const t=i.filter(i=>i.uid!==e.uid);return void m?.(t)}if(2===n.length&&e.type?.startsWith("image/")){const t=t=>{const o=new Image;o.onload=()=>{if(o.width!==+n[0]||o.height!==+n[1]){r.warning(`只能上传${$}分辨率的图片`);const t=i.filter(i=>i.uid!==e.uid);return void m?.(t)}m?.(i)},o.src=t};if(e.url)t(e.url);else{const i=new FileReader;i.onload=e=>{t(e.target.result)},i.readAsDataURL(e)}}else m?.(i)},onPreview:e=>{D&&(I(e.url||e.thumbUrl),L(!0)),f?.(e)},onRemove:e=>(e.originFileObj||h?.(e),g?.(e)),beforeUpload:(e,i)=>!!v&&v(e,i),...F,children:u.length>=k?null:K}),j?J()&&c("div",{style:{marginTop:10,color:"#ff4d4f"},children:J()}):null,c(o,{open:z,title:"查看图片",footer:null,onCancel:()=>{L(!1)},children:c("img",{alt:"preview",style:{width:"100%",objectFit:"scale-down"},src:B})})]})};p.displayName="Upload";export{p as default};
1
+ import{PlusOutlined as e,VideoCameraAddOutlined as n,UploadOutlined as t}from"@ant-design/icons";import{Upload as i,Modal as o,Button as r,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 p=p=>{const{value:m=[],onChange:g,onPreview:h,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}=p,[z,L]=a(!1),[O,B]=a(""),I=s(new Set),M=".jpg,.jpeg,.png",S=".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=>S.split(",").includes(e))?"document":e.some(e=>M.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?M:N?A:W?S:M,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(r,{type:"primary",icon:u(N?n:t,{}),children:J});return d(c,{children:[u(i,{fileList:m,multiple:b,maxCount:E,listType:k,accept:q,onChange:({fileList:e})=>{console.log(e);const n=q?q.split(","):[],t=j?j.split("*"):[],i=1024*H*1024;(async e=>{const o=[],r=[];for(const a of e){const e=a.name?.substring(a.name.lastIndexOf("."),a.name.length)||"";if(n.length>0&&!n.includes(e))r.push(a),I.current.has(a.uid)||(I.current.add(a.uid),l.warning(`${a.name}:只能上传${K}格式的文件`));else if(i&&a.size>i)r.push(a),I.current.has(a.uid)||(I.current.add(a.uid),l.warning(`${a.name}:文件大小不能超过${H}M`));else{if(2===t.length&&a.type?.startsWith("image/")){const e=e=>new Promise(n=>{const i=new Image;i.onload=()=>{const e=i.width===+t[0]&&i.height===+t[1];e||I.current.has(a.uid)||(I.current.add(a.uid),l.warning(`${a.name}:只能上传${j}分辨率的图片`)),n(e)},i.onerror=()=>n(!1),i.src=e});if(!(a.url?await e(a.url):await new Promise(n=>{const t=new FileReader;t.onload=t=>{e(t.target.result).then(n)},t.onerror=()=>n(!1),t.readAsDataURL(a.originFileObj)}))){r.push(a);continue}}o.push(a)}}return{validFiles:o,invalidFiles:r}})(e).then(({validFiles:e})=>{g?.(e)})},onPreview:e=>{G&&(B(e.url||e.thumbUrl),L(!0)),h?.(e)},onRemove:e=>(I.current.delete(e.uid),e.originFileObj||w?.(e),f?.(e)),beforeUpload:(e,n)=>!!v&&v(e,n),...P,children:m.length>=E?null:V}),F?Q()&&u("div",{style:{marginTop:10,color:"#ff4d4f"},children:Q()}):null,u(o,{open:z,title:"查看图片",footer:null,onCancel:()=>{L(!1)},children:u("img",{alt:"preview",style:{width:"100%",objectFit:"scale-down"},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": "1.1.50",
4
+ "version": "1.1.51",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",