2 lines
2.5 KiB
JavaScript
2 lines
2.5 KiB
JavaScript
"use strict";const t=require("../../../common/vendor.js"),e={name:"fui-waterfall-item",emits:["click"],inject:["waterfall"],options:{virtualHost:!0},props:{background:{type:String,default:"#FFFFFF"},radius:{type:[Number,String],default:16},src:{type:String,default:""},imgWidth:{type:[Number,String],default:0},imgHeight:{type:[Number,String],default:0},webp:{type:Boolean,default:!1},draggable:{type:Boolean,default:!0},param:{type:[Number,String],default:0}},created(){this.src&&(this.isSrc=!0),this.waterfall&&(this.waterfall.childrenArr.push(this),this.waterfall.itemWidth?this.width=this.waterfall.itemWidth:this.waterfall.initParam((t=>{this.width=t})))},computed:{getStyles(){let t=`width:${0!=this.imgWidth?`${this.imgWidth}rpx`:`${this.width}px`};border-radius:${this.radius}rpx ${this.radius}rpx 0 0;`;return 0!=this.imgHeight&&(t+=`height:${this.imgHeight}rpx;`),t},getStyl(){let t=this.getStyles;return 0!=this.imgHeight||this.isLoaded||(t+=`height:${this.width}px;`),t}},mounted(){this.src&&0==this.imgHeight||this.$nextTick((()=>{setTimeout((()=>{this.getWaterfallItemInfo()}),50)}))},data:()=>({elId:`fui_${Math.ceil(1e6*Math.random()).toString(36)}`,width:0,height:0,transform:"",isShow:!1,isLoaded:!0,isSrc:!1}),methods:{getWaterfallItemInfo(){this.getItemHeight((t=>{this.waterfall&&(this.waterfall.loadedArr.push("ok"),this.waterfall.childrenArr.length===this.waterfall.loadedArr.length&&this.waterfall.startSorting())}))},getItemHeight(e,i=0){t.index.createSelectorQuery().in(this).select(`#${this.elId}`).fields({size:!0},(t=>{if(!(i>=20))return t&&t.height?(this.height=t.height,void(e&&e(t.height))):(i++,void setTimeout((()=>{this.getItemHeight(e,i)}),50))})).exec()},handleLoad(t){0==this.imgHeight&&setTimeout((()=>{this.getWaterfallItemInfo()}),50)},handleError(t){this.isLoaded=!1,0==this.imgHeight&&setTimeout((()=>{this.getWaterfallItemInfo()}),50)},handleTap(){this.$emit("click",{param:this.param})}}};const i=t._export_sfc(e,[["render",function(e,i,r,h,a,s){return t.e({a:a.isSrc},a.isSrc?t.e({b:a.isLoaded},a.isLoaded?{c:r.src,d:0!=r.imgHeight?"scaleToFill":"widthFix",e:r.webp,f:r.draggable,g:t.o(((...t)=>s.handleLoad&&s.handleLoad(...t))),h:t.o(((...t)=>s.handleError&&s.handleError(...t))),i:t.s(s.getStyles)}:{},{j:a.isLoaded?"":1,k:0!=r.imgHeight?1:"",l:t.s(s.getStyl)}):{},{m:a.elId,n:a.isShow?1:"",o:a.width+"px",p:r.background,q:r.radius+"rpx",r:a.transform,s:t.o(((...t)=>s.handleTap&&s.handleTap(...t)))})}],["__scopeId","data-v-8634fc3b"]]);wx.createComponent(i);
|