scroll-view.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. let itemCount = 100
  2. let items = [...new Array(itemCount)].map((v, i) => i)
  3. import ad from '../index/ad'
  4. ad({
  5. data: {
  6. disableScroll: false,
  7. height: 300,
  8. itemHeight: 50,
  9. itemBuffer: 30,
  10. scrollToIndex: 0,
  11. scrollWithAnimation: false,
  12. },
  13. onLoad() {
  14. this.updated(items)
  15. },
  16. updated(items) {
  17. const startTime = Date.now()
  18. this.virtualList = this.virtualList || this.selectComponent('#wux-virtual-list')
  19. this.virtualList.render(items, () => {
  20. const diffTime = Date.now() - startTime
  21. console.log(`onSuccess - render time: ${diffTime}ms`)
  22. })
  23. },
  24. loadData(e) {
  25. if (itemCount >= 1000) return
  26. if (this.data.disableScroll) return
  27. this.setData({ disableScroll: true })
  28. wx.showLoading()
  29. setTimeout(() => {
  30. itemCount += 100
  31. items = [...new Array(itemCount)].map((v, i) => i)
  32. this.updated(items)
  33. this.setData({ disableScroll: false })
  34. wx.hideLoading()
  35. }, 3000)
  36. console.log('loadData', e.detail)
  37. },
  38. onChange(e) {
  39. const { startIndex, endIndex } = e.detail
  40. if (this.data.startIndex !== startIndex || this.data.endIndex !== endIndex) {
  41. this.setData(e.detail)
  42. console.log('onChange', e.detail)
  43. }
  44. },
  45. onScrollToLower(e) {
  46. this.loadData(e)
  47. console.log('onScrollToLower', e)
  48. },
  49. onInputBlur(e) {
  50. const { meta } = e.currentTarget.dataset
  51. this.setData({ [meta]: e.detail.value })
  52. console.log('onInputBlur', e)
  53. },
  54. onSwicth(e) {
  55. const { meta } = e.currentTarget.dataset
  56. this.setData({ [meta]: e.detail.value })
  57. console.log('onSwicth', e)
  58. },
  59. })