index.js 2.1 KB

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