import{Modal as o,message as e}from"antd";import{useState as n}from"react";import{getFileUrl as t,getFileSuffix as c,getFileName as r}from"../../utils/index.js";function l(l="object"){const[d,a]=n(!1);let i=0;const m=n=>{i++,i>0&&a(!0);const{url:l,name:d}=n;l?o.confirm({title:"提示",content:"确定要下载此文件吗？",onOk:()=>{const o=t();let n=d;n?!c(n)&&c(l)&&(n=`${n}.${c(l)}`):n=r(l),fetch(l.includes(o)?l:o+l).then(o=>o.blob()).then(o=>{const e=document.createElement("a");document.body.appendChild(e),e.style.display="none";const t=window.URL.createObjectURL(o);e.href=t,e.download=`${n}`,e.click(),document.body.removeChild(e),window.URL.revokeObjectURL(t)}).catch(()=>{e.error("下载失败")}).finally(()=>{i--,i<=0&&a(!1)})},onCancel:()=>{i--,i<=0&&a(!1)}}):console.error("【downloadFile】 缺少 url 参数")};return"array"===l?[d,m]:{loading:d,downloadFile:m}}export{l as default};
