page-scroll.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. let height = wx.getSystemInfoSync().windowHeight
  2. let itemCount = 1000
  3. let items = [...new Array(itemCount)].map((v, i) => i)
  4. import ad from '../index/ad'
  5. ad({
  6. data: {
  7. disableScroll: false,
  8. height,
  9. },
  10. onLoad() {
  11. this.updated(items)
  12. },
  13. updated(items) {
  14. const startTime = Date.now()
  15. this.virtualList = this.virtualList || this.selectComponent('#wux-virtual-list')
  16. this.virtualList.render(items, () => {
  17. const diffTime = Date.now() - startTime
  18. console.log(`onSuccess - render time: ${diffTime}ms`)
  19. })
  20. },
  21. loadData() {
  22. if (itemCount >= 10000) return
  23. if (this.data.disableScroll) return
  24. this.setData({ disableScroll: true })
  25. wx.showLoading()
  26. setTimeout(() => {
  27. itemCount += 1000
  28. items = [...new Array(itemCount)].map((v, i) => i)
  29. this.updated(items)
  30. this.setData({ disableScroll: false })
  31. wx.hideLoading()
  32. wx.stopPullDownRefresh()
  33. }, 3000)
  34. console.log('loadData')
  35. },
  36. onChange(e) {
  37. const { startIndex, endIndex } = e.detail
  38. if (this.data.startIndex !== startIndex || this.data.endIndex !== endIndex) {
  39. this.setData(e.detail)
  40. console.log('onChange', e.detail)
  41. }
  42. },
  43. onPageScroll(e) {
  44. // 当页面滚动时调用组件 scrollHandler 方法
  45. this.virtualList.scrollHandler({ detail: e })
  46. // console.log('onPageScroll', e)
  47. },
  48. onReachBottom() {
  49. this.loadData()
  50. console.log('onReachBottom')
  51. },
  52. onPullDownRefresh() {
  53. itemCount = 0
  54. this.loadData()
  55. console.log('onPullDownRefresh')
  56. },
  57. })