import{a_ as I,d as M,h as q,r as d,dP as H,k as J,o as r,c as u,a0 as w,e as c,p as y,m as k,A as P,y as f,$ as g,I as x,q as v,z as T,bu as K,J as Q,b3 as _,T as z,G as W}from"./index-XuO881sr.js";import{E as X}from"./el-link-0y2NgOVV.js";import{E as Y}from"./el-upload-CMRuHOSh.js";function me(t){return I({url:"/resource/oss/list",method:"get",params:t})}function Z(t){return I({url:"/resource/oss/listByIds/"+t,method:"get"})}function ee(t){return I({url:"/resource/oss/"+t,method:"delete"})}const le={class:"upload-file"},te={key:1,class:"el-upload__tip"},se={style:{color:"#f56c6c"}},oe={style:{color:"#f56c6c"}},ae={class:"el-icon-document"},ie={class:"ele-upload-list__item-content-action"},ne=M({__name:"index",props:{modelValue:{type:[String,Object,Array],default:()=>[]},limit:_.number.def(5),fileSize:_.number.def(5),fileType:_.array.def(["doc","docx","xls","xlsx","ppt","pptx","txt","pdf"]),isShowTip:_.bool.def(!0),disabled:_.bool.def(!1)},emits:["update:modelValue"],setup(t,{emit:U}){const a=t,{proxy:n}=q(),E=U,m=d(0),h=d([]),V=d("http://wuyeapi.bugtc.com"+"/resource/oss/upload"),L=d(H()),i=d([]),N=z(()=>a.isShowTip&&(a.fileType||a.fileSize)),$=d(),O=z(()=>a.fileType.map(e=>`.${e}`).join(","));J(()=>a.modelValue,async e=>{if(e){let l=1,o=[];Array.isArray(e)?o=e:o=(await Z(e)).data.map(p=>({name:p.originalName,url:p.url,ossId:p.ossId})),i.value=o.map(s=>(s={name:s.name,url:s.url,ossId:s.ossId},s.uid=s.uid||new Date().getTime()+l++,s))}else return i.value=[],[]},{deep:!0,immediate:!0});const C=e=>{if(a.fileType.length){const l=e.name.split("."),o=l[l.length-1];if(!(a.fileType.indexOf(o)>=0))return n?.$modal.msgError(`文件格式不正确, 请上传${a.fileType.join("/")}格式文件!`),!1}return e.name.includes(",")?(n?.$modal.msgError("文件名不正确，不能包含英文逗号!"),!1):a.fileSize&&!(e.size/1024/1024<a.fileSize)?(n?.$modal.msgError(`上传文件大小不能超过 ${a.fileSize} MB!`),!1):(n?.$modal.loading("正在上传文件，请稍候..."),m.value++,!0)},A=()=>{n?.$modal.msgError(`上传文件数量不能超过 ${a.limit} 个!`)},j=()=>{n?.$modal.msgError("上传文件失败")},D=(e,l)=>{e.code===200?(h.value.push({name:e.data.fileName,url:e.data.url,ossId:e.data.ossId}),S()):(m.value--,n?.$modal.closeLoading(),n?.$modal.msgError(e.msg),$.value?.handleRemove(l),S())},F=e=>{const l=i.value[e].ossId;ee(l),i.value.splice(e,1),E("update:modelValue",B(i.value))},S=()=>{m.value>0&&h.value.length===m.value&&(i.value=i.value.filter(e=>e.url!==void 0).concat(h.value),h.value=[],m.value=0,E("update:modelValue",B(i.value)),n?.$modal.closeLoading())},R=e=>e.lastIndexOf("/")>-1?e.slice(e.lastIndexOf("/")+1):e,B=(e,l)=>{let o="";return l=l||",",e.forEach(s=>{s.ossId&&(o+=s.ossId+l)}),o!=""?o.substring(0,o.length-1):""};return(e,l)=>{const o=P,s=Y,p=X;return r(),u("div",le,[t.disabled?g("",!0):(r(),w(s,{key:0,ref_key:"fileUploadRef",ref:$,multiple:"",action:c(V),"before-upload":C,"file-list":c(i),limit:t.limit,accept:c(O),"on-error":j,"on-exceed":A,"on-success":D,"show-file-list":!1,headers:c(L),class:"upload-file-uploader"},{default:y(()=>[k(o,{type:"primary"},{default:y(()=>[...l[0]||(l[0]=[f("选取文件",-1)])]),_:1})]),_:1},8,["action","file-list","limit","accept","headers"])),c(N)&&!t.disabled?(r(),u("div",te,[l[3]||(l[3]=f(" 请上传 ",-1)),t.fileSize?(r(),u(x,{key:0},[l[1]||(l[1]=f(" 大小不超过 ",-1)),v("b",se,T(t.fileSize)+"MB",1)],64)):g("",!0),t.fileType?(r(),u(x,{key:1},[l[2]||(l[2]=f(" 格式为 ",-1)),v("b",oe,T(t.fileType.join("/")),1)],64)):g("",!0),l[4]||(l[4]=f(" 的文件 ",-1))])):g("",!0),k(K,{class:"upload-file-list el-upload-list el-upload-list--text",name:"el-fade-in-linear",tag:"ul"},{default:y(()=>[(r(!0),u(x,null,Q(c(i),(b,G)=>(r(),u("li",{key:b.uid,class:"el-upload-list__item ele-upload-list__item-content"},[k(p,{href:`${b.url}`,underline:!1,target:"_blank"},{default:y(()=>[v("span",ae,T(R(b.name)),1)]),_:2},1032,["href"]),v("div",ie,[t.disabled?g("",!0):(r(),w(o,{key:0,type:"danger",link:"",onClick:de=>F(G)},{default:y(()=>[...l[5]||(l[5]=[f("删除",-1)])]),_:1},8,["onClick"]))])]))),128))]),_:1})])}}}),pe=W(ne,[["__scopeId","data-v-20a80ff4"]]);export{pe as _,me as a,ee as d,Z as l};
