import{u as i,w as f}from"./xlsx.ed122d16.js";import{ch as p,a5 as m,cm as c}from"./index.js";const{VITE_PROXY_DOMAIN_REAL:x,VITE_PROXY_USER_REAL:E}=m(),d=E+"/admin/",h=E,w=(e,t)=>p.request("post",`${d}${e}`,{data:t,responseType:"blob"}),F=(e,t)=>p.request("post",`${h}${e}`,{data:t,responseType:"blob"}),b=(e,t)=>p.request("post",`${e}`,{data:t,responseType:"blob"}),B=["\u5E8F\u53F7","\u64CD\u4F5C"];function y(e){const{data:t,columns:n,name:r}=e;if(!t||!n)return;if(t.length===0)return c.warning("\u8BF7\u6253\u5F00\u52FE\u9009\u5217\u5E76\u52FE\u9009\u5BFC\u51FA\u6570\u636E");const u=R({data:t,columns:n}),o=n.map(({label:l})=>l).filter(l=>l&&!B.includes(l));u.unshift(o);const a=i.book_new(),s=i.aoa_to_sheet(u);i.book_append_sheet(a,s,"sheet1"),f(a,r)}async function A(e){if(!e.url)return;e.onStart&&e.onStart();let t=e.admin===!1?F:w;e.noBaseUrl&&(t=b);const n=await t(e.url,{...e.params}).catch(()=>e.onFail&&e.onFail()),{code:r}=n;if(Number(r)!==0&&e.onFail&&e.onFail(),n.type==="application/json"){c.warning("\u672A\u627E\u5230\u6570\u636E");return}if(c.warning("\u4E0B\u8F7D\u4E2D,\u8BF7\u7A0D\u7B49"),r&&Number(r)!==0){c.warning(n.message);return}function u(){const o=new Blob([n],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),a=window.URL.createObjectURL(o),s=document.createElement("a");s.style.display="none",s.href=a,s.setAttribute("download",e.name),document.body.appendChild(s),s.click(),window.URL.revokeObjectURL(a),c.success("\u4E0B\u8F7D\u5B8C\u6210"),e.onSuccess&&e.onSuccess()}u()}function R({data:e,columns:t}){return e.map(n=>{const r=[];for(let u=0;u<t.length;u++){const{prop:o,transform:a}=t[u];if(!o)continue;const s=a?a(n[o]):n[o];r.push(s)}return r})}function C({type:e,url:t,columns:n,data:r,name:u}){const o=u||"\u5BFC\u51FA\u6570\u636E.xlsx";switch(e){case"front":y({data:r,columns:n,name:o});break;case"http":A({url:t,name:o});break}}export{C as e,A as h};
