index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. const app = getApp()
  2. import {
  3. createStoreBindings
  4. } from 'mobx-miniprogram-bindings'
  5. import {
  6. getCategoryList,
  7. getResourceList
  8. } from "~/api/works"
  9. import share from '~/mixins/share'
  10. import event from '~/mixins/event'
  11. import reachBottom from '~/mixins/reachBottom'
  12. import {
  13. store
  14. } from '~/store/index'
  15. Page({
  16. behaviors: [reachBottom, share, event],
  17. data: {
  18. navBarHeight: app.globalData.navBarHeight,
  19. categoryList: [],
  20. listOptions: {},
  21. },
  22. onShow() {
  23. if (typeof this.getTabBar === 'function') {
  24. this.getTabBar().setData({
  25. selected: 1
  26. })
  27. }
  28. this.getLocUserInfo()
  29. if (Object.keys(this.data.userInfo).length > 0) {
  30. this.requestAgain()
  31. } else {
  32. getApp().callBack = (res) => {
  33. this.getLocUserInfo()
  34. this.requestAgain()
  35. }
  36. }
  37. },
  38. requestAgain() {
  39. this.resetData()
  40. this.getCategoryList()
  41. },
  42. async loadMore() {
  43. if (!this.data.userInfo.grade) {
  44. return
  45. }
  46. let data = await getResourceList({
  47. grade: this.data.userInfo.grade
  48. })
  49. this.setData({
  50. listOptions: data,
  51. })
  52. },
  53. async getCategoryList() {
  54. let grade = this.data.userInfo.grade
  55. let categoryList = await getCategoryList({
  56. grade
  57. })
  58. this.setData({
  59. categoryList
  60. })
  61. },
  62. jumpChildClassify({
  63. currentTarget
  64. }) {
  65. let firstInfo = currentTarget.dataset.item
  66. let params = firstInfo.childList.length > 0 ? `list=${encodeURIComponent(JSON.stringify(firstInfo.childList))}` : `id=${firstInfo.id}`
  67. wx.navigateTo({
  68. url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&${params}`,
  69. })
  70. },
  71. onUnload() {
  72. this.storeBindings.destroyStoreBindings()
  73. },
  74. async getLocUserInfo() {
  75. this.storeBindings = createStoreBindings(this, {
  76. store,
  77. fields: {
  78. userInfo: 'userInfo'
  79. },
  80. })
  81. this.storeBindings.updateStoreBindings()
  82. },
  83. onUnload() {
  84. this.storeBindings.destroyStoreBindings()
  85. },
  86. })