import{message as o}from"antd";import e from"dayjs";import{useState as n}from"react";function t(t="object"){const[r,a]=n(!1);let d=0;const c=(n,t)=>{if(d++,d>0&&a(!0),n)return new Promise((r,c)=>{const{name:l="",type:s="",params:i={}}=t,m=new URL((process.env.app.API_HOST||window.__JJB_ENVIRONMENT__.API_HOST)+n);Object.entries(i).forEach(([o,e])=>{m.searchParams.append(o,e)}),fetch(m,{method:"GET",mode:"cors",headers:{"Content-Type":"application/json",token:window.sessionStorage.token}}).then(o=>{if(o.ok)return o.blob();console.error("【downloadBlob】 网络响应异常")}).then(o=>{const n=new Blob([o],{type:s||"application/vnd.ms-excel"}),t=document.createElement("a"),a=window.URL.createObjectURL(n);t.style.display="none",t.href=a,t.download=l||e().format("YYYY-MM-DD HH:mm:ss"),document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(a),r({data:n})}).catch(e=>{o.error("导出失败"),c(e)}).finally(()=>{d--,d<=0&&a(!1)})});console.error("【downloadBlob】 缺少 url 参数")};return"array"===t?[r,c]:{loading:r,downloadBlob:c}}export{t as default};
