index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const app = getApp()
  2. import share from '~/mixins/share'
  3. import {
  4. getSelfRead,
  5. getFavoritesList
  6. } from '~/api/user'
  7. import {
  8. getFollowWorks
  9. } from '~/api/works'
  10. import reachBottom from '~/mixins/reachBottom'
  11. import {
  12. createStoreBindings
  13. } from 'mobx-miniprogram-bindings'
  14. import {
  15. store
  16. } from '~/store/index'
  17. Page({
  18. behaviors: [reachBottom, share],
  19. data: {
  20. navBarHeight: app.globalData.navBarHeight,
  21. // 4关注作品,5我的作品,6收藏作品
  22. currentType: '4',
  23. isFixed: false
  24. },
  25. onShow() {
  26. if (typeof this.getTabBar === 'function') {
  27. this.getTabBar().setData({
  28. selected: 3
  29. })
  30. }
  31. this.getLocUserInfo()
  32. if (Object.keys(this.data.userInfo).length > 0) {
  33. this.requestAgain()
  34. } else {
  35. getApp().callBack = (res) => {
  36. this.getLocUserInfo()
  37. this.requestAgain()
  38. }
  39. }
  40. },
  41. loadMore() {
  42. if (this.data.currentType == '4') {
  43. this.getData(getFollowWorks, {})
  44. } else if (this.data.currentType == '5') {
  45. this.getData(getSelfRead, {})
  46. } else if (this.data.currentType == '6') {
  47. this.getData(getFavoritesList, {})
  48. }
  49. },
  50. changeType({
  51. target
  52. }) {
  53. if (target.dataset.type) {
  54. let workListDom = this.selectComponent('#worksList')
  55. if (workListDom) {
  56. this.selectComponent('#worksList').resetAudio()
  57. }
  58. this.setData({
  59. currentType: target.dataset.type
  60. })
  61. this.requestAgain()
  62. }
  63. },
  64. /**
  65. * 监听页面滚动事件
  66. */
  67. onPageScroll(e) {
  68. if (e.scrollTop >= 6 && !this.data.isFixed) {
  69. this.setData({
  70. isFixed: true
  71. })
  72. } else if (e.scrollTop < 6 && this.data.isFixed) {
  73. this.setData({
  74. isFixed: false
  75. })
  76. }
  77. },
  78. requestAgain() {
  79. this.resetData()
  80. },
  81. async getLocUserInfo() {
  82. this.storeBindings = createStoreBindings(this, {
  83. store,
  84. fields: {
  85. userInfo: 'userInfo'
  86. },
  87. })
  88. this.storeBindings.updateStoreBindings()
  89. },
  90. onReachBottom() {
  91. this.loadMore()
  92. },
  93. onUnload() {
  94. this.storeBindings.destroyStoreBindings()
  95. },
  96. })