import{cR as U,d as k,r,aC as E,j as e,cS as O,ac as M,u as $,cq as D,a4 as w,bZ as H,V as P,l as C,cs as q,bX as V,ar as B,ay as L,aH as A,aa as G,N as x,am as Q,aE as X,ag as Z,aF as J,ai as K,al as W,H as Y,bQ as ee,bR as te,R as ae}from"./index-9PRMimni.js";import{c as T}from"./componentSetting-DVhNDBTO.js";const le={...U,accept:{type:String,default:".jpg,.png,.jpeg,.svg,.gif"},helpText:{type:String,default:""},maxSize:{type:Number,default:2},maxNumber:{type:Number,default:1/0},value:{type:String,default:""},width:{type:Number,default:104},height:{type:Number,default:104}},ne=k({name:"ImagePreview",props:{url:{type:String,required:!0}},setup(n,{expose:u}){const i=r(),v=r(""),o=r(!1);let l=r(null);async function g(s){v.value=s||"",o.value=!0,await M(),i.value?.click&&(i.value.click(),a())}function a(){l.value&&(l.value.disconnect(),l.value=null),l.value=new MutationObserver(s=>{s.forEach(m=>{m.removedNodes?.length&&m.removedNodes.forEach(d=>{d?.classList?.contains?.("n-image-preview-container")&&(o.value=!1,l.value.disconnect(),l.value=null)})})}),l.value.observe(document.body,{childList:!0,subtree:!1})}return E(()=>{l.value&&(l.value.disconnect(),l.value=null)}),u({openModal:g}),()=>e("div",{class:"hidden"},[o.value?e(O,{ref:i,src:v.value||n.url,class:"m-auto"},null):""])}}),{t:se}=P();function ue(n){const u=$(),i=D(),v=w(()=>n?.helpText);function o(t){return T.upload.fileType.includes(t)}function l({file:t}){const c=t.file;if(!n)return;const{maxSize:p,accept:f}=n,h=H(f)&&f.split(",")||[],b=T.upload.fileType;return h.length>0&&!o(c.type)?(u.error(`${se("common.uploadTips")} ${b.join(",")}`),!1):!0}function g(t){return V(t)?t.element:t}function a(t){return q(t)}function s(t){const{fileUrl:c}=i;return C(t).map(p=>{const f=d(p);return{id:a(),name:"img",status:"finished",url:/(^http|https:\/\/)/g.test(f)?f:`${c}${f}`}})}function m(t){return C(t).map(c=>c.url)}function d(t){const{fileUrl:c}=i,p=g(t);return/(^http|https:\/\/)/g.test(p)?p:`${c}${p}`}const N=w(()=>({width:`${n?.width}px`,height:`${n?.height}px`}));return{getHelpText:v,getFlieUrl:d,getCSSProperties:N,getFlieId:a,packFiles:s,takeFiles:m,checkFileType:o,beforeUpload:l}}const{t:S}=P(),ce=k({name:"SingleImageUpload",props:le,emits:["uploadChange","update:value","delete"],setup(n,{emit:u}){const i=r(),v=r(),o=r(""),l=$(),g=B(),a=r(""),s=r(""),{getHelpText:m,getCSSProperties:d,beforeUpload:N}=ue(n);L(()=>n.value,()=>{a.value=n.value},{immediate:!0});const t=w(()=>1);function c(h){v.value.openModal(),o.value=h}function p(){g.info({title:S("common.tipsText"),content:S("common.dialogContentDeleteText"),positiveText:S("common.okText"),negativeText:S("common.cancelText"),onPositiveClick:()=>{a.value="",s.value="",u("uploadChange",a.value,s.value),u("update:value",a.value),u("delete",a.value)},onNegativeClick:()=>{}})}function f({event:h}){try{const b=(h?.target).response,y=te("("+b+")"),{infoField:F,imgField:I,imgNameField:R}=T.upload.apiSetting,{code:j}=y,z=y.msg||y.message||"上传失败",_=y[F];j===ae.SUCCESS?(a.value=_[I],s.value=_[R],u("uploadChange",a.value,s.value),u("update:value",a.value)):(i.value?.clear?.(),l.error(z))}catch(b){console.error(b)}}return()=>e("div",{class:"w-full"},[e("div",{class:"upload"},[e("div",{class:"upload-card"},[e("div",{class:"flex flex-wrap w-full"},[a.value===""?e("div",{className:"upload-card-item upload-card-item-select-picture",style:d.value},[e(A,G({ref:i},n,{max:t.value,listType:"image-card",onBeforeUpload:N,onFinish:f,"trigger-style":d.value}),{default:()=>[e(x,{component:Q,size:26,class:"upload-icon-btn"},null)]})]):e("div",{class:"cursor-move upload-card-item",style:d.value},[e("div",{class:"upload-card-item-info"},[e("div",{class:"img-box"},[e("img",{src:a.value},null)]),e("div",{class:"img-box-actions"},[e(x,{size:"18",className:"mx-2 action-icon",onClick:c.bind(this,a.value)},{default:()=>[e(Z,null,null)]}),X(e(x,{size:"18",className:"mx-2 action-icon",onClick:p.bind(this)},{default:()=>[e(K,null,null)]}),[[J,!n.disabled]])])])])])])]),m.value?e("div",{class:"mt-3 upload-alert"},[e("div",{class:"inline-block"},[e(W,{type:"info","show-icon":!1,closable:!0},{default:()=>[e(Y,{align:"center"},{default:()=>[e(x,{component:ee,size:22,class:"upload-icon-btn"},null),e("div",{class:"pr-6"},[m.value])]})]})])]):null,e(ne,{ref:v,url:o.value},null)])}}),re={...U,accept:{type:String,default:".jpg,.png,.jpeg,.svg,.gif"},helpText:{type:String,default:""},maxSize:{type:Number,default:2},maxNumber:{type:Number,default:1/0},value:{type:Array,default:()=>[]},singleValue:{type:String,default:""},width:{type:Number,default:104},height:{type:Number,default:104}};export{ne as _,ce as a,re as b};
