zy-react-library 1.4.6 → 1.4.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.
@@ -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 a,Document as c,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:C=!1}=h,L=p(),j=g.includes(L)?g:L+g,[P,F]=i(0),[D,R]=i(600),S=l(null),[U,{enterFullscreen:E,exitFullscreen:O}]=e(S),{downloadFile:W}=d();a.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${a.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(c,{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,maskClosable:!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"),C&&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 l,Document as c,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:C=!1}=h,L=p(),j=x.includes(L)?x:L+x,[P,F]=i(0),[D,R]=i(600),S=a(null),[U,{enterFullscreen:E,exitFullscreen:O}]=e(S),{downloadFile:W}=s();l.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${l.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(c,{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,maskClosable:!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"),C&&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": "1.4.6",
4
+ "version": "1.4.8",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",