index.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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: 0
  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. wx.navigateTo({
  67. url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&id=${firstInfo.id}`,
  68. })
  69. },
  70. showTips() {
  71. wx.showModal({
  72. title: '新栏目更新中',
  73. content: '敬请期待….',
  74. showCancel: false,
  75. confirmColor: '#333333',
  76. success(res) {}
  77. })
  78. },
  79. onUnload() {
  80. this.storeBindings.destroyStoreBindings()
  81. },
  82. async getLocUserInfo() {
  83. this.storeBindings = createStoreBindings(this, {
  84. store,
  85. fields: {
  86. userInfo: 'userInfo'
  87. },
  88. })
  89. this.storeBindings.updateStoreBindings()
  90. },
  91. onUnload() {
  92. this.storeBindings.destroyStoreBindings()
  93. },
  94. })