index.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. showTips() {
  72. wx.showModal({
  73. title: '新栏目更新中',
  74. content: '敬请期待….',
  75. showCancel: false,
  76. confirmColor:'#333333',
  77. success(res) {
  78. }
  79. })
  80. },
  81. onUnload() {
  82. this.storeBindings.destroyStoreBindings()
  83. },
  84. async getLocUserInfo() {
  85. this.storeBindings = createStoreBindings(this, {
  86. store,
  87. fields: {
  88. userInfo: 'userInfo'
  89. },
  90. })
  91. this.storeBindings.updateStoreBindings()
  92. },
  93. onUnload() {
  94. this.storeBindings.destroyStoreBindings()
  95. },
  96. })