page-scroll.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.pageScrollMixin = void 0;
  6. function getCurrentPage() {
  7. var pages = getCurrentPages();
  8. return pages[pages.length - 1] || {};
  9. }
  10. function onPageScroll(event) {
  11. var _a = getCurrentPage().vanPageScroller;
  12. var vanPageScroller = _a === void 0 ? [] : _a;
  13. vanPageScroller.forEach(function (scroller) {
  14. if (typeof scroller === 'function') {
  15. scroller(event);
  16. }
  17. });
  18. }
  19. exports.pageScrollMixin = function (scroller) {
  20. return {
  21. beforeMount: function () {
  22. var page = getCurrentPage();
  23. if (Array.isArray(page.vanPageScroller)) {
  24. page.vanPageScroller.push(scroller.bind(this));
  25. } else {
  26. page.vanPageScroller = typeof page.onPageScroll === 'function' ? [page.onPageScroll.bind(page), scroller.bind(this)] : [scroller.bind(this)];
  27. }
  28. page.onPageScroll = onPageScroll;
  29. },
  30. destroyed: function () {
  31. var page = getCurrentPage();
  32. page.vanPageScroller = (page.vanPageScroller || []).filter(function (item) {
  33. return item !== scroller;
  34. });
  35. }
  36. };
  37. };