import{c as p,t as c}from"./index.ad3efb29.js";import{l as i}from"./elementPlus.4833989a.js";import"./vue.adf17aba.js";import"./echarts.72dc8373.js";function l(t,r,s){let e;s.response?e=`${s.response.error||s.response}`:s.responseText?e=`${s.responseText}`:e=`fail to post ${t} ${s.status}`;const n=new Error(e);return n.status=s.status,n.method="post",n.url=t,n}function d(t){const r=t.responseText||t.response;if(!r)return r;try{return JSON.parse(r)}catch{return r}}function f(t,r,s){if(typeof XMLHttpRequest>"u")return;const e=new XMLHttpRequest,n=t.action;e.timeout=t.timeout,e.upload&&(e.upload.onprogress=function(o){o.total>0&&(o.percent=o.loaded/o.total*100),t.onProgress(o)});const u=new FormData;t.data&&Object.keys(t.data).forEach(o=>{u.append(o,t.data[o])}),u.append(t.name,t.file,t.file.name),e.onerror=function(o){s(o)},e.onload=function(){if(e.status<200||e.status>=300)return t.onError(l(n,t,e));r(d(e))},e.open("post",n,!0),t.withCredentials&&"withCredentials"in e&&(e.withCredentials=!0);const a=t.headers||{};for(const o in a)a.hasOwnProperty(o)&&a[o]!==null&&e.setRequestHeader(o,a[o]);return e.send(u),e}function m(t){return new Promise((r,s)=>{f(t,async e=>{r(e)},e=>{s(e)})})}async function w(t){const{file:r,fileName:s,onProgress:e}=t,n=t.options,u=await p(r,s,n);n.data==null&&(n.data={}),n.data.key=u;const a={file:r,onProgress:e,timeout:6e4,...n};delete a.uploadRequest;let o=await(n.uploadRequest??m)(a);return n.successHandle&&(o=await n.successHandle(o,a)),o&&typeof o=="object"&&o.key==null&&(o.key=u),o}async function q(t){const{getConfig:r}=c(),s=r("form");return t.options=i.merge({},i.cloneDeep(s),t.options),await w(t)}export{q as upload};
