import{cg as y,ch as P,O as h,r as q,ci as A,E as M,b as j,a7 as N}from"./index-CKIhG1T4.js";import"./spark-md5-Nsus8Zqw.js";import{a as v,f,v as O,M as C,D as b,T as g,af as Q,U as u,F as V,_ as w,Q as Y,$ as T,u as Z,Y as G,Z as H}from"./spreadSheetsDesignerVue-MRUT1X_l.js";const J={class:"el-upload__tip"},K={__name:"index",props:{apiUrl:{type:String,required:!0},chunkSize:{type:Number,default:5},accept:{type:String,default:""},headers:{type:Object,default:()=>({})},fileList:{type:Array,default:()=>[]},autoUpload:{type:Boolean,default:!0},listType:{type:String,default:"text"},showTips:{type:Boolean,default:!0},buttonText:{type:String,default:"\u4E0A\u4F20\u6587\u4EF6"},buttonType:{type:String,default:"default"},showButtonIcon:{type:Boolean,default:!0},limit:{type:Number,default:0},disabled:{type:Boolean,default:!1}},emits:["update:fileList","success","error"],setup(s,{emit:_}){const x=v("https://cloud-admin-uat.gzsei.com/admin-api/"),l=s,L=_,U=f(()=>{var e;return(e=l.fileList||[])==null?void 0:e.map(t=>({...t,url:t.url?y(t.url):y(t.name||`${t.path||""}${t.name||""}`)}))}),n=f(()=>l.accept||"*"),$=f(()=>l.accept||"\u4EFB\u610F\u7C7B\u578B"),B=e=>{var a;const t=((a=(e.name||"").match(/\.([^.]+)$/))==null?void 0:a[0])||null;return!(n.value!=="*"&&!n.value.includes(t)&&(h.error("\u53EA\u80FD\u4E0A\u4F20"+l.realAccept),1))},d=v(!1),z=async e=>{const{file:t,onProgress:a,onSuccess:o,onError:r}=e;try{const i=new FormData;i.append("file",t);const c=await q.post({url:x.value+l.apiUrl,data:i,headers:{authorization:"Bearer "+A(),"Content-Type":"multipart/form-data",accept:"*/*",...l.headers},onUploadProgress:F=>{const I=Math.round(F.loaded/t.size*100);a({percent:I})}});c&&(p({...t,name:t.name,status:"success",url:c}),console.log("handlePostFile",e,t,{...t,status:"success",url:c}))}catch(i){r(i)}},E=e=>{d.value=!1},k=e=>{d.value=!1},D=async e=>{if(e.id)try{await axios.delete(`${l.apiUrl}/${e.id}`),p(e,!0)}catch{h.error("\u5220\u9664\u5931\u8D25")}else p(e,!0)},p=(e,t=!1)=>{const a=[...l.fileList],o=a.findIndex(r=>r.uid===e.uid||r.url===e.url);t&&o>-1?a.splice(o,1):t||o!==-1||a.push(e),L("update:fileList",a)},m=e=>{if(d.value)return e.preventDefault(),e.returnValue="\u6587\u4EF6\u6B63\u5728\u4E0A\u4F20\u4E2D\uFF0C\u786E\u5B9A\u8981\u79BB\u5F00\u5417\uFF1F","\u6587\u4EF6\u6B63\u5728\u4E0A\u4F20\u4E2D\uFF0C\u786E\u5B9A\u8981\u79BB\u5F00\u5417\uFF1F"};return O(()=>{window.addEventListener("beforeunload",m)}),C(()=>{window.removeEventListener("beforeunload",m)}),(e,t)=>{const a=M,o=j,r=N;return b(),g(r,{action:"#",headers:s.headers,"file-list":U.value,accept:n.value,"before-upload":B,"on-success":E,"on-error":k,"on-remove":D,"http-request":z,"list-type":s.listType,"auto-upload":s.autoUpload,limit:s.limit,disabled:s.disabled},Q({default:u(()=>[Y(e.$slots,"trigger",{},()=>[T(o,{type:s.buttonType,bg:!1},{default:u(()=>[s.showButtonIcon?(b(),g(a,{key:0},{default:u(()=>[T(Z(P))]),_:1})):G("",!0),H(" "+w(s.buttonText),1)]),_:1},8,["type"])])]),_:2},[s.showTips?{name:"tip",fn:u(()=>[V("div",J," \u652F\u6301\u6269\u5C55\u540D\uFF1A"+w($.value),1)]),key:"0"}:void 0]),1032,["headers","file-list","accept","list-type","auto-upload","limit","disabled"])}}};export{K as _};