import{d as R,ai as i,r as n,b8 as C,b9 as D,M as L,o as N,c as P,g as v,aN as Q,w as y,a as O,Q as E,aC as S,ba as G,h as f,q as m,t as T,k as H,D as J,__tla as K}from"./index-7d5b26d3.js";import{u as W,__tla as X}from"./useMessage-c81eaa5b.js";let U,Y=Promise.all([(()=>{try{return K}catch{}})(),(()=>{try{return X}catch{}})()]).then(async()=>{let h,_,g,x,b;h={class:"upload-file"},_={style:{"font-size":"8px"}},g={style:{color:"#f56c6c"}},x={style:{"font-size":"8px"}},b={style:{color:"#f56c6c"}},U=R({name:"UploadFile",__name:"UploadFile",props:{modelValue:i.oneOfType([String,Array]).isRequired,title:i.string.def("\u6587\u4EF6\u4E0A\u4F20"),updateUrl:i.string.def("https://sh.letcgo.com/admin-api/infra/file/upload"),fileType:i.array.def(["doc","xls","ppt","txt","pdf"]),fileSize:i.number.def(5),limit:i.number.def(5),autoUpload:i.bool.def(!0),drag:i.bool.def(!1),isShowTip:i.bool.def(!0)},emits:["update:modelValue"],setup(s,{emit:w}){const o=W(),I=w,t=s,V=n(),d=n([]),l=n([]),c=n(0),$=n({Authorization:"Bearer "+C(),"tenant-id":D()}),j=e=>{if(l.value.length>=t.limit)return o.error(`\u4E0A\u4F20\u6587\u4EF6\u6570\u91CF\u4E0D\u80FD\u8D85\u8FC7${t.limit}\u4E2A!`),!1;let a="";e.name.lastIndexOf(".")>-1&&(a=e.name.slice(e.name.lastIndexOf(".")+1));const r=t.fileType.some(p=>e.type.indexOf(p)>-1||!!(a&&a.indexOf(p)>-1)),u=e.size<1024*t.fileSize*1024;return r?u?(o.success("\u6B63\u5728\u4E0A\u4F20\u6587\u4EF6\uFF0C\u8BF7\u7A0D\u5019..."),void c.value++):(o.error(`\u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F\u4E0D\u80FD\u8D85\u8FC7${t.fileSize}MB!`),!1):(o.error(`\u6587\u4EF6\u683C\u5F0F\u4E0D\u6B63\u786E, \u8BF7\u4E0A\u4F20${t.fileType.join("/")}\u683C\u5F0F!`),!1)},k=e=>{o.success("\u4E0A\u4F20\u6210\u529F");const a=l.value.findIndex(r=>{var u;return((u=r.response)==null?void 0:u.data)===e.data});l.value.splice(a,1),d.value.push({name:e.data,url:e.data}),d.value.length==c.value&&(l.value.push(...d.value),d.value=[],c.value=0,z())},B=()=>{o.error(`\u4E0A\u4F20\u6587\u4EF6\u6570\u91CF\u4E0D\u80FD\u8D85\u8FC7${t.limit}\u4E2A!`)},M=()=>{o.error("\u5BFC\u5165\u6570\u636E\u5931\u8D25\uFF0C\u8BF7\u60A8\u91CD\u65B0\u4E0A\u4F20\uFF01")},q=e=>{const a=l.value.map(r=>r.name).indexOf(e.name);a>-1&&(l.value.splice(a,1),z())},A=e=>{console.log(e)};L(()=>t.modelValue,e=>{e?(l.value=[],S(e)?l.value.push(...e.split(",").map(a=>({name:a.substring(a.lastIndexOf("/")+1),url:a}))):l.value.push(...e.map(a=>({name:a.substring(a.lastIndexOf("/")+1),url:a})))):l.value=[]},{immediate:!0,deep:!0});const z=()=>{let e=l.value.map(a=>a.url);S(t.modelValue)&&(e=e.join(",")),I("update:modelValue",e)};return(e,a)=>{const r=H,u=J,p=G;return N(),P("div",h,[v(p,{ref_key:"uploadRef",ref:V,"file-list":O(l),"onUpdate:fileList":a[0]||(a[0]=F=>E(l)?l.value=F:null),action:s.updateUrl,"auto-upload":s.autoUpload,"before-upload":j,drag:s.drag,headers:O($),limit:t.limit,multiple:t.limit>1,"on-error":M,"on-exceed":B,"on-preview":A,"on-remove":q,"on-success":k,"show-file-list":!0,class:"upload-file-uploader",name:"file"},Q({default:y(()=>[v(u,{type:"primary"},{default:y(()=>[v(r,{icon:"ep:upload-filled"}),m(" \u9009\u53D6\u6587\u4EF6 ")]),_:1})]),_:2},[s.isShowTip?{name:"tip",fn:y(()=>[f("div",_,[m(" \u5927\u5C0F\u4E0D\u8D85\u8FC7 "),f("b",g,T(s.fileSize)+"MB",1)]),f("div",x,[m(" \u683C\u5F0F\u4E3A "),f("b",b,T(s.fileType.join("/")),1),m(" \u7684\u6587\u4EF6 ")])]),key:"0"}:void 0]),1032,["file-list","action","auto-upload","drag","headers","limit","multiple"])])}}})});export{U as _,Y as __tla};
