import{q as e,o,c as r,w as t,R as i,A as a,a2 as s,E as d,i as n}from"./index-DL8B2Mxu.js";import{_ as l}from"./u-icon.CLOPtL2B.js";import{r as u}from"./uni-app.es.BSVEa1f2.js";import{_ as h}from"./_plugin-vue_export-helper.BCo6x5W8.js";const g=h({name:"u-image",emits:["click","error","load"],props:{src:{type:String,default:""},mode:{type:String,default:"aspectFill"},width:{type:[String,Number],default:"100%"},height:{type:[String,Number],default:"auto"},shape:{type:String,default:"square"},borderRadius:{type:[String,Number],default:0},lazyLoad:{type:Boolean,default:!0},showMenuByLongpress:{type:Boolean,default:!0},loadingIcon:{type:String,default:"photo"},errorIcon:{type:String,default:"error-circle"},showLoading:{type:Boolean,default:!0},showError:{type:Boolean,default:!0},fade:{type:Boolean,default:!0},webp:{type:Boolean,default:!1},duration:{type:[String,Number],default:500},bgColor:{type:String,default:"#f3f4f6"}},data(){return{isError:!1,loading:!0,opacity:1,durationTime:this.duration,backgroundStyle:{}}},watch:{src:{immediate:!0,handler(e){e?(this.isError=!1,this.loading=!0):(this.isError=!0,this.loading=!1)}}},computed:{wrapStyle(){let e={};return e.width=this.$u.addUnit(this.width),e.height=this.$u.addUnit(this.height),e.borderRadius="circle"==this.shape?"50%":this.$u.addUnit(this.borderRadius),e.overflow=this.borderRadius>0?"hidden":"visible",this.fade&&(e.opacity=this.opacity,e.transition=`opacity ${Number(this.durationTime)/1e3}s ease-in-out`),e}},methods:{onClick(){this.$emit("click")},onErrorHandler(e){this.loading=!1,this.isError=!0,this.$emit("error",e)},onLoadHandler(){if(this.loading=!1,this.isError=!1,this.$emit("load"),!this.fade)return this.removeBgColor();this.opacity=0,this.durationTime=0,setTimeout((()=>{this.durationTime=this.duration,this.opacity=1,setTimeout((()=>{this.removeBgColor()}),this.durationTime)}),50)},removeBgColor(){this.backgroundStyle={backgroundColor:"transparent"}}}},[["render",function(h,g,c,p,y,m){const f=d,b=u(e("u-icon"),l),w=n;return o(),r(w,{class:"u-image",onClick:m.onClick,style:i([m.wrapStyle,y.backgroundStyle])},{default:t((()=>[y.isError?a("",!0):(o(),r(f,{key:0,src:c.src,mode:c.mode,onError:m.onErrorHandler,onLoad:m.onLoadHandler,"lazy-load":c.lazyLoad,class:"u-image__image","show-menu-by-longpress":c.showMenuByLongpress,style:i({borderRadius:"circle"==c.shape?"50%":h.$u.addUnit(c.borderRadius)})},null,8,["src","mode","onError","onLoad","lazy-load","show-menu-by-longpress","style"])),c.showLoading&&y.loading?(o(),r(w,{key:1,class:"u-image__loading",style:i({borderRadius:"circle"==c.shape?"50%":h.$u.addUnit(c.borderRadius),backgroundColor:c.bgColor})},{default:t((()=>[h.$slots.loading?s(h.$slots,"loading",{key:0},void 0,!0):(o(),r(b,{key:1,name:c.loadingIcon,width:c.width,height:c.height},null,8,["name","width","height"]))])),_:3},8,["style"])):a("",!0),c.showError&&y.isError&&!y.loading?(o(),r(w,{key:2,class:"u-image__error",style:i({borderRadius:"circle"==c.shape?"50%":h.$u.addUnit(c.borderRadius)})},{default:t((()=>[h.$slots.error?s(h.$slots,"error",{key:0},void 0,!0):(o(),r(b,{key:1,name:c.errorIcon,width:c.width,height:c.height},null,8,["name","width","height"]))])),_:3},8,["style"])):a("",!0)])),_:3},8,["onClick","style"])}],["__scopeId","data-v-f12a4d2a"]]);export{g as _};
