mescroll-body.js 5.7 KB

1
  1. "use strict";const n=require("../../../../common/vendor.js"),r=require("../mescroll-uni/mescroll-uni.js"),d=require("../mescroll-uni/mescroll-uni-option.js"),a=require("../mescroll-uni/mescroll-i18n.js"),x=require("../mescroll-uni/wxs/mixins.js"),h=e=>{e.wxsCallMethods||(e.wxsCallMethods=[]),e.wxsCallMethods.push("wxsCall")},T=()=>"../mescroll-uni/components/mescroll-top.js",f={name:"mescroll-body",mixins:[x.WxsMixin],components:{MescrollTop:T},props:{down:Object,up:Object,i18n:Object,top:[String,Number],topbar:[Boolean,String],bottom:[String,Number],safearea:Boolean,height:[String,Number],bottombar:{type:Boolean,default:!0},sticky:Boolean},data(){return{mescroll:{optDown:{},optUp:{}},downHight:0,downRate:0,downLoadType:0,upLoadType:0,isShowEmpty:!1,isShowToTop:!1,windowHeight:0,windowBottom:0,statusBarHeight:0}},computed:{minHeight(){return this.toPx(this.height||"100%")+"px"},numTop(){return this.toPx(this.top)},padTop(){return this.numTop+"px"},numBottom(){return this.toPx(this.bottom)},padBottom(){return this.numBottom+"px"},isDownReset(){return this.downLoadType===3||this.downLoadType===4},transition(){return this.isDownReset?"transform 300ms":""},translateY(){return this.downHight>0?"translateY("+this.downHight+"px)":""},isDownLoading(){return this.downLoadType===3},downRotate(){return"rotate("+360*this.downRate+"deg)"},downText(){if(!this.mescroll)return"";switch(this.downLoadType){case 1:return this.mescroll.optDown.textInOffset;case 2:return this.mescroll.optDown.textOutOffset;case 3:return this.mescroll.optDown.textLoading;case 4:return this.mescroll.isDownEndSuccess?this.mescroll.optDown.textSuccess:this.mescroll.isDownEndSuccess==!1?this.mescroll.optDown.textErr:this.mescroll.optDown.textInOffset;default:return this.mescroll.optDown.textInOffset}}},methods:{toPx(e){if(typeof e=="string"){if(e.indexOf("px")!==-1)if(e.indexOf("rpx")!==-1)e=e.replace("rpx","");else if(e.indexOf("upx")!==-1)e=e.replace("upx","");else return Number(e.replace("px",""));else if(e.indexOf("%")!==-1){let c=Number(e.replace("%",""))/100;return this.windowHeight*c}}return e?n.index.upx2px(Number(e)):0},emptyClick(){this.$emit("emptyclick",this.mescroll)},toTopClick(){this.mescroll.scrollTo(0,this.mescroll.optUp.toTop.duration),this.$emit("topclick",this.mescroll)}},created(){let e=this,c={down:{inOffset(){e.downLoadType=1},outOffset(){e.downLoadType=2},onMoving(o,s,i){e.downHight=i,e.downRate=s},showLoading(o,s){e.downLoadType=3,e.downHight=s},beforeEndDownScroll(o){return e.downLoadType=4,o.optDown.beforeEndDelay},endDownScroll(){e.downLoadType=4,e.downHight=0,e.downResetTimer&&(clearTimeout(e.downResetTimer),e.downResetTimer=null),e.downResetTimer=setTimeout(()=>{e.downLoadType===4&&(e.downLoadType=0)},300)},callback:function(o){e.$emit("down",o)}},up:{showLoading(){e.upLoadType=1},showNoMore(){e.upLoadType=2},hideUpScroll(o){e.upLoadType=o.optUp.hasNext?0:3},empty:{onShow(o){e.isShowEmpty=o}},toTop:{onShow(o){e.isShowToTop=o}},callback:function(o){e.$emit("up",o)}}},p=a.mescrollI18n.getType(),m={type:p};r.MeScroll.extend(m,e.i18n),r.MeScroll.extend(m,d.GlobalOption.i18n),r.MeScroll.extend(c,m[p]),r.MeScroll.extend(c,{down:d.GlobalOption.down,up:d.GlobalOption.up});let t=JSON.parse(JSON.stringify({down:e.down,up:e.up}));r.MeScroll.extend(t,c),e.mescroll=new r.MeScroll(t,!0),e.mescroll.i18n=m,e.$emit("init",e.mescroll);const l=n.index.getSystemInfoSync();l.windowHeight&&(e.windowHeight=l.windowHeight),l.windowBottom&&(e.windowBottom=l.windowBottom),l.statusBarHeight&&(e.statusBarHeight=l.statusBarHeight),e.mescroll.setBodyHeight(l.windowHeight),e.mescroll.resetScrollTo((o,s)=>{typeof o=="string"?setTimeout(()=>{let i;o.indexOf("#")==-1&&o.indexOf(".")==-1?i="#"+o:i=o,n.index.createSelectorQuery().select(i).boundingClientRect(function(w){if(w){let u=w.top;u+=e.mescroll.getScrollTop(),n.index.pageScrollTo({scrollTop:u,duration:s})}else console.error(i+" does not exist")}).exec()},30):n.index.pageScrollTo({scrollTop:o,duration:s})}),e.up&&e.up.toTop&&e.up.toTop.safearea!=null||(e.mescroll.optUp.toTop.safearea=e.safearea),n.index.$on("setMescrollGlobalOption",o=>{if(!o)return;let s=o.i18n?o.i18n.type:null;if(s&&e.mescroll.i18n.type!=s&&(e.mescroll.i18n.type=s,a.mescrollI18n.setType(s),r.MeScroll.extend(o,e.mescroll.i18n[s])),o.down){let i=r.MeScroll.extend({},o.down);e.mescroll.optDown=r.MeScroll.extend(i,e.mescroll.optDown)}if(o.up){let i=r.MeScroll.extend({},o.up);e.mescroll.optUp=r.MeScroll.extend(i,e.mescroll.optUp)}})},destroyed(){n.index.$off("setMescrollGlobalOption")}};if(!Array){const e=n.resolveComponent("mescroll-empty"),c=n.resolveComponent("mescroll-top");(e+c)()}const y=()=>"../mescroll-empty/mescroll-empty.js";Math||y();function g(e,c,p,m,t,l){return n.e({a:p.topbar&&t.statusBarHeight},p.topbar&&t.statusBarHeight?{b:t.statusBarHeight+"px",c:p.topbar}:{},{d:t.mescroll.optDown.use},t.mescroll.optDown.use?{e:l.isDownLoading?1:"",f:t.mescroll.optDown.textColor,g:l.downRotate,h:n.t(l.downText),i:t.mescroll.optDown.bgColor,j:t.mescroll.optDown.textColor}:{},{k:t.isShowEmpty},t.isShowEmpty?{l:n.o(l.emptyClick),m:n.p({option:t.mescroll.optUp.empty})}:{},{n:t.mescroll.optUp.use&&!l.isDownLoading&&t.upLoadType!==3},t.mescroll.optUp.use&&!l.isDownLoading&&t.upLoadType!==3?n.e({o:t.mescroll.optUp.textColor,p:n.t(t.mescroll.optUp.textLoading),q:t.upLoadType===1,r:t.upLoadType===2},t.upLoadType===2?{s:n.t(t.mescroll.optUp.textNoMore)}:{},{t:t.mescroll.optUp.bgColor,v:t.mescroll.optUp.textColor}):{},{w:l.translateY,x:l.transition,y:e.callProp,z:p.safearea},p.safearea?{}:{},{A:n.o(l.toTopClick),B:n.o(o=>t.isShowToTop=o),C:n.p({option:t.mescroll.optUp.toTop,modelValue:t.isShowToTop}),D:e.renderBiz.propObserver,E:e.wxsProp,F:p.sticky?1:"",G:l.minHeight,H:l.padTop,I:l.padBottom,J:e.wxsProp})}typeof h=="function"&&h(f);const S=n._export_sfc(f,[["render",g]]);wx.createComponent(S);