|
|
+import{w as o,d as a,S as r,aC as e,c as l,C as s,an as i,V as n,a7 as t,a9 as d,o as c,X as u,a as v,y as g,x as f,R as h,ax as m,b7 as p,L as w,N as y,E as b}from"./index-13c35f79.js";const[x,z]=o("image"),L=b(a({name:x,props:{src:String,alt:String,fit:String,position:String,round:Boolean,block:Boolean,width:g,height:g,radius:g,lazyLoad:Boolean,iconSize:g,showError:f,errorIcon:h("photo-fail"),iconPrefix:String,showLoading:f,loadingIcon:h("photo")},emits:["load","error"],setup(o,{emit:a,slots:g}){const f=r(!1),h=r(!0),b=r(),{$Lazyload:x}=e().proxy,L=l((()=>{const a={width:s(o.width),height:s(o.height)};return i(o.radius)&&(a.overflow="hidden",a.borderRadius=s(o.radius)),a}));n((()=>o.src),(()=>{f.value=!1,h.value=!0}));const S=o=>{h.value&&(h.value=!1,a("load",o))},E=()=>{const o=new Event("load");Object.defineProperty(o,"target",{value:b.value,enumerable:!0}),S(o)},I=o=>{f.value=!0,h.value=!1,a("error",o)},P=(a,r,e)=>e?e():v(y,{name:a,size:o.iconSize,"class":r,classPrefix:o.iconPrefix},null),$=()=>{if(f.value||!o.src)return;const a={alt:o.alt,"class":z("img"),style:{objectFit:o.fit,objectPosition:o.position}};return o.lazyLoad?m(v("img",w({ref:b},a),null),[[p("lazy"),o.src]]):v("img",w({ref:b,src:o.src,onLoad:S,onError:I},a),null)},j=({el:o})=>{const a=()=>{o===b.value&&h.value&&E()};b.value?a():u(a)},k=({el:o})=>{o!==b.value||f.value||I()};return x&&t&&(x.$on("loaded",j),x.$on("error",k),d((()=>{x.$off("loaded",j),x.$off("error",k)}))),c((()=>{u((()=>{var a;(null==(a=b.value)?void 0:a.complete)&&!o.lazyLoad&&E()}))})),()=>{var a;return v("div",{"class":z({round:o.round,block:o.block}),style:L.value},[$(),h.value&&o.showLoading?v("div",{"class":z("loading")},[P(o.loadingIcon,z("loading-icon"),g.loading)]):f.value&&o.showError?v("div",{"class":z("error")},[P(o.errorIcon,z("error-icon"),g.error)]):void 0,null==(a=g["default"])?void 0:a.call(g)])}}}));export{L as I};
|