index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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我的作品
  20. currentType: '4',
  21. isFixed: false
  22. },
  23. onShow() {
  24. if (typeof this.getTabBar === 'function') {
  25. this.getTabBar().setData({
  26. selected: 1
  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. this.setData({
  52. currentType: target.dataset.type
  53. })
  54. this.selectComponent('#worksList').resetAudio()
  55. this.resetData()
  56. }
  57. },
  58. /**
  59. * 监听页面滚动事件
  60. */
  61. onPageScroll(e) {
  62. if (e.scrollTop >= 110 && !this.data.isFixed) {
  63. this.setData({
  64. isFixed: true
  65. })
  66. } else if (e.scrollTop < 20 && this.data.isFixed) {
  67. this.setData({
  68. isFixed: false
  69. })
  70. }
  71. },
  72. /**
  73. * 页面上拉触底事件的处理函数
  74. */
  75. onReachBottom() {
  76. this.loadMore()
  77. },
  78. })