const defaultoptions={url:void 0,method:"GET",qs:void 0,body:void 0,headers:void 0,type:"json",contentType:"application/json",crossOrigin:!0,credentials:void 0},makeOptions=(e,t)=>{let s={};return t?(s=t,e&&(s.url=e)):"string"==typeof e?s.url=e:s=e,s=Object.assign({},defaultoptions,s),s},addQs=(e,t)=>{let s="",o=e;if(t&&"object"==typeof t){for(const e of Object.keys(t))s+=`&${e}=${t[e]}`;s.length>0&&(e.split("?").length<2||0===e.split("?")[1].length)&&(s=s.substring(1)),o=-1===e.indexOf("?")?`${e}?${s}`:`${e}${s}`}return o},request=(e,t)=>{const s=makeOptions(e,t),{method:o,body:n,headers:d,qs:r,type:i,contentType:a}=s;let l=s.url;r&&(l=addQs(l,r));let p=d;return d&&d["content-type"]||!a||(p=Object.assign({},d,{"content-type":a})),new Promise(((e,t)=>{wx.request({url:l,method:o,data:n,header:p,dataType:i,success(s){(s.statusCode<200||s.statusCode>=300)&&t(s),e(s)},fail(e){t(e)}})}))};export default request;