index.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. },
  26. onShow() {
  27. if (Object.keys(this.data.userInfo).length > 0) {
  28. this.requestAgain()
  29. } else {
  30. getApp().callBack = (res) => {
  31. this.getLocUserInfo()
  32. this.requestAgain()
  33. }
  34. }
  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. let data = await getResourceList({
  65. grade: this.data.userInfo.grade
  66. })
  67. this.setData({
  68. listOptions: data,
  69. })
  70. },
  71. jumpChildClassify({
  72. currentTarget
  73. }) {
  74. let firstInfo = currentTarget.dataset.item
  75. wx.navigateTo({
  76. url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&id=${firstInfo.id}`,
  77. })
  78. },
  79. showTips() {
  80. wx.showModal({
  81. title: '新栏目更新中',
  82. content: '敬请期待….',
  83. showCancel: false,
  84. confirmColor: '#333333',
  85. success(res) {}
  86. })
  87. },
  88. jumpSearch() {
  89. wx.navigateTo({
  90. url: '/pages/childClassify/index?type=search',
  91. })
  92. },
  93. onUnload() {
  94. this.storeBindings.destroyStoreBindings()
  95. },
  96. })