index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. jump({
  55. currentTarget
  56. }) {
  57. let type = currentTarget.dataset.type
  58. wx.navigateTo({
  59. url: `/pages/userWorks/index?type=${type}`,
  60. })
  61. },
  62. onReachBottom() {
  63. this.loadMore()
  64. },
  65. onUnload() {
  66. this.storeBindings.destroyStoreBindings()
  67. },
  68. })