index.js 2.3 KB

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