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