import{u as l,w as f}from"./xlsx.ed122d16.js";import{aU as p,ac as m,aZ as c}from"./index.js";const{VITE_PROXY_DOMAIN_REAL:B,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=["\u5E8F\u53F7","\u64CD\u4F5C"];function A(e){const{data:t,columns:n,name:o}=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=g({data:t,columns:n}),r=n.map(({label:i})=>i).filter(i=>i&&!b.includes(i));u.unshift(r);const s=l.book_new(),a=l.aoa_to_sheet(u);l.book_append_sheet(s,a,"sheet1"),f(s,o)}async function R(e){if(!e.url)return;e.onStart&&e.onStart();const n=await(e.admin===!1?F:w)(e.url,{...e.params}).catch(()=>e.onFail&&e.onFail()),{code:o}=n;if(Number(o)!==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"),o&&Number(o)!==0){c.warning(n.message);return}function u(){const r=new Blob([n],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),s=window.URL.createObjectURL(r),a=document.createElement("a");a.style.display="none",a.href=s,a.setAttribute("download",e.name),document.body.appendChild(a),a.click(),window.URL.revokeObjectURL(s),c.success("\u4E0B\u8F7D\u5B8C\u6210"),e.onSuccess&&e.onSuccess()}u()}function g({data:e,columns:t}){return e.map(n=>{const o=[];for(let u=0;u<t.length;u++){const{prop:r,transform:s}=t[u];if(!r)continue;const a=s?s(n[r]):n[r];o.push(a)}return o})}function C({type:e,url:t,columns:n,data:o,name:u}){const r=u||"\u5BFC\u51FA\u6570\u636E.xlsx";switch(e){case"front":A({data:o,columns:n,name:r});break;case"http":R({url:t,name:r});break}}export{C as e,R as h};
