import{b as O}from"./ImageUpload.vue_vue_type_style_index_0_scoped_cb086928_lang-D-28kXvw.js";import{d as G,cq as q,a4 as x,u as A,ar as Z,r as f,ay as J,h as g,o as r,F as U,i as s,j as o,c as B,D as C,a9 as K,aG as F,aH as Q,aa as W,w as l,N as X,l as k,am as Y,al as ee,p as te,A as se,cr as oe,bZ as ae,bR as ne,R as le,H as ie,ag as ce,ai as re}from"./index-9PRMimni.js";import{c as w}from"./componentSetting-DVhNDBTO.js";const ue={class:"w-full"},pe={class:"upload"},de={class:"upload-card"},me={class:"upload-card-item-info"},_e={class:"img-box"},fe=["src"],ge={class:"img-box-actions"},ve={class:"flex flex-col justify-center"},he=["src"],ke=G({__name:"BasicUpload",props:{...O},emits:["uploadChange","delete"],setup(z,{emit:E}){const P=q(),a=z,D=x(()=>a.maxNumber),v=x(()=>a.helpText),h=E,S=x(()=>({width:`${a.width}px`,height:`${a.height}px`})),b=A(),I=Z(),y=f(!1),$=f(""),u=f([]),p=f([]);J(()=>a.value,()=>{p.value=a.value.map(e=>N(e))},{immediate:!0});function R(e){y.value=!0,$.value=e}function V(e){I.info({title:"提示",content:"你确定要删除吗？",positiveText:"确定",negativeText:"取消",onPositiveClick:()=>{p.value.splice(e,1),u.value.splice(e,1),h("uploadChange",u.value),h("delete",u.value)},onNegativeClick:()=>{}})}function N(e){const{fileUrl:t}=P;return/(^http|https:\/\/)/g.test(e)?e:`${t}${e}`}function j(e){return w.upload.fileType.includes(e)}function H({file:e}){const t=e.file,{maxSize:i,accept:n}=a,d=ae(n)&&n.split(",")||[],m=w.upload.fileType;return d.length>0&&!j(t.type)?(b.error(`只能上传文件类型为${m.join(",")}`),!1):!0}function L({event:e}){try{const t=ne("("+e.target.response+")"),{infoField:i,imgField:n}=w.upload.apiSetting,{code:d}=t,m=t.msg||t.message||"上传失败",_=t[i];if(d===le.SUCCESS){let c=N(_[n]);p.value.push(c),u.value.push(_[n]),h("uploadChange",u.value)}else b.error(m)}catch(t){console.error(t)}}return(e,t)=>{const i=X,n=Q,d=ee,m=ie,_=oe;return r(),g(U,null,[s("div",ue,[s("div",pe,[s("div",de,[(r(!0),g(U,null,K(p.value,(c,T)=>(r(),g("div",{class:"upload-card-item",style:F(S.value),key:`img_${T}`},[s("div",me,[s("div",_e,[s("img",{src:c},null,8,fe)]),s("div",ge,[o(i,{size:"18",class:"mx-2 action-icon",onClick:M=>R(c)},{default:l(()=>[o(k(ce))]),_:2},1032,["onClick"]),o(i,{size:"18",class:"mx-2 action-icon",onClick:M=>V(T)},{default:l(()=>[o(k(re))]),_:2},1032,["onClick"])])])],4))),128)),p.value.length<D.value?(r(),g("div",{key:0,class:"upload-card-item upload-card-item-select-picture",style:F(S.value)},[o(n,W(e.$props,{"file-list-style":{display:"none"},onBeforeUpload:H,onFinish:L}),{default:l(()=>[s("div",ve,[o(i,{size:"18",class:"m-auto"},{default:l(()=>[o(k(Y))]),_:1}),t[1]||(t[1]=s("span",{class:"upload-title"},"上传图片",-1))])]),_:1},16)],4)):C("",!0)])]),v.value?(r(),B(m,{key:0},{default:l(()=>[v.value?(r(),B(d,{key:0,title:"提示",type:"info",class:"flex w-full"},{default:l(()=>[te(se(v.value),1)]),_:1})):C("",!0)]),_:1})):C("",!0)]),o(_,{show:y.value,"onUpdate:show":t[0]||(t[0]=c=>y.value=c),preset:"card",title:"预览",bordered:!1,style:{width:"520px"}},{default:l(()=>[s("img",{src:$.value,class:"m-auto"},null,8,he)]),_:1},8,["show"])],64)}}});export{ke as _};
