1 |
- "use strict";const c=require("../../../../common/vendor.js");function i(t,o){let e=this;e.version="1.3.7",e.options=t||{},e.isScrollBody=o||!1,e.isDownScrolling=!1,e.isUpScrolling=!1;let n=e.options.down&&e.options.down.callback;e.initDownScroll(),e.initUpScroll(),setTimeout(function(){(e.optDown.use||e.optDown.native)&&e.optDown.auto&&n&&(e.optDown.autoShowLoading?e.triggerDownScroll():e.optDown.callback&&e.optDown.callback(e)),e.isUpAutoLoad||setTimeout(function(){e.optUp.use&&e.optUp.auto&&!e.isUpAutoLoad&&e.triggerUpScroll()},100)},30)}i.prototype.extendDownScroll=function(t){i.extend(t,{use:!0,auto:!0,native:!1,autoShowLoading:!1,isLock:!1,offset:80,startTop:100,inOffsetRate:1,outOffsetRate:.2,bottomOffset:20,minAngle:45,textInOffset:"下拉刷新",textOutOffset:"释放更新",textLoading:"加载中 ...",textSuccess:"加载成功",textErr:"加载失败",beforeEndDelay:0,bgColor:"transparent",textColor:"gray",inited:null,inOffset:null,outOffset:null,onMoving:null,beforeLoading:null,showLoading:null,afterLoading:null,beforeEndDownScroll:null,endDownScroll:null,afterEndDownScroll:null,callback:function(o){o.resetUpScroll()}})};i.prototype.extendUpScroll=function(t){i.extend(t,{use:!0,auto:!0,isLock:!1,isBoth:!0,callback:null,page:{num:0,size:10,time:null},noMoreSize:5,offset:150,textLoading:"加载中 ...",textNoMore:"-- END --",bgColor:"transparent",textColor:"gray",inited:null,showLoading:null,showNoMore:null,hideUpScroll:null,errDistance:60,toTop:{src:null,offset:1e3,duration:300,btnClick:null,onShow:null,zIndex:9990,left:null,right:20,bottom:120,safearea:!1,width:72,radius:"50%"},empty:{use:!0,icon:null,tip:"~ 暂无相关数据 ~",btnText:"",btnClick:null,onShow:null,fixed:!1,top:"100rpx",zIndex:99},onScroll:!1})};i.extend=function(t,o){if(!t)return o;for(let e in o)if(t[e]==null){let n=o[e];n!=null&&typeof n=="object"?t[e]=i.extend({},n):t[e]=n}else typeof t[e]=="object"&&i.extend(t[e],o[e]);return t};i.prototype.hasColor=function(t){if(!t)return!1;let o=t.toLowerCase();return o!="#fff"&&o!="#ffffff"&&o!="transparent"&&o!="white"};i.prototype.initDownScroll=function(){let t=this;t.optDown=t.options.down||{},!t.optDown.textColor&&t.hasColor(t.optDown.bgColor)&&(t.optDown.textColor="#fff"),t.extendDownScroll(t.optDown),t.isScrollBody&&t.optDown.native?t.optDown.use=!1:t.optDown.native=!1,t.downHight=0,t.optDown.use&&t.optDown.inited&&setTimeout(function(){t.optDown.inited(t)},0)};i.prototype.touchstartEvent=function(t){this.optDown.use&&(this.startPoint=this.getPoint(t),this.startTop=this.getScrollTop(),this.startAngle=0,this.lastPoint=this.startPoint,this.maxTouchmoveY=this.getBodyHeight()-this.optDown.bottomOffset,this.inTouchend=!1)};i.prototype.touchmoveEvent=function(t){if(!this.optDown.use)return;let o=this,e=o.getScrollTop(),n=o.getPoint(t);if(n.y-o.startPoint.y>0&&(o.isScrollBody&&e<=0||!o.isScrollBody&&(e<=0||e<=o.optDown.startTop&&e===o.startTop))&&!o.inTouchend&&!o.isDownScrolling&&!o.optDown.isLock&&(!o.isUpScrolling||o.isUpScrolling&&o.optUp.isBoth)){if(o.startAngle||(o.startAngle=o.getAngle(o.lastPoint,n)),o.startAngle<o.optDown.minAngle)return;if(o.maxTouchmoveY>0&&n.y>=o.maxTouchmoveY){o.inTouchend=!0,o.touchendEvent();return}o.preventDefault(t);let s=n.y-o.lastPoint.y;o.downHight<o.optDown.offset?(o.movetype!==1&&(o.movetype=1,o.isDownEndSuccess=null,o.optDown.inOffset&&o.optDown.inOffset(o),o.isMoveDown=!0),o.downHight+=s*o.optDown.inOffsetRate):(o.movetype!==2&&(o.movetype=2,o.optDown.outOffset&&o.optDown.outOffset(o),o.isMoveDown=!0),s>0?o.downHight+=s*o.optDown.outOffsetRate:o.downHight+=s),o.downHight=Math.round(o.downHight);let p=o.downHight/o.optDown.offset;o.optDown.onMoving&&o.optDown.onMoving(o,p,o.downHight)}o.lastPoint=n};i.prototype.touchendEvent=function(t){this.optDown.use&&(this.isMoveDown?(this.downHight>=this.optDown.offset?this.triggerDownScroll():(this.downHight=0,this.endDownScrollCall(this)),this.movetype=0,this.isMoveDown=!1):!this.isScrollBody&&this.getScrollTop()===this.startTop&&this.getPoint(t).y-this.startPoint.y<0&&this.getAngle(this.getPoint(t),this.startPoint)>80&&this.triggerUpScroll(!0))};i.prototype.getPoint=function(t){return t?t.touches&&t.touches[0]?{x:t.touches[0].pageX,y:t.touches[0].pageY}:t.changedTouches&&t.changedTouches[0]?{x:t.changedTouches[0].pageX,y:t.changedTouches[0].pageY}:{x:t.clientX,y:t.clientY}:{x:0,y:0}};i.prototype.getAngle=function(t,o){let e=Math.abs(t.x-o.x),n=Math.abs(t.y-o.y),l=Math.sqrt(e*e+n*n),s=0;return l!==0&&(s=Math.asin(n/l)/Math.PI*180),s};i.prototype.triggerDownScroll=function(){this.optDown.beforeLoading&&this.optDown.beforeLoading(this)||(this.showDownScroll(),!this.optDown.native&&this.optDown.callback&&this.optDown.callback(this))};i.prototype.showDownScroll=function(){this.isDownScrolling=!0,this.optDown.native?(c.index.startPullDownRefresh(),this.showDownLoadingCall(0)):(this.downHight=this.optDown.offset,this.showDownLoadingCall(this.downHight))};i.prototype.showDownLoadingCall=function(t){this.optDown.showLoading&&this.optDown.showLoading(this,t),this.optDown.afterLoading&&this.optDown.afterLoading(this,t)};i.prototype.onPullDownRefresh=function(){this.isDownScrolling=!0,this.showDownLoadingCall(0),this.optDown.callback&&this.optDown.callback(this)};i.prototype.endDownScroll=function(){if(this.optDown.native){this.isDownScrolling=!1,this.endDownScrollCall(this),c.index.stopPullDownRefresh();return}let t=this,o=function(){t.downHight=0,t.isDownScrolling=!1,t.endDownScrollCall(t),t.isScrollBody||(t.setScrollHeight(0),t.scrollTo(0,0))},e=0;t.optDown.beforeEndDownScroll&&(e=t.optDown.beforeEndDownScroll(t),t.isDownEndSuccess==null&&(e=0)),typeof e=="number"&&e>0?setTimeout(o,e):o()};i.prototype.endDownScrollCall=function(){this.optDown.endDownScroll&&this.optDown.endDownScroll(this),this.optDown.afterEndDownScroll&&this.optDown.afterEndDownScroll(this)};i.prototype.lockDownScroll=function(t){t==null&&(t=!0),this.optDown.isLock=t};i.prototype.lockUpScroll=function(t){t==null&&(t=!0),this.optUp.isLock=t};i.prototype.initUpScroll=function(){let t=this;t.optUp=t.options.up||{use:!1},!t.optUp.textColor&&t.hasColor(t.optUp.bgColor)&&(t.optUp.textColor="#fff"),t.extendUpScroll(t.optUp),t.optUp.use!==!1&&(t.optUp.hasNext=!0,t.startNum=t.optUp.page.num+1,t.optUp.inited&&setTimeout(function(){t.optUp.inited(t)},0))};i.prototype.onReachBottom=function(){this.isScrollBody&&!this.isUpScrolling&&!this.optUp.isLock&&this.optUp.hasNext&&this.triggerUpScroll()};i.prototype.onPageScroll=function(t){this.isScrollBody&&(this.setScrollTop(t.scrollTop),t.scrollTop>=this.optUp.toTop.offset?this.showTopBtn():this.hideTopBtn())};i.prototype.scroll=function(t,o){this.setScrollTop(t.scrollTop),this.setScrollHeight(t.scrollHeight),this.preScrollY==null&&(this.preScrollY=0),this.isScrollUp=t.scrollTop-this.preScrollY>0,this.preScrollY=t.scrollTop,this.isScrollUp&&this.triggerUpScroll(!0),t.scrollTop>=this.optUp.toTop.offset?this.showTopBtn():this.hideTopBtn(),this.optUp.onScroll&&o&&o()};i.prototype.triggerUpScroll=function(t){if(!this.isUpScrolling&&this.optUp.use&&this.optUp.callback){if(t===!0){let o=!1;if(this.optUp.hasNext&&!this.optUp.isLock&&!this.isDownScrolling&&this.getScrollBottom()<=this.optUp.offset&&(o=!0),o===!1)return}this.showUpScroll(),this.optUp.page.num++,this.isUpAutoLoad=!0,this.num=this.optUp.page.num,this.size=this.optUp.page.size,this.time=this.optUp.page.time,this.optUp.callback(this)}};i.prototype.showUpScroll=function(){this.isUpScrolling=!0,this.optUp.showLoading&&this.optUp.showLoading(this)};i.prototype.showNoMore=function(){this.optUp.hasNext=!1,this.optUp.showNoMore&&this.optUp.showNoMore(this)};i.prototype.hideUpScroll=function(){this.optUp.hideUpScroll&&this.optUp.hideUpScroll(this)};i.prototype.endUpScroll=function(t){t!=null&&(t?this.showNoMore():this.hideUpScroll()),this.isUpScrolling=!1};i.prototype.resetUpScroll=function(t){if(this.optUp&&this.optUp.use){let o=this.optUp.page;this.prePageNum=o.num,this.prePageTime=o.time,o.num=this.startNum,o.time=null,!this.isDownScrolling&&t!==!1&&(t==null?(this.removeEmpty(),this.showUpScroll()):this.showDownScroll()),this.isUpAutoLoad=!0,this.num=o.num,this.size=o.size,this.time=o.time,this.optUp.callback&&this.optUp.callback(this)}};i.prototype.setPageNum=function(t){this.optUp.page.num=t-1};i.prototype.setPageSize=function(t){this.optUp.page.size=t};i.prototype.endByPage=function(t,o,e){let n;this.optUp.use&&o!=null&&(n=this.optUp.page.num<o),this.endSuccess(t,n,e)};i.prototype.endBySize=function(t,o,e){let n;this.optUp.use&&o!=null&&(n=(this.optUp.page.num-1)*this.optUp.page.size+t<o),this.endSuccess(t,n,e)};i.prototype.endSuccess=function(t,o,e){let n=this;if(n.isDownScrolling&&(n.isDownEndSuccess=!0,n.endDownScroll()),n.optUp.use){let l;if(t!=null){let s=n.optUp.page.num,p=n.optUp.page.size;s===1&&e&&(n.optUp.page.time=e),t<p||o===!1?(n.optUp.hasNext=!1,t===0&&s===1?(l=!1,n.showEmpty()):((s-1)*p+t<n.optUp.noMoreSize?l=!1:l=!0,n.removeEmpty())):(l=!1,n.optUp.hasNext=!0,n.removeEmpty())}n.endUpScroll(l)}};i.prototype.endErr=function(t){if(this.isDownScrolling){this.isDownEndSuccess=!1;let o=this.optUp.page;o&&this.prePageNum&&(o.num=this.prePageNum,o.time=this.prePageTime),this.endDownScroll()}this.isUpScrolling&&(this.optUp.page.num--,this.endUpScroll(!1),this.isScrollBody&&t!==0&&(t||(t=this.optUp.errDistance),this.scrollTo(this.getScrollTop()-t,0)))};i.prototype.showEmpty=function(){this.optUp.empty.use&&this.optUp.empty.onShow&&this.optUp.empty.onShow(!0)};i.prototype.removeEmpty=function(){this.optUp.empty.use&&this.optUp.empty.onShow&&this.optUp.empty.onShow(!1)};i.prototype.showTopBtn=function(){this.topBtnShow||(this.topBtnShow=!0,this.optUp.toTop.onShow&&this.optUp.toTop.onShow(!0))};i.prototype.hideTopBtn=function(){this.topBtnShow&&(this.topBtnShow=!1,this.optUp.toTop.onShow&&this.optUp.toTop.onShow(!1))};i.prototype.getScrollTop=function(){return this.scrollTop||0};i.prototype.setScrollTop=function(t){this.scrollTop=t};i.prototype.scrollTo=function(t,o){this.myScrollTo&&this.myScrollTo(t,o)};i.prototype.resetScrollTo=function(t){this.myScrollTo=t};i.prototype.getScrollBottom=function(){return this.getScrollHeight()-this.getClientHeight()-this.getScrollTop()};i.prototype.getStep=function(t,o,e,n,l){let s=o-t;if(n===0||s===0){e&&e(o);return}n=n||300,l=l||30;let p=n/l,h=s/p,f=0,r=setInterval(function(){f<p-1?(t+=h,e&&e(t,r),f++):(e&&e(o,r),clearInterval(r))},l)};i.prototype.getClientHeight=function(t){let o=this.clientHeight||0;return o===0&&t!==!0&&(o=this.getBodyHeight()),o};i.prototype.setClientHeight=function(t){this.clientHeight=t};i.prototype.getScrollHeight=function(){return this.scrollHeight||0};i.prototype.setScrollHeight=function(t){this.scrollHeight=t};i.prototype.getBodyHeight=function(){return this.bodyHeight||0};i.prototype.setBodyHeight=function(t){this.bodyHeight=t};i.prototype.preventDefault=function(t){t&&t.cancelable&&!t.defaultPrevented&&t.preventDefault()};exports.MeScroll=i;
|