import{bt as e,bH as a,ag as t,bx as s,aD as o,bI as r,bJ as c,bK as n,ah as l,bq as i,ay as m}from"./index-Cg3FU-dV.js";const p=(i="common/upload",m={},p=2)=>{const u=1024*p*1024;return new Promise(((h,f)=>{e({count:1,extension:a,success:e=>{const a=e.tempFilePaths[0];e.tempFiles[0].size>u?f("图片或文件大小不能超过"+p+"MB"):d(a,i)},fail:()=>{f("图片或文件选择失败")}});const d=(e,a)=>{t({title:"上传中"}),s({url:o+""+r+a,header:{[c]:"Bearer "+n.state.app.token},filePath:e,name:"file",formData:m,success:e=>{l();const a=JSON.parse(e.data);h(a)},fail:()=>{l(),f("上传失败，请稍后再试！")},complete:()=>{l()}})}}))},u=(e="common/upload",a={},p=2,u=["camera","album"])=>{const f=1024*p*1024;return new Promise(((d,g)=>{i({count:1,sourceType:u,success:a=>{const t=a.tempFilePaths[0],s=a.tempFiles[0];m({src:t,success:async a=>{try{const o=await h(t,a);s.size>f?g("图片或文件大小不能超过"+p+"MB"):w(o,e)}catch(o){g("图片选择失败")}}})},fail:()=>{g("图片选择失败")}});const w=(e,i)=>{t({title:"上传中",mask:!0}),s({url:o+""+r+i,header:{[c]:"Bearer "+n.state.app.token},filePath:e,name:"file",formData:a,success:e=>{l();const a=JSON.parse(e.data);d(a)},fail:()=>{l(),g("上传失败，请稍后再试！")},complete:()=>{l()}})}}))},h=(e,a)=>{let t=a.width,s=a.height,o=t/s;t>800&&(t=800,s=Math.floor(t/o));let r=new Image;return new Promise(((a,o)=>{r.onload=()=>{let e=document.createElement("canvas"),o=e.getContext("2d");e.width=t,e.height=s,o.clearRect(0,0,t,s),o.drawImage(r,0,0,t,s);const c=e.toDataURL("image/jpeg",.5);a(c)},r.onerror=()=>{o("图片选择失败")},r.src=e}))},f=(e,a=2)=>{if(0===e)return"0 Bytes";const t=a<0?0:a,s=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,s)).toFixed(t))+" "+["Bytes","KB","MB","GB"][s]};export{p as a,f,u};
