index.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. const app = getApp()
  2. import {
  3. getCategoryList,
  4. getResourceList
  5. } from "~/api/works"
  6. import event from '~/mixins/event'
  7. import share from '~/mixins/share'
  8. import {
  9. createStoreBindings
  10. } from 'mobx-miniprogram-bindings'
  11. import {
  12. store
  13. } from '~/store/index'
  14. let storeBindings
  15. Page({
  16. behaviors: [share, event],
  17. data: {
  18. navBarHeight: app.globalData.navBarHeight,
  19. categoryList: [],
  20. listOptions: {},
  21. tmplIds: [],
  22. },
  23. onLoad(options) {
  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. onShow() {
  35. if (typeof this.getTabBar === 'function') {
  36. this.getTabBar().setData({
  37. selected: 2
  38. })
  39. }
  40. },
  41. requestAgain() {
  42. this.getResource()
  43. this.getCategoryList()
  44. },
  45. async getLocUserInfo() {
  46. this.storeBindings = createStoreBindings(this, {
  47. store,
  48. fields: {
  49. userInfo: 'userInfo',
  50. },
  51. })
  52. this.storeBindings.updateStoreBindings()
  53. },
  54. async getCategoryList() {
  55. let grade = this.data.userInfo.grade
  56. let categoryList = await getCategoryList({
  57. grade
  58. })
  59. this.setData({
  60. categoryList
  61. })
  62. },
  63. async getResource() {
  64. console.log(this.data.userInfo);
  65. let data = await getResourceList({
  66. grade: this.data.userInfo.grade
  67. })
  68. this.setData({
  69. listOptions: data,
  70. })
  71. },
  72. jumpChildClassify({
  73. currentTarget
  74. }) {
  75. let firstInfo = currentTarget.dataset.item
  76. wx.navigateTo({
  77. url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&id=${firstInfo.id}`,
  78. })
  79. },
  80. showTips() {
  81. wx.showModal({
  82. title: '新栏目更新中',
  83. content: '敬请期待….',
  84. showCancel: false,
  85. confirmColor: '#333333',
  86. success(res) {}
  87. })
  88. },
  89. jumpSearch() {
  90. wx.navigateTo({
  91. url: '/pages/childClassify/index?type=search',
  92. })
  93. },
  94. onUnload() {
  95. this.storeBindings.destroyStoreBindings()
  96. },
  97. })