zy-react-library 1.4.21 → 1.4.22

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{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"../../hooks/useDownloadFile/index.js";import{HTTP_URL as s}from"../../regular/index.js";import{getFileUrl as u}from"../../utils/index.js";import"x-data-spreadsheet/dist/xspreadsheet.js";import"./xspreadsheet.css";import{jsx as d}from"react/jsx-runtime";function h(h){const{visible:x=!1,onCancel:p,file:w,name:v,inline:g=!1,title:y="Excel预览",style:C={},extraButtons:E}=h,j=o(null),k=o(null),I=o(!1),T=u(),[b,S]=l(!1),{downloadFile:D}=a();c(()=>{if(!x&&!g||!w)return;I.current=!1;const e=setTimeout(()=>{(async()=>{S(!0),j.current.innerHTML="";try{const e=await fetch(w.includes(T)||s.test(w)?w:T+w);if(!e.ok)return void r.error("加载 Excel 文件失败");const t=await e.arrayBuffer(),n=new i.Workbook;if(await n.xlsx.load(t),I.current)return;window.x_spreadsheet(j.current,{mode:"read",showToolbar:!1,showContextmenu:!1,view:{height:()=>j.current?.clientHeight||520,width:()=>j.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:m(e)}}),t.rows[r-1]=n}),(t.merges||[]).forEach(e=>{const r=function(e){const[t,r=t]=e.split(":"),n=f(t),i=f(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 文件失败"),p&&p()}finally{I.current||S(!1)}})()},100);return()=>{I.current=!0,j.current&&(j.current.innerHTML=""),e&&clearTimeout(e)}},[x,g,w]);const M=()=>d(n,{spinning:b,children:d("div",{style:{height:"72vh",overflow:"hidden",...C},children:d("div",{ref:j,style:{width:"100%",height:"100%"}})})});return g?M():d("div",{ref:k,children:d(e,{style:{top:100,maxWidth:"calc(100vw - 32px)",paddingBottom:24},open:x,maskClosable:!1,width:1e3,title:y,onCancel:()=>{p()},getContainer:!1,footer:[d(t,{onClick:()=>{p()},children:"关闭"},"cancel"),d(t,{type:"primary",onClick:()=>{D({url:w,name:v})},children:"下载"},"download"),...E||[]],children:M()})})}function m(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 f(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}h.displayName="Excel";export{h as default};
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"../../hooks/useDownloadFile/index.js";import{HTTP_URL as s}from"../../regular/index.js";import{getFileUrl as u}from"../../utils/index.js";import"x-data-spreadsheet/dist/xspreadsheet.js";import"./xspreadsheet.css";import{jsx as d}from"react/jsx-runtime";function h(h){const{visible:x=!1,onCancel:p,file:w,name:v,inline:g=!1,title:y="Excel预览",style:C={},extraButtons:E}=h,j=o(null),k=o(null),I=o(!1),T=u(),[b,S]=l(!1),{downloadFile:D}=a();c(()=>{if(!x&&!g||!w)return;I.current=!1;const e=setTimeout(()=>{(async()=>{S(!0),j.current.innerHTML="";try{const e=await fetch(w.includes(T)||s.test(w)?w:T+w);if(!e.ok)return void r.error("加载 Excel 文件失败");const t=await e.arrayBuffer(),n=new i.Workbook;if(await n.xlsx.load(t),I.current)return;window.x_spreadsheet(j.current,{mode:"read",showToolbar:!1,showContextmenu:!1,view:{height:()=>j.current?.clientHeight||520,width:()=>j.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:m(e)}}),t.rows[r-1]=n}),(t.merges||[]).forEach(e=>{const r=function(e){const[t,r=t]=e.split(":"),n=f(t),i=f(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 文件失败"),p&&p()}finally{I.current||S(!1)}})()},100);return()=>{I.current=!0,j.current&&(j.current.innerHTML=""),e&&clearTimeout(e)}},[x,g,w]);const M=()=>d(n,{spinning:b,children:d("div",{style:{height:"72vh",overflow:"hidden",...C},children:d("div",{ref:j,style:{width:"100%",height:"100%"}})})});return g?M():d("div",{ref:k,children:d(e,{style:{top:100,maxWidth:"calc(100vw - 32px)",paddingBottom:24},open:x,maskClosable:!1,width:1e3,title:y,onCancel:()=>{p()},getContainer:!1,footer:[d(t,{onClick:()=>{p()},children:"关闭"},"cancel"),d(t,{type:"primary",onClick:()=>{D({url:w,name:v})},children:"下载"},"download"),...E||[]],children:M()})})}function m(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 f(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}h.displayName="Excel";export{h 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.21",
4
+ "version": "1.4.22",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",