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