index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import {
  2. createStoreBindings
  3. } from 'mobx-miniprogram-bindings'
  4. import {
  5. getCategoryList,
  6. getResourceList
  7. } from "~/api/works"
  8. import share from '~/mixins/share'
  9. import reachBottom from '~/mixins/reachBottom'
  10. import {
  11. store
  12. } from '~/store/index'
  13. Page({
  14. behaviors: [reachBottom, share],
  15. data: {
  16. categoryList: [],
  17. listOptions: {},
  18. isFixed: false
  19. },
  20. onShow() {
  21. if (typeof this.getTabBar === 'function') {
  22. this.getTabBar().setData({
  23. selected: 1
  24. })
  25. }
  26. this.getLocUserInfo()
  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. },
  36. requestAgain() {
  37. this.resetData()
  38. this.getCategoryList()
  39. },
  40. async loadMore() {
  41. if (!this.data.userInfo.grade) {
  42. return
  43. }
  44. let data = await getResourceList({
  45. grade: this.data.userInfo.grade
  46. })
  47. this.setData({
  48. listOptions: data,
  49. })
  50. console.log(data, );
  51. },
  52. async getCategoryList() {
  53. let grade = this.data.userInfo.grade
  54. let categoryList = await getCategoryList({
  55. grade
  56. })
  57. this.setData({
  58. categoryList
  59. })
  60. },
  61. jumpChildClassify({
  62. currentTarget
  63. }) {
  64. let firstInfo = currentTarget.dataset.item
  65. let params = firstInfo.childList.length > 0 ? `list=${encodeURIComponent(JSON.stringify(firstInfo.childList))}` : `id=${firstInfo.id}`
  66. wx.navigateTo({
  67. url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&${params}`,
  68. })
  69. },
  70. onUnload() {
  71. this.storeBindings.destroyStoreBindings()
  72. },
  73. async getLocUserInfo() {
  74. this.storeBindings = createStoreBindings(this, {
  75. store,
  76. fields: {
  77. userInfo: 'userInfo'
  78. },
  79. })
  80. this.storeBindings.updateStoreBindings()
  81. },
  82. onUnload() {
  83. this.storeBindings.destroyStoreBindings()
  84. },
  85. /**
  86. * 监听页面滚动事件
  87. */
  88. onPageScroll(e) {
  89. if (e.scrollTop >= 6 && !this.data.isFixed) {
  90. this.setData({
  91. isFixed: true
  92. })
  93. } else if (e.scrollTop < 6 && this.data.isFixed) {
  94. this.setData({
  95. isFixed: false
  96. })
  97. }
  98. },
  99. })