index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import share from '~/mixins/share'
  2. import {
  3. getHotrecommendList,
  4. } from "~/api/works"
  5. import event from '~/mixins/event'
  6. import reachBottom from '~/mixins/reachBottom'
  7. import {
  8. createStoreBindings
  9. } from 'mobx-miniprogram-bindings'
  10. import {
  11. store
  12. } from '~/store/index'
  13. Page({
  14. behaviors: [reachBottom, share, event],
  15. data: {
  16. isFixed: false
  17. },
  18. onShow() {
  19. if (typeof this.getTabBar === 'function') {
  20. this.getTabBar().setData({
  21. selected: 1
  22. })
  23. }
  24. this.getLocUserInfo()
  25. if (Object.keys(this.data.userInfo).length > 0) {
  26. this.requestAgain()
  27. } else {
  28. getApp().callBack = (res) => {
  29. this.getLocUserInfo()
  30. this.requestAgain()
  31. }
  32. }
  33. },
  34. loadMore() {
  35. if (!this.data.userInfo.grade) {
  36. return
  37. }
  38. this.localGetData(getHotrecommendList, {
  39. grade: this.data.userInfo.grade
  40. })
  41. },
  42. requestAgain() {
  43. this.resetData()
  44. },
  45. async getLocUserInfo() {
  46. this.storeBindings = createStoreBindings(this, {
  47. store,
  48. fields: {
  49. userInfo: 'userInfo'
  50. },
  51. })
  52. this.storeBindings.updateStoreBindings()
  53. },
  54. onReachBottom() {
  55. this.loadMore()
  56. },
  57. onUnload() {
  58. this.storeBindings.destroyStoreBindings()
  59. },
  60. })