import{b as P,_ as I}from"./ImageUpload.vue_vue_type_style_index_0_scoped_cb086928_lang-D-28kXvw.js";import{u as w,cq as R,a4 as S,bZ as z,l as k,cs as O,bX as D,d as E,r as y,ar as H,ay as j,j as e,aH as M,aa as V,N as _,am as q,ag as B,ai as G,al as K,H as L,bQ as Q,bR as X,R as Z,v as A}from"./index-9PRMimni.js";import{c as U}from"./componentSetting-DVhNDBTO.js";import{D as J}from"./vuedraggable.umd-Co2xEC3p.js";function W(n){const c=w(),r=R(),m=S(()=>n?.helpText);function f(l){return U.upload.fileType.includes(l)}function b({file:l}){const s=l.file;if(!n)return;const{maxSize:o,accept:t}=n,i=z(t)&&t.split(",")||[],u=U.upload.fileType;return i.length>0&&!f(s.type)?(c.error(`只能上传文件类型为${u.join(",")}`),!1):!0}function a(l){return D(l)?l.element:l}function d(l){return O(l)}function g(l){const{fileUrl:s}=r;return k(l).map(o=>{const t=v(o);return{id:d(),name:"img",status:"finished",url:/(^http|https:\/\/)/g.test(t)?t:`${s}${t}`}})}function p(l){return k(l).map(s=>s.url)}function v(l){const{fileUrl:s}=r,o=a(l);return/(^http|https:\/\/)/g.test(o)?o:`${s}${o}`}const h=S(()=>({width:`${n?.width}px`,height:`${n?.height}px`}));return{getHelpText:m,getFlieUrl:v,getCSSProperties:h,getFlieId:d,packFiles:g,takeFiles:p,checkFileType:f,beforeUpload:b}}const Y=E({name:"ImageUpload",props:P,emits:["uploadChange","delete"],setup(n,{emit:c}){const r=y(),m=y(""),f=w(),b=H(),a=y([]),{getHelpText:d,getFlieUrl:g,getCSSProperties:p,beforeUpload:v}=W(n);j(()=>n.value,()=>{a.value=n.value},{immediate:!0});const h=S(()=>n.maxNumber);function l(t){r.value.openModal(),m.value=t}function s(t){console.log(t),b.info({title:"提示",content:"你确定要删除吗？",positiveText:"确定",negativeText:"取消",onPositiveClick:()=>{a.value.splice(t,1),c("uploadChange",a.value),c("delete",a.value)},onNegativeClick:()=>{}})}function o({event:t}){try{const i=(t?.target).response,u=X("("+i+")"),{infoField:F,imgField:C,imgNameField:T}=U.upload.apiSetting,{code:$}=u,N=u.msg||u.message||"上传失败",x=u[F];$===Z.SUCCESS?(a.value.push(x[C]),c("uploadChange",a.value,x[C],x[T])):f.error(N)}catch(i){console.error(i)}}return()=>e("div",{class:"w-full"},[e("div",{class:"upload"},[e("div",{class:"upload-card"},[e(J,{class:"flex flex-wrap w-full",itemKey:"element",modelValue:a.value,"onUpdate:modelValue":t=>a.value=t,animation:"300"},{item:(t,i)=>e("div",{class:"cursor-move upload-card-item",style:p.value,key:t.element},[e("div",{class:"upload-card-item-info",key:t.element},[e("div",{class:"img-box"},[e("img",{src:g(t)},null)]),e("div",{class:"img-box-actions"},[e(_,{size:"18",class:"mx-2 action-icon",onClick:l.bind(this,g(t))},{default:()=>[e(B,null,null)]}),e(_,{size:"18",class:"mx-2 action-icon",onClick:s.bind(this,i)},{default:()=>[e(G,null,null)]})])])]),footer:()=>a.value.length<h.value?e("div",{class:"upload-card-item upload-card-item-select-picture",style:p.value},[e(M,V({ref:"uploadRef"},n,{max:h.value,listType:"image-card",onBeforeUpload:v,onFinish:o,"trigger-style":p.value}),{default:()=>[e(_,{component:q,size:26,class:"upload-icon-btn"},null)]})]):null})])]),d.value?e("div",{class:"mt-3 upload-alert"},[e("div",{class:"inline-block"},[e(K,{type:"info","show-icon":!1,closable:!0},{default:()=>[e(L,{align:"center"},{default:()=>[e(_,{component:Q,size:22,class:"upload-icon-btn"},null),e("div",{class:"pr-6"},[d.value])]})]})])]):null,e(I,{ref:r,url:m.value},null)])}}),ae=A(Y,[["__scopeId","data-v-cb086928"]]);export{ae as _,W as u};
