index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. const app = getApp()
  2. import {
  3. getBannerList
  4. } from '~/api/global'
  5. import share from '~/mixins/share'
  6. import {
  7. getSelfRead,
  8. getFavoritesList
  9. } from '~/api/user'
  10. import {
  11. getFollowWorks
  12. } from '~/api/works'
  13. import reachBottom from '~/mixins/reachBottom'
  14. Page({
  15. behaviors: [reachBottom, share],
  16. data: {
  17. navBarHeight: app.globalData.navBarHeight,
  18. bannerList: [],
  19. // 4关注作品,5我的作品,6收藏作品
  20. currentType: '4',
  21. isFixed: false
  22. },
  23. onShow() {
  24. if (typeof this.getTabBar === 'function') {
  25. this.getTabBar().setData({
  26. selected: 2
  27. })
  28. }
  29. let uid = wx.getStorageSync('uid')
  30. if (uid) {
  31. this.resetData()
  32. } else {
  33. getApp().callBack = (res) => {
  34. this.resetData()
  35. }
  36. }
  37. },
  38. loadMore() {
  39. if (this.data.currentType == '4') {
  40. this.getData(getFollowWorks, {})
  41. } else if (this.data.currentType == '5') {
  42. this.getData(getSelfRead, {})
  43. } else if (this.data.currentType == '6') {
  44. this.getData(getFavoritesList, {})
  45. }
  46. },
  47. changeType({
  48. target
  49. }) {
  50. if (target.dataset.type) {
  51. let workListDom = this.selectComponent('#worksList')
  52. if (workListDom) {
  53. this.selectComponent('#worksList').resetAudio()
  54. }
  55. this.setData({
  56. currentType: target.dataset.type
  57. })
  58. this.resetData()
  59. }
  60. },
  61. /**
  62. * 监听页面滚动事件
  63. */
  64. onPageScroll(e) {
  65. if (e.scrollTop >= 110 && !this.data.isFixed) {
  66. this.setData({
  67. isFixed: true
  68. })
  69. } else if (e.scrollTop < 20 && this.data.isFixed) {
  70. this.setData({
  71. isFixed: false
  72. })
  73. }
  74. },
  75. /**
  76. * 页面上拉触底事件的处理函数
  77. */
  78. onReachBottom() {
  79. this.loadMore()
  80. },
  81. })