1
0
mirror da https://github.com/ialley-workshop-open/uni-halo.git synced 2026-06-12 13:19:31 +08:00
Files
uni-halo/uni_modules/z-paging/components/z-paging/wxs/z-paging-renderjs.js
T
2022-12-06 15:08:29 +08:00

69 righe
1.8 KiB
JavaScript

// [z-paging]使用renderjs在app-vue和h5中对touchmove事件冒泡进行处理
import u from '../js/z-paging-utils'
var data = {
renderScrollTop: 0,
renderUsePageScroll: false,
startY: 0,
isTouchFromZPaging: false,
isIosAndH5: false
}
var currentVm = null;
export default {
mounted() {
this._handleTouch();
// #ifdef APP-VUE
this.$ownerInstance && this.$ownerInstance.callMethod('_checkVirtualListScroll');
// #endif
},
methods: {
//接收逻辑层发送的数据
renderPropScrollTopChange(newVal, oldVal, ownerVm, vm) {
if (newVal === -1) return;
currentVm = ownerVm;
data.renderScrollTop = newVal;
},
renderPropUsePageScrollChange(newVal) {
if (newVal === -1) return;
data.renderUsePageScroll = newVal;
},
renderPropIsIosAndH5Change(newVal) {
if (newVal === -1) return;
data.isIosAndH5 = newVal;
},
//拦截处理touch事件
_handleTouch() {
if (window && !window.$zPagingRenderJsInited) {
window.$zPagingRenderJsInited = true;
window.addEventListener('touchstart', this._handleTouchstart, {
passive: true
})
window.addEventListener('touchmove', this._handleTouchmove, {
passive: false
})
}
},
_handleTouchstart(e) {
const touch = u.getTouch(e);
data.startY = touch.touchY;
data.isTouchFromZPaging = u.getTouchFromZPaging(e.target);
this.$ownerInstance && this.$ownerInstance.callMethod('_updateRenderJsData');
},
_handleTouchmove(e) {
const touch = u.getTouch(e);
var moveY = touch.touchY - data.startY;
if (data.isTouchFromZPaging && ((data.renderScrollTop < 1 && moveY > 0) || (data.isIosAndH5 && !data.renderUsePageScroll && moveY < 0))) {
if (e.cancelable && !e.defaultPrevented) {
e.preventDefault();
}
}
},
_removeAllEventListener(){
window.removeEventListener('touchstart');
window.removeEventListener('touchmove');
}
}
};