refresher.js 20.5 KB
Newer Older
mengcuiguang's avatar
mengcuiguang committed
1 2 3 4 5
// [z-paging]下拉刷新view模块
import u from '.././z-paging-utils'
import c from '.././z-paging-constant'
import Enum from '.././z-paging-enum'

jyx's avatar
jyx committed
6
const ZPRefresher = {
mengcuiguang's avatar
mengcuiguang committed
7 8 9 10
	props: {
		//下拉刷新的主题样式,支持black,white,默认black
		refresherThemeStyle: {
			type: String,
jyx's avatar
jyx committed
11 12 13
			default: function() {
				return u.gc('refresherThemeStyle', '');
			}
mengcuiguang's avatar
mengcuiguang committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
		},
		//自定义下拉刷新中左侧图标的样式
		refresherImgStyle: {
			type: Object,
			default: function() {
				return u.gc('refresherImgStyle', {});
			}
		},
		//自定义下拉刷新中右侧状态描述文字的样式
		refresherTitleStyle: {
			type: Object,
			default: function() {
				return u.gc('refresherTitleStyle', {});
			}
		},
		//自定义下拉刷新中右侧最后更新时间文字的样式(show-refresher-update-time为true时有效)
		refresherUpdateTimeStyle: {
			type: Object,
			default: function() {
				return u.gc('refresherUpdateTimeStyle', {});
			}
		},
		//在微信小程序和QQ小程序中,是否实时监听下拉刷新中进度,默认为否
		watchRefresherTouchmove: {
			type: Boolean,
			default: u.gc('watchRefresherTouchmove', false)
		},
		//底部加载更多的主题样式,支持black,white,默认black
		loadingMoreThemeStyle: {
			type: String,
jyx's avatar
jyx committed
44 45 46
			default: function() {
				return u.gc('loadingMoreThemeStyle', '');
			}
mengcuiguang's avatar
mengcuiguang committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
		},
		//是否只使用下拉刷新,设置为true后将关闭mounted自动请求数据、关闭滚动到底部加载更多,强制隐藏空数据图。默认为否
		refresherOnly: {
			type: Boolean,
			default: u.gc('refresherOnly', false)
		},
		//自定义下拉刷新结束以后延迟回弹的时间,单位为毫秒,默认为0
		refresherCompleteDelay: {
			type: [Number, String],
			default: u.gc('refresherCompleteDelay', 0)
		},
		//自定义下拉刷新结束回弹动画时间,单位为毫秒,默认为300毫秒(refresherEndBounceEnabled为false时,refresherCompleteDuration为设定值的1/3),nvue无效
		refresherCompleteDuration: {
			type: [Number, String],
			default: u.gc('refresherCompleteDuration', 300)
		},
		//自定义下拉刷新结束状态下是否允许列表滚动,默认为否
		refresherCompleteScrollable: {
			type: Boolean,
			default: u.gc('refresherCompleteScrollable', false)
		},
		//是否使用自定义的下拉刷新,默认为是,即使用z-paging的下拉刷新。设置为false即代表使用uni scroll-view自带的下拉刷新,h5、App、微信小程序以外的平台不支持uni scroll-view自带的下拉刷新
		useCustomRefresher: {
			type: Boolean,
			default: u.gc('useCustomRefresher', true)
		},
		//自定义下拉刷新下拉帧率,默认为40,过高可能会出现抖动问题
		refresherFps: {
			type: [Number, String],
			default: u.gc('refresherFps', 40)
		},
		//自定义下拉刷新允许触发的最大下拉角度,默认为40度,当下拉角度小于设定值时,自定义下拉刷新动画不会被触发
		refresherMaxAngle: {
			type: [Number, String],
			default: u.gc('refresherMaxAngle', 40)
		},
		//自定义下拉刷新的角度由未达到最大角度变到达到最大角度时,是否继续下拉刷新手势,默认为否
		refresherAngleEnableChangeContinued: {
			type: Boolean,
			default: u.gc('refresherAngleEnableChangeContinued', false)
		},
		//自定义下拉刷新默认状态下的文字
		refresherDefaultText: {
			type: [String, Object],
			default: u.gc('refresherDefaultText', null)
		},
		//自定义下拉刷新松手立即刷新状态下的文字
		refresherPullingText: {
			type: [String, Object],
			default: u.gc('refresherPullingText', null)
		},
		//自定义下拉刷新刷新中状态下的文字
		refresherRefreshingText: {
			type: [String, Object],
			default: u.gc('refresherRefreshingText', null)
		},
		//自定义下拉刷新刷新结束状态下的文字
		refresherCompleteText: {
			type: [String, Object],
			default: u.gc('refresherCompleteText', null)
		},
		//是否开启自定义下拉刷新刷新结束回弹效果,默认为是
		refresherEndBounceEnabled: {
			type: Boolean,
			default: u.gc('refresherEndBounceEnabled', true)
		},
		//是否开启自定义下拉刷新,默认为是
		refresherEnabled: {
			type: Boolean,
			default: u.gc('refresherEnabled', true)
		},
		//设置自定义下拉刷新阈值,默认为80rpx
		refresherThreshold: {
			type: [Number, String],
			default: u.gc('refresherThreshold', '80rpx')
		},
		//设置系统下拉刷新默认样式,支持设置 black,white,none,none 表示不使用默认样式,默认为black
		refresherDefaultStyle: {
			type: String,
			default: u.gc('refresherDefaultStyle', 'black')
		},
		//设置自定义下拉刷新区域背景
		refresherBackground: {
			type: String,
			default: u.gc('refresherBackground', 'transparent')
		},
		//设置固定的自定义下拉刷新区域背景
		refresherFixedBackground: {
			type: String,
			default: u.gc('refresherFixedBackground', 'transparent')
		},
		//设置固定的自定义下拉刷新区域高度,默认为0
		refresherFixedBacHeight: {
			type: [Number, String],
			default: u.gc('refresherFixedBacHeight', 0)
		},
jyx's avatar
jyx committed
143
		//设置自定义下拉刷新下拉超出阈值后继续下拉位移衰减的比例,范围0-1,值越大代表衰减越多。默认为0.7(nvue无效)
mengcuiguang's avatar
mengcuiguang committed
144 145
		refresherOutRate: {
			type: Number,
jyx's avatar
jyx committed
146
			default: u.gc('refresherOutRate', 0.7)
mengcuiguang's avatar
mengcuiguang committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
		},
		//是否显示最后更新时间,默认为否
		showRefresherUpdateTime: {
			type: Boolean,
			default: u.gc('showRefresherUpdateTime', false)
		},
		//如果需要区别不同页面的最后更新时间,请为不同页面的z-paging的`refresher-update-time-key`设置不同的字符串
		refresherUpdateTimeKey: {
			type: String,
			default: u.gc('refresherUpdateTimeKey', 'default')
		},
	},
	data() {
		return {
			//下拉刷新状态
			refresherStatus: Enum.Refresher.Default,
			refresherTouchstartY: 0,
			lastRefresherTouchmove: null,
			refresherReachMaxAngle: true,
			refresherTransform: 'translateY(0px)',
			refresherTransition: '',
			finalRefresherDefaultStyle: 'black',
			refresherRevealStackCount: 0,
			refresherCompleteTimeout: null,
			refresherCompleteSubTimeout: null,
			refresherEndTimeout: null,
			refresherTriggered: false,
			isTouchmoving: false,
			isTouchEnded: false,
			isUserPullDown: false,
			privateRefresherEnabled: -1,
			privateShowRefresherWhenReload: false,
			customRefresherHeight: -1,
			showCustomRefresher: false,
			doRefreshAnimateAfter: false,
			isRefresherInComplete: false,
			pullDownTimeStamp: 0,
			moveDis: 0,
			oldMoveDis: 0,
		}
	},
	watch: {
		refresherDefaultStyle: {
			handler(newVal) {
				if (newVal.length) {
					this.finalRefresherDefaultStyle = newVal;
				}
			},
			immediate: true
		},
jyx's avatar
jyx committed
197 198 199 200
		refresherStatus(newVal, oldVal) {
			if (newVal === Enum.Refresher.Loading){
				this._cleanRefresherEndTimeout();
			}
mengcuiguang's avatar
mengcuiguang committed
201 202 203
			this.$emit('refresherStatusChange', newVal);
			this.$emit('update:refresherStatus', newVal);
		},
jyx's avatar
jyx committed
204 205
		moveDis(newVal, oldVal){
			this.oldMoveDis = oldVal;
mengcuiguang's avatar
mengcuiguang committed
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
		}
	},
	computed: {
		pullDownDisTimeStamp() {
			return 1000 / this.refresherFps;
		},
		finalRefresherEnabled() {
			if (this.useChatRecordMode) return false;
			if (this.privateRefresherEnabled === -1) return this.refresherEnabled;
			return this.privateRefresherEnabled === 1;
		},
		finalRefresherThreshold() {
			let refresherThreshold = this.refresherThreshold;
			let idDefault = false;
			if (refresherThreshold === '80rpx') {
				idDefault = true;
				if (this.showRefresherUpdateTime) {
					refresherThreshold = '120rpx';
				}
			}
jyx's avatar
jyx committed
226 227 228 229
			if (idDefault && this.customRefresherHeight > 0) {
				return this.customRefresherHeight;
			}
			return u.convertTextToPx(refresherThreshold);
mengcuiguang's avatar
mengcuiguang committed
230 231
		},
		finalRefresherFixedBacHeight() {
jyx's avatar
jyx committed
232
			return u.convertTextToPx(this.refresherFixedBacHeight);
mengcuiguang's avatar
mengcuiguang committed
233 234 235 236 237 238 239 240 241 242 243
		},
		finalRefresherThemeStyle() {
			return this.refresherThemeStyle.length ? this.refresherThemeStyle : this.defaultThemeStyle;
		},
		finalRefresherOutRate() {
			let rate = this.refresherOutRate;
			rate = Math.max(0,rate);
			rate = Math.min(1,rate);
			return rate;
		},
		finalRefresherTransform() {
jyx's avatar
jyx committed
244
			if (this.refresherTransform === 'translateY(0px)') return 'none';
mengcuiguang's avatar
mengcuiguang committed
245 246 247 248 249 250 251 252 253 254
			return this.refresherTransform;
		},
		finalShowRefresherWhenReload() {
			return this.showRefresherWhenReload || this.privateShowRefresherWhenReload;
		},
		finalRefresherTriggered() {
			if (!(this.finalRefresherEnabled && !this.useCustomRefresher)) return false;
			return this.refresherTriggered;
		},
		showRefresher() {
jyx's avatar
jyx committed
255
			const showRefresher = this.finalRefresherEnabled && this.useCustomRefresher && this.isTouchmoving;
mengcuiguang's avatar
mengcuiguang committed
256
			// #ifndef APP-NVUE
jyx's avatar
jyx committed
257 258 259 260 261 262 263
			if (this.customRefresherHeight === -1 && showRefresher) {
				setTimeout(() => {
					this.$nextTick(()=>{
						this._updateCustomRefresherHeight();
					})
				}, 100)
			}
mengcuiguang's avatar
mengcuiguang committed
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
			// #endif
			return showRefresher;
		},
		hasTouchmove(){
			// #ifdef VUE2
			// #ifdef APP-VUE || H5
			if (this.$listeners && !this.$listeners.refresherTouchmove) return false;
			// #endif
			// #ifdef MP-WEIXIN || MP-QQ
			return this.watchRefresherTouchmove;
			// #endif
			return true;
			// #endif
			return this.watchRefresherTouchmove;
		},
	},
	methods: {
		//终止下拉刷新状态
jyx's avatar
jyx committed
282 283
		endRefresh(){
		   this._refresherEnd();
mengcuiguang's avatar
mengcuiguang committed
284 285 286 287 288
		},
		handleRefresherStatusChanged(func) {
			this.refresherStatusChangedFunc = func;
		},
		//自定义下拉刷新被触发
jyx's avatar
jyx committed
289
		_onRefresh(fromScrollView=false,isUserPullDown=true) {
mengcuiguang's avatar
mengcuiguang committed
290 291 292 293 294 295 296 297 298 299 300
			if (fromScrollView && !(this.finalRefresherEnabled && !this.useCustomRefresher)) return;
			this.$emit('onRefresh');
			this.$emit('Refresh');
			if (this.loading || this.isRefresherInComplete) return;
			this.loadingType = Enum.LoadingType.Refresher;
			if (this.nShowRefresherReveal) return;
			this.isUserPullDown = isUserPullDown;
			this.isUserReload = !isUserPullDown;
			this._startLoading(true);
			this.refresherTriggered = true;
			if(this.reloadWhenRefresh && isUserPullDown){
jyx's avatar
jyx committed
301 302 303 304 305
				if (this.useChatRecordMode) {
					this._onLoadingMore('click')
				} else {
					this._reload(false, false, isUserPullDown);
				}
mengcuiguang's avatar
mengcuiguang committed
306 307 308 309 310 311 312 313 314 315 316 317
			}
		},
		//自定义下拉刷新被复位
		_onRestore() {
			this.refresherTriggered = 'restore';
			this.$emit('onRestore');
			this.$emit('Restore');
		},
		// #ifndef APP-VUE || MP-WEIXIN || MP-QQ || H5
		//拖拽开始
		_refresherTouchstart(e) {
			if (this._touchDisabled()) return;
jyx's avatar
jyx committed
318 319
			const touch = u.getTouch(e);
			this._handleRefresherTouchstart(touch);
mengcuiguang's avatar
mengcuiguang committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
		},
		// #endif
		//进一步处理拖拽开始结果
		_handleRefresherTouchstart(touch) {
			if (!this.loading && this.isTouchEnded) {
				this.isTouchmoving = false;
			}
			this.isTouchEnded = false;
			this.refresherTransition = '';
			this.refresherTouchstartY = touch.touchY;
			this.$emit('refresherTouchstart', this.refresherTouchstartY);
			this.lastRefresherTouchmove = touch;
			this._cleanRefresherCompleteTimeout();
			this._cleanRefresherEndTimeout();
		},
		// #ifndef APP-VUE || MP-WEIXIN || MP-QQ || H5
		//拖拽中
		_refresherTouchmove(e) {
			const currentTimeStamp = u.getTime();
			if (this.pullDownTimeStamp && currentTimeStamp - this.pullDownTimeStamp <= this.pullDownDisTimeStamp) return;
			if (this._touchDisabled()) return;
			this.pullDownTimeStamp = Number(currentTimeStamp);
jyx's avatar
jyx committed
342 343
			const touch = u.getTouch(e);
			let refresherTouchmoveY = touch.touchY;
mengcuiguang's avatar
mengcuiguang committed
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
			let moveDis = refresherTouchmoveY - this.refresherTouchstartY;
			if (moveDis < 0) return;
			if (this.refresherMaxAngle >= 0 && this.refresherMaxAngle <= 90 && this.lastRefresherTouchmove && this.lastRefresherTouchmove.touchY <= refresherTouchmoveY) {
				if (!moveDis && !this.refresherAngleEnableChangeContinued && this.moveDis < 1 && !this.refresherReachMaxAngle) return;
				const x = Math.abs(touch.touchX - this.lastRefresherTouchmove.touchX);
				const y = Math.abs(refresherTouchmoveY - this.lastRefresherTouchmove.touchY);
				const z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
				if ((x || y) && x > 1) {
					const angle = Math.asin(y / z) / Math.PI * 180;
					if (angle < this.refresherMaxAngle) {
						this.lastRefresherTouchmove = touch;
						this.refresherReachMaxAngle = false;
						return;
					}
				}
			}
			moveDis = this._getFinalRefresherMoveDis(moveDis);
			this._handleRefresherTouchmove(moveDis, touch);
			if (!this.disabledBounce) {
jyx's avatar
jyx committed
363 364 365 366 367
				if(this.isIos){
					// #ifndef MP-LARK
					this._handleScrollViewDisableBounce({bounce: false});
					// #endif
				}
mengcuiguang's avatar
mengcuiguang committed
368 369
				this.disabledBounce = true;
			}
jyx's avatar
jyx committed
370
			this._emitTouchmove({pullingDistance:moveDis,dy:this.moveDis - this.oldMoveDis});
mengcuiguang's avatar
mengcuiguang committed
371 372 373 374 375 376
		},
		// #endif
		//进一步处理拖拽中结果
		_handleRefresherTouchmove(moveDis, touch) {
			this.refresherReachMaxAngle = true;
			this.isTouchmoving = true;
jyx's avatar
jyx committed
377
			//this.refresherTransition = '';
mengcuiguang's avatar
mengcuiguang committed
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
			this.isTouchEnded = false;
			this.refresherStatus = moveDis >= this.finalRefresherThreshold ? Enum.Refresher.ReleaseToRefresh : this.refresherStatus = Enum.Refresher.Default;
			// #ifndef APP-VUE || MP-WEIXIN || MP-QQ  || H5
			// this.scrollEnable = false;
			this.refresherTransform = `translateY(${moveDis}px)`;
			this.lastRefresherTouchmove = touch;
			// #endif
			this.moveDis = moveDis;
		},
		// #ifndef APP-VUE || MP-WEIXIN || MP-QQ || H5
		//拖拽结束
		_refresherTouchend(e) {
			if (this._touchDisabled() || !this.isTouchmoving) return;
			const touch = u.getTouch(e);
			let refresherTouchendY = touch.touchY;
			let moveDis = refresherTouchendY - this.refresherTouchstartY;
			moveDis = this._getFinalRefresherMoveDis(moveDis);
			this._handleRefresherTouchend(moveDis);
jyx's avatar
jyx committed
396
			this._handleScrollViewDisableBounce({bounce: true});
mengcuiguang's avatar
mengcuiguang committed
397 398 399 400 401 402 403 404 405
			this.disabledBounce = false;
		},
		// #endif
		//进一步处理拖拽结束结果
		_handleRefresherTouchend(moveDis) {
			// #ifndef APP-PLUS || H5 || MP-WEIXIN
			if (!this.isTouchmoving) return;
			// #endif
			this.refresherReachMaxAngle = true;
jyx's avatar
jyx committed
406 407 408 409 410
			if (moveDis < 0 && this.usePageScroll && this.loadingMoreEnabled && this.useCustomRefresher && this.pageScrollTop === -1) {
				if (this.showConsoleError) {
					u.consoleErr('usePageScroll为true并且自定义下拉刷新时必须引入mixin或在page滚动时通过调用z-paging组件的updatePageScrollTop方法设置当前的scrollTop');
				}
			}
mengcuiguang's avatar
mengcuiguang committed
411
			this.isTouchEnded = true;
jyx's avatar
jyx committed
412 413 414
			if (moveDis >= this.finalRefresherThreshold && this.refresherStatus === Enum.Refresher.ReleaseToRefresh) {
				// #ifndef APP-VUE || MP-WEIXIN || MP-QQ  || H5
				this.refresherTransform = `translateY(${this.finalRefresherThreshold}px)`;
mengcuiguang's avatar
mengcuiguang committed
415
				// #endif
jyx's avatar
jyx committed
416
				this.moveDis = this.finalRefresherThreshold;
mengcuiguang's avatar
mengcuiguang committed
417 418 419 420
				this.refresherStatus = Enum.Refresher.Loading;
				this._doRefresherLoad();
			} else {
				this._refresherEnd();
jyx's avatar
jyx committed
421
				setTimeout(() => {
mengcuiguang's avatar
mengcuiguang committed
422
					this.isTouchmoving = false;
jyx's avatar
jyx committed
423
				}, c.delayTime);
mengcuiguang's avatar
mengcuiguang committed
424 425
			}
			this.scrollEnable = true;
jyx's avatar
jyx committed
426
			// this.refresherTransition = 'transform .1s linear';
mengcuiguang's avatar
mengcuiguang committed
427 428 429
			this.$emit('refresherTouchend', moveDis);
		},
		//处理scroll-view bounce是否生效
jyx's avatar
jyx committed
430
		_handleScrollViewDisableBounce(e) {
mengcuiguang's avatar
mengcuiguang committed
431
			if (!this.usePageScroll && !this.scrollToTopBounceEnabled) {
jyx's avatar
jyx committed
432 433
				this.refresherTransition = '';
				this.scrollEnable = e.bounce;
mengcuiguang's avatar
mengcuiguang committed
434 435 436 437 438 439 440 441 442 443
			}
		},
		//wxs正在下拉状态改变处理
		_handleWxsPullingDownStatusChange(onPullingDown) {
			this.wxsOnPullingDown = onPullingDown;
			if (onPullingDown && !this.useChatRecordMode) {
				this.renderPropScrollTop = 0;
			}
		},
		//wxs正在下拉处理
jyx's avatar
jyx committed
444 445
		_handleWxsPullingDown(e){
			this._emitTouchmove({pullingDistance:e.moveDis,dy:e.diffDis});
mengcuiguang's avatar
mengcuiguang committed
446 447 448 449
		},
		//下拉刷新结束
		_refresherEnd(shouldEndLoadingDelay = true, fromAddData = false, isUserPullDown = false, setLoading = true) {
			if (this.loadingType === Enum.LoadingType.Refresher) {
jyx's avatar
jyx committed
450 451 452 453
				let refresherCompleteDelay = 0;
				if(fromAddData && (isUserPullDown || this.showRefresherWhenReload)){
					refresherCompleteDelay = this.refresherCompleteDuration > 700 ? 1 : this.refresherCompleteDelay;
				}
mengcuiguang's avatar
mengcuiguang committed
454 455 456
				const refresherStatus = refresherCompleteDelay > 0 ? Enum.Refresher.Complete : Enum.Refresher.Default;
				if (this.finalShowRefresherWhenReload) {
					const stackCount = this.refresherRevealStackCount;
jyx's avatar
jyx committed
457
					this.refresherRevealStackCount--;
mengcuiguang's avatar
mengcuiguang committed
458 459 460
					if (stackCount > 1) return;
				}
				this._cleanRefresherEndTimeout();
jyx's avatar
jyx committed
461
				this.refresherEndTimeout = setTimeout(() => {
mengcuiguang's avatar
mengcuiguang committed
462
					this.refresherStatus = refresherStatus;
jyx's avatar
jyx committed
463
				}, refresherStatus === Enum.Refresher.Default ? this.refresherCompleteDuration : 0);
mengcuiguang's avatar
mengcuiguang committed
464 465 466 467 468 469 470
				
				// #ifndef APP-NVUE
				if (refresherCompleteDelay > 0) {
					this.isRefresherInComplete = true;
				}
				// #endif
				this._cleanRefresherCompleteTimeout();
jyx's avatar
jyx committed
471
				this.refresherCompleteTimeout = setTimeout(() => {
mengcuiguang's avatar
mengcuiguang committed
472 473 474 475 476
					let animateDuration = 1;
					const animateType = this.refresherEndBounceEnabled && fromAddData ? 'cubic-bezier(0.19,1.64,0.42,0.72)' : 'linear';
					if (fromAddData) {
						animateDuration = this.refresherEndBounceEnabled ? this.refresherCompleteDuration / 1000 : this.refresherCompleteDuration / 3000;
					}
jyx's avatar
jyx committed
477
					this.refresherTransition = `transform ${fromAddData?animateDuration:0.1}s ${animateType}`;
mengcuiguang's avatar
mengcuiguang committed
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
					// #ifndef APP-VUE || MP-WEIXIN || MP-QQ  || H5
					this.refresherTransform = 'translateY(0px)';
					// #endif
					// #ifdef APP-VUE || MP-WEIXIN || MP-QQ || H5
					this.wxsPropType = this.refresherTransition + 'end' + u.getTime();
					// #endif
					// #ifdef APP-NVUE
					this._nRefresherEnd();
					// #endif
					this.moveDis = 0;
					// #ifndef APP-NVUE
					if (refresherStatus === Enum.Refresher.Complete) {
						if (this.refresherCompleteSubTimeout) {
							clearTimeout(this.refresherCompleteSubTimeout);
							this.refresherCompleteSubTimeout = null;
						}
jyx's avatar
jyx committed
494
						this.refresherCompleteSubTimeout = setTimeout(() => {
mengcuiguang's avatar
mengcuiguang committed
495 496 497 498 499 500 501 502 503 504
							this.$nextTick(() => {
								this.refresherStatus = Enum.Refresher.Default;
								this.isRefresherInComplete = false;
							})
						}, animateDuration * 800);
					}
					// #endif
				}, refresherCompleteDelay);
			}
			if (setLoading) {
jyx's avatar
jyx committed
505 506 507
				setTimeout(() => {
					this.loading = false;
				}, shouldEndLoadingDelay ? c.delayTime : 0);
mengcuiguang's avatar
mengcuiguang committed
508 509 510 511 512 513 514 515 516 517 518 519 520 521
				isUserPullDown && this._onRestore();
			}
		},
		//模拟用户手动触发下拉刷新
		_doRefresherRefreshAnimate() {
			this._cleanRefresherCompleteTimeout();
			// #ifndef APP-NVUE
			const doRefreshAnimateAfter = !this.doRefreshAnimateAfter && (this.finalShowRefresherWhenReload) && this
				.customRefresherHeight === -1 && this.refresherThreshold === '80rpx';
			if (doRefreshAnimateAfter) {
				this.doRefreshAnimateAfter = true;
				return;
			}
			// #endif
jyx's avatar
jyx committed
522
			this.refresherRevealStackCount++;
mengcuiguang's avatar
mengcuiguang committed
523 524 525 526 527 528 529 530 531 532
			this.refresherTransform = `translateY(${this.finalRefresherThreshold}px)`;
			// #ifdef APP-VUE || MP-WEIXIN || MP-QQ || H5
			this.wxsPropType = 'begin' + u.getTime();
			// #endif
			this.moveDis = this.finalRefresherThreshold;
			this.refresherStatus = Enum.Refresher.Loading;
			this.isTouchmoving = true;
			this._doRefresherLoad(false);
		},
		//触发下拉刷新
jyx's avatar
jyx committed
533
		_doRefresherLoad(isUserPullDown=true) {
mengcuiguang's avatar
mengcuiguang committed
534 535 536 537 538
			this._onRefresh(false,isUserPullDown);
			this.loading = true;
		},
		//获取处理后的moveDis
		_getFinalRefresherMoveDis(moveDis) {
jyx's avatar
jyx committed
539 540 541
			moveDis = moveDis * 0.85;
			if (moveDis >= this.finalRefresherThreshold) {
				moveDis = this.finalRefresherThreshold + (moveDis - this.finalRefresherThreshold) * (1 - this.finalRefresherOutRate);
mengcuiguang's avatar
mengcuiguang committed
542
			}
jyx's avatar
jyx committed
543
			return moveDis;
mengcuiguang's avatar
mengcuiguang committed
544
		},
jyx's avatar
jyx committed
545
		// #ifndef APP-VUE || MP-WEIXIN || MP-QQ || H5
mengcuiguang's avatar
mengcuiguang committed
546 547
		//判断touch手势是否要触发
		_touchDisabled() {
jyx's avatar
jyx committed
548
			let checkOldScrollTop = this.oldScrollTop > 5;
mengcuiguang's avatar
mengcuiguang committed
549 550 551 552 553 554
			return this.loading || this.isRefresherInComplete || this.useChatRecordMode || !this.refresherEnabled || !this.useCustomRefresher ||(this.usePageScroll && this.useCustomRefresher && this.pageScrollTop > 10) || (!(this.usePageScroll && this.useCustomRefresher) && checkOldScrollTop);
		},
		// #endif
		//更新自定义下拉刷新view高度
		_updateCustomRefresherHeight() {
			this._getNodeClientRect('.zp-custom-refresher-slot-view').then((res) => {
jyx's avatar
jyx committed
555 556 557 558 559 560 561 562
				if (res) {
					this.customRefresherHeight = res[0].height;
					if (this.customRefresherHeight > 0) {
						this.showCustomRefresher = true;
					}
				} else {
					this.customRefresherHeight = 0;
				}
mengcuiguang's avatar
mengcuiguang committed
563 564 565 566 567 568 569
				if (this.doRefreshAnimateAfter) {
					this.doRefreshAnimateAfter = false;
					this._doRefresherRefreshAnimate();
				}
			});
		},
		//发射pullingDown事件
jyx's avatar
jyx committed
570
		_emitTouchmove(e){
mengcuiguang's avatar
mengcuiguang committed
571 572 573
			// #ifndef APP-NVUE
			e.viewHeight = this.finalRefresherThreshold;
			// #endif
jyx's avatar
jyx committed
574 575 576 577
			e.rate = e.pullingDistance / e.viewHeight;
			if(this.hasTouchmove){
				this.$emit('refresherTouchmove',e);
			}
mengcuiguang's avatar
mengcuiguang committed
578 579 580 581 582 583 584 585 586 587 588 589 590 591
		},
		//清除refresherCompleteTimeout
		_cleanRefresherCompleteTimeout() {
			this.refresherCompleteTimeout = this._cleanTimeout(this.refresherCompleteTimeout);
			// #ifdef APP-NVUE
			this._nRefresherEnd(false);
			// #endif
		},
		//清除refresherEndTimeout
		_cleanRefresherEndTimeout() {
			this.refresherEndTimeout = this._cleanTimeout(this.refresherEndTimeout);
		},
	}
}
jyx's avatar
jyx committed
592 593

export default ZPRefresher;