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