z-paging-renderjs.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // z-paging
  2. // github地址:https://github.com/SmileZXLee/uni-z-paging
  3. // dcloud地址:https://ext.dcloud.net.cn/plugin?id=3935
  4. // 反馈QQ群:790460711
  5. // 使用renderjs在app-vue和h5中对touchmove事件冒泡进行处理
  6. import zUtils from '../js/z-paging-utils'
  7. var data = {
  8. renderScrollTop: 0,
  9. renderUsePageScroll: false,
  10. renderIsIos: uni.getSystemInfoSync().platform === 'ios',
  11. startY: 0,
  12. isTouchFromZPaging: false
  13. }
  14. export default {
  15. mounted() {
  16. this._handleTouch();
  17. },
  18. methods: {
  19. //接收逻辑层发送的数据
  20. renderPropScrollTopChange(newVal, oldVal, ownerVm, vm) {
  21. data.renderScrollTop = newVal;
  22. },
  23. renderPropUsePageScrollChange(newVal, oldVal, ownerVm, vm) {
  24. if(newVal !== -1){
  25. data.renderUsePageScroll = newVal;
  26. }
  27. },
  28. //拦截处理touch事件
  29. _handleTouch() {
  30. if (window && !window.$zPagingRenderJsInited) {
  31. window.$zPagingRenderJsInited = true;
  32. window.addEventListener('touchstart', this._handleTouchstart, {
  33. passive: true
  34. })
  35. window.addEventListener('touchmove', this._handleTouchmove, {
  36. passive: false
  37. })
  38. }
  39. },
  40. _handleTouchstart(e) {
  41. const touch = zUtils.getCommonTouch(e);
  42. data.startY = touch.touchY;
  43. data.isTouchFromZPaging = zUtils.getTouchFromZPaging(e.target);
  44. },
  45. _handleTouchmove(e) {
  46. const touch = zUtils.getCommonTouch(e);
  47. var moveY = touch.touchY - data.startY;
  48. if ((data.isTouchFromZPaging && data.renderScrollTop < 1 && moveY > 0) || (data.isTouchFromZPaging && data
  49. .renderIsIos && !data
  50. .renderUsePageScroll && moveY <
  51. 0)) {
  52. if (e.cancelable && !e.defaultPrevented) {
  53. e.preventDefault();
  54. }
  55. }
  56. },
  57. }
  58. };