1 |
- import{t as o,d as a,Q as r,az as e,c as l,z as s,ak as i,S as n,a4 as t,a6 as d,o as c,V as u,a as v,w as g,v as f,N as h,au as m,bc as p,J as w,L as z,C as b}from"./index-81a4e71e.js";const[y,L]=o("image"),S=b(a({name:y,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:y}=e().proxy,S=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 x=o=>{h.value&&(h.value=!1,a("load",o))},I=()=>{const o=new Event("load");Object.defineProperty(o,"target",{value:b.value,enumerable:!0}),x(o)},P=o=>{f.value=!0,h.value=!1,a("error",o)},$=(a,r,e)=>e?e():v(z,{name:a,size:o.iconSize,"class":r,classPrefix:o.iconPrefix},null),j=()=>{if(f.value||!o.src)return;const a={alt:o.alt,"class":L("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:x,onError:P},a),null)},k=({el:o})=>{const a=()=>{o===b.value&&h.value&&I()};b.value?a():u(a)},E=({el:o})=>{o!==b.value||f.value||P()};return y&&t&&(y.$on("loaded",k),y.$on("error",E),d((()=>{y.$off("loaded",k),y.$off("error",E)}))),c((()=>{u((()=>{var a;(null==(a=b.value)?void 0:a.complete)&&!o.lazyLoad&&I()}))})),()=>{var a;return v("div",{"class":L({round:o.round,block:o.block}),style:S.value},[j(),h.value&&o.showLoading?v("div",{"class":L("loading")},[$(o.loadingIcon,L("loading-icon"),g.loading)]):f.value&&o.showError?v("div",{"class":L("error")},[$(o.errorIcon,L("error-icon"),g.error)]):void 0,null==(a=g["default"])?void 0:a.call(g)])}}}));export{S as I};
|