zy-react-library 2.2.15 → 2.2.17
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/components/Excel/index.js +1 -1
- package/components/FilePreview/index.js +1 -1
- package/components/Pdf/index.js +1 -1
- package/components/PreviewImg/index.js +1 -1
- package/components/Video/index.js +1 -1
- package/components/Word/index.js +1 -1
- package/hooks/useDownloadFile/index.js +1 -1
- package/package.json +1 -1
- package/regular/index.d.ts +4 -0
- package/regular/index.js +1 -1
|
@@ -1 +1 @@
|
|
|
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{
|
|
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{HTTP_URL as s}from"../../regular/index.js";import{getFileUrl as d}from"../../utils/index.js";import"x-data-spreadsheet/dist/xspreadsheet.css";import{jsx as h}from"react/jsx-runtime";function m(m){const{visible:p=!1,onCancel:w,file:v,name:g,inline:y=!1,title:C="Excel预览",style:E={},extraButtons:k}=m,I=o(null),j=o(null),T=o(!1),b=d(),[S,D]=l(!1),{downloadFile:M}=u();c(()=>{if(!p&&!y||!v)return;T.current=!1;const e=setTimeout(()=>{(async()=>{D(!0),I.current.innerHTML="";try{const e=await fetch(v.includes(b)||s.test(v)?v:b+v);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(I.current,{mode:"read",showToolbar:!1,showContextmenu:!1,view:{height:()=>I.current?.clientHeight||520,width:()=>I.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:f(e)}}),t.rows[r-1]=n}),(t.merges||[]).forEach(e=>{const r=function(e){const[t,r=t]=e.split(":"),n=x(t),i=x(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 文件失败"),w&&w()}finally{T.current||D(!1)}})()},100);return()=>{T.current=!0,I.current&&(I.current.innerHTML=""),e&&clearTimeout(e)}},[p,y,v]);const B=()=>h(n,{spinning:S,children:h("div",{style:{height:"72vh",overflow:"hidden",...E},children:h("div",{ref:I,style:{width:"100%",height:"100%"}})})});return y?B():h("div",{ref:j,children:h(e,{style:{top:100,maxWidth:"calc(100vw - 32px)",paddingBottom:24},open:p,mask:{closable:!1},width:1e3,title:C,onCancel:()=>{w()},getContainer:!1,footer:[h(t,{onClick:()=>{w()},children:"关闭"},"cancel"),h(t,{type:"primary",onClick:()=>{M({url:v,name:g})},children:"下载"},"download"),...k||[]],children:B()})})}function f(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 x(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}m.displayName="Excel";export{m as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Space as e,Button as
|
|
1
|
+
import{Space as e,Button as l}from"antd";import{useState as i}from"react";import r from"../../hooks/useDownloadFile/index.js";import{getFileName as n}from"../../utils/index.js";import o from"../Excel/index.js";import m from"../Pdf/index.js";import t from"../PreviewImg/index.js";import a from"../Video/index.js";import s from"../Word/index.js";import{jsxs as d,Fragment as p,jsx as c}from"react/jsx-runtime";const u=u=>{const{files:f=[],nameKey:x="",urlKey:v="",name:y,url:g,componentProps:h={}}=u,{downloadFile:j}=r(),[w,b]=i(null),C=f.length>0?f.map(e=>{const l=e.filePath||e.url||e[v];return{name:e.name||e.fileName||e[x]||n(l),url:l}}).filter(e=>e.url):y&&g?[{name:y,url:g}]:[],P=()=>{b(null)};return 0===C.length?null:d(p,{children:[c(e,{orientation:"vertical",children:C.map(i=>{const r=(e=>{const l=e.url.split(/[?#]/)[0],i=l.slice(l.lastIndexOf(".")+1).toLowerCase();return["jpg","jpeg","png","gif","webp","bmp","svg"].includes(i)?"image":"pdf"===i?"pdf":"docx"===i?"word":"xlsx"===i?"excel":["mp4","webm","m3u8"].includes(i)?"video":void 0})(i),n=`${i.name}-${i.url}`;return"image"===r?c(e,{children:c(t,{...h.image,files:[i.url]})},n):d(e,{children:[c("span",{children:i.name}),c(l,r?{type:"primary",size:"small",onClick:()=>((e,l)=>{b({...e,type:l})})(i,r),children:"预览"}:{type:"primary",size:"small",onClick:()=>j({url:i.url,name:i.name}),children:"下载"})]},n)})}),"pdf"===w?.type&&c(m,{...h.pdf,visible:!0,file:w.url,name:w.name,onCancel:P}),"word"===w?.type&&c(s,{...h.word,visible:!0,file:w.url,name:w.name,onCancel:P}),"excel"===w?.type&&c(o,{...h.excel,visible:!0,file:w.url,name:w.name,onCancel:P}),"video"===w?.type&&c(a,{...h.video,visible:!0,source:w.url,title:w.name,onCancel:P})]})};u.displayName="FilePreview";export{u as default};
|
package/components/Pdf/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useFullscreen as e}from"ahooks";import{Modal as t,Button as r,Spin as o,message as
|
|
1
|
+
import{useFullscreen as e}from"ahooks";import{Modal as t,Button as r,Spin as o,message as i}from"antd";import{useState as n,useRef as a}from"react";import{pdfjs as l,Document as c,Page as s}from"react-pdf";import d from"../../hooks/useDownloadFile/index.js";import{HTTP_URL as p}from"../../regular/index.js";import{getFileUrl as m}from"../../utils/index.js";import"react-pdf/dist/Page/AnnotationLayer.css";import"react-pdf/dist/Page/TextLayer.css";import"./index.less";import{jsx as f,Fragment as h}from"react/jsx-runtime";function u(u){const{visible:g=!1,onCancel:x,file:y,name:v,inline:w=!1,title:k="PDF预览",style:b={},extraButtons:L,usePrint:j=!1}=u,C=m(),P=y.includes(C)||p.test(y)?y:C+y,[F,D]=n(0),[R,S]=n(600),U=a(null),[E,{enterFullscreen:O,exitFullscreen:W}]=e(U),{downloadFile:A}=d();l.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${l.version}/build/pdf.worker.min.mjs`;const B=({numPages:e})=>{D(e)},N=()=>{i.error("加载 PDF 文件失败"),x&&x()},T=({width:e})=>{S(e)},$=()=>f(h,{children:f("div",{style:{height:E?"calc(100vh - 40px - 24px - 8px - 32px - 12px)":"72vh",overflowY:"auto",padding:"24px",...b},children:f(c,{file:P,onLoadSuccess:B,onLoadError:N,loading:f("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"65vh"},children:f(o,{size:"large"})}),children:Array.from({length:F}).map((e,t)=>f(s,{pageNumber:t+1,onLoadSuccess:T},`page_${t+1}`))})})});return w?$():f("div",{ref:U,children:f(t,{style:{top:E?0:100,maxWidth:E?"100vw":"calc(100vw - 32px)",paddingBottom:E?0:24},open:g,mask:{closable:!1},width:E?"100vw":R+100,styles:{body:{maxHeight:"auto !important",overflow:"auto"}},title:k,onCancel:()=>{E&&W(),x()},getContainer:!1,footer:[f(r,{onClick:()=>{E&&W(),x()},children:"关闭"},"cancel"),f(r,{onClick:()=>{E?W():O()},children:E?"退出全屏":"全屏"},"fullScreen"),f(r,{type:"primary",onClick:()=>{E&&W(),A({url:y,name:v})},children:"下载"},"download"),j&&f(r,{type:"primary",onClick:async()=>{try{const e=await fetch(P);if(!e.ok)return void i.warning("获取 PDF 文件失败");const t=URL.createObjectURL(await e.blob()),r=document.createElement("iframe");r.style.cssText="position:fixed;width:0;height:0;border:0",r.onload=()=>{const e=r.contentWindow,o=()=>{URL.revokeObjectURL(t),r.remove()};e.addEventListener("afterprint",o,{once:!0});try{e.focus(),e.print()}catch(e){o(),i.error(e.message||"打印失败,请稍后重试")}},r.src=t,document.body.appendChild(r)}catch(e){i.error(e.message||"打印失败,请稍后重试")}},children:"打印"},"print"),...L||[]],children:$()})})}u.displayName="Pdf";export{u as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Image as
|
|
1
|
+
import{Image as r}from"antd";import{HTTP_URL as t}from"../../regular/index.js";import{getFileUrl as e}from"../../utils/index.js";import{jsx as i}from"react/jsx-runtime";const o=o=>{const{files:m=[],fileUrlKey:s="filePath"}=o,l=e();return i(r.PreviewGroup,{children:m.filter(Boolean).map(e=>{const o=e[s]||e,m=o.includes(l)||t.test(o)?o:l+o;return i(r,{src:m,styles:{root:{marginRight:10,marginBottom:10}},width:100,height:100,alt:""},o)})})};o.displayName="PreviewImg";export{o as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Modal as e,Button as r}from"antd";import{forwardRef as t,useState as n,useRef as
|
|
1
|
+
import{Modal as e,Button as r}from"antd";import{forwardRef as t,useState as n,useRef as o,useImperativeHandle as a,useEffect as i}from"react";import{HTTP_URL as l}from"../../regular/index.js";import{getFileUrl as s}from"../../utils/index.js";import c from"./AliPlayer.js";import{jsx as u}from"react/jsx-runtime";const p=t(({source:t="",vid:p="",playAuth:d="",cover:m="",autoplay:y=!0,showProgress:h=!0,playTime:P=0,inline:f=!1,isLive:g=!1,width:v="100%",height:w="600px",title:x="视频",visible:j=!1,onCancel:I,onEnded:T,onTimeupdate:A,onGetPlayerInstance:C,aliPlayerProps:b={}},k)=>{const[E,G]=n(!1),L=o(null);a(k,()=>({play:()=>{L.current&&L.current.play()},pause:()=>{L.current&&L.current.pause()},getPlayerInstance:()=>L.current&&L.current.getPlayerInstance()}));const N=I?j:E,V=I||G;i(()=>{f||(N?L.current&&L.current.play():L.current&&L.current.pause())},[N,f]);const q=u(c,{ref:L,source:(()=>{if(t)return l.test(t)?t:s()+t})(),vid:p,playAuth:d,cover:m,autoplay:y,showProgress:h,playTime:P,isLive:g,width:v,height:w,aliPlayerProps:b,onEnded:T,onTimeupdate:A,onGetPlayerInstance:C});return f?q:u(e,{open:N,width:800,title:x,footer:[u(r,{onClick:()=>V(!1),children:"关闭"},"cancel")],mask:{closable:!1},onCancel:()=>V(!1),children:q})});p.displayName="Video";export{p as default};
|
package/components/Word/index.js
CHANGED
|
@@ -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{
|
|
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{HTTP_URL as d}from"../../regular/index.js";import{getFileUrl as u}from"../../utils/index.js";import{jsx as s}from"react/jsx-runtime";function m(m){const{visible:f=!1,onCancel:p,file:h,name:g,inline:w=!1,title:x="Word预览",style:v={},extraButtons:y}=m,k=o(null),W=o(null),C=o(!1),b=u(),[j,T]=a(!1),{downloadFile:B}=c();l(()=>{if(!f&&!w||!h)return;C.current=!1;const r=setTimeout(()=>{(async()=>{T(!0),k.current.innerHTML="";try{const r=await fetch(h.includes(b)||d.test(h)?h:b+h);if(!r.ok)return void n.error("加载 Word 文件失败");const e=await r.arrayBuffer();if(C.current)return;await i(e,k.current,null,{className:"docx-preview",inWrapper:!0,ignoreWidth:!1,ignoreHeight:!1,breakPages:!0})}catch{n.error("加载 Word 文件失败"),p&&p()}finally{C.current||T(!1)}})()},100);return()=>{C.current=!0,k.current&&(k.current.innerHTML=""),r&&clearTimeout(r)}},[f,w,h]);const H=()=>s(t,{spinning:j,children:s("div",{style:{height:"72vh",overflowY:"auto",padding:"24px",background:"#f5f5f5",...v},children:s("div",{ref:k})})});return w?H():s("div",{ref:W,children:s(r,{style:{top:100,maxWidth:"calc(100vw - 32px)",paddingBottom:24},open:f,mask:{closable:!1},width:900,title:x,onCancel:()=>{p()},getContainer:!1,footer:[s(e,{onClick:()=>{p()},children:"关闭"},"cancel"),s(e,{type:"primary",onClick:()=>{B({url:h,name:g})},children:"下载"},"download"),...y||[]],children:H()})})}m.displayName="Word";export{m as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Modal as
|
|
1
|
+
import{Modal as e,message as o}from"antd";import{useState as t}from"react";import{HTTP_URL as n}from"../../regular/index.js";import{getFileUrl as r,getFileSuffix as c,getFileName as l}from"../../utils/index.js";function d(d="object"){const[i,a]=t(!1);let m=0;const s=t=>{m++,m>0&&a(!0);const{url:d,name:i}=t;d?e.confirm({title:"提示",content:"确定要下载此文件吗?",onOk:()=>{const e=r();let t=i;t?!c(t)&&c(d)&&(t=`${t}.${c(d)}`):t=l(d),fetch(d.includes(e)||n.test(e)?d:e+d).then(e=>e.blob()).then(e=>{const o=document.createElement("a");document.body.appendChild(o),o.style.display="none";const n=window.URL.createObjectURL(e);o.href=n,o.download=`${t}`,o.click(),document.body.removeChild(o),window.URL.revokeObjectURL(n)}).catch(()=>{o.error("下载失败")}).finally(()=>{m--,m<=0&&a(!1)})},onCancel:()=>{m--,m<=0&&a(!1)}}):console.error("【downloadFile】 缺少 url 参数")};return"array"===d?[i,s]:{loading:i,downloadFile:s}}export{d as default};
|
package/package.json
CHANGED
package/regular/index.d.ts
CHANGED
package/regular/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const d=/^(?:(?:\+|00)86)?1(?:3\d|4[5-7|9]|5[0-3|5-9]|6[5-7]|7[0-8]|8\d|9[1|89])\d{8}$/,$=/^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/,A=/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[12]\d|30|31)\d{3}[\dX]$/i,H=/^(13\d|14[579]|15[0-3,5-9]|166|17[0135-8]|18\d|19[89])\d{8}$/,J=/(^[1-9](\d+)?(\.\d{1,2})?$)|(^(0)$)|(^\d\.\d(\d)?$)/,N=/^\d+\.\d{2}$/,P=/^\d+(\.\d?)?$/,Z=/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$/,
|
|
1
|
+
const d=/^(?:(?:\+|00)86)?1(?:3\d|4[5-7|9]|5[0-3|5-9]|6[5-7]|7[0-8]|8\d|9[1|89])\d{8}$/,$=/^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/,A=/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[12]\d|30|31)\d{3}[\dX]$/i,H=/^(13\d|14[579]|15[0-3,5-9]|166|17[0135-8]|18\d|19[89])\d{8}$/,J=/(^[1-9](\d+)?(\.\d{1,2})?$)|(^(0)$)|(^\d\.\d(\d)?$)/,N=/^\d+\.\d{2}$/,P=/^\d+(\.\d?)?$/,Z=/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$/,t=/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z\d]).{8,}$/,X=/<[^>]*>/g,a=/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/g,g=/^(?:(?:\d{3}-)?\d{8}|^(?:\d{4}-)?\d{7,8})(?:-\d+)?$/,i=/^https?:\/\//i;export{J as FLOATING_POINT_NUMBER,X as HTML_TAG,i as HTTP_URL,A as ID_NUMBER,Z as LICENSE_PLATE_NUMBER,H as MOBILE_PHONE,P as ONE_DECIMAL_PLACES,d as PHONE,a as POSTAL_CODE,t as STRONG_PASSWORD,g as TEL_PHONE,N as TWO_DECIMAL_PLACES,$ as UNIFIED_SOCIAL_CREDIT_CODE};
|