index.js 1.5 KB

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