zy-react-library 1.1.50 → 1.1.52
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
|
|
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};
|