index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 event from '~/mixins/event'
  10. import reachBottom from '~/mixins/reachBottom'
  11. import {
  12. store
  13. } from '~/store/index'
  14. Page({
  15. behaviors: [reachBottom, share,event],
  16. data: {
  17. categoryList: [],
  18. listOptions: {},
  19. isFixed: false
  20. },
  21. onShow() {
  22. if (typeof this.getTabBar === 'function') {
  23. this.getTabBar().setData({
  24. selected: 1
  25. })
  26. }
  27. this.getLocUserInfo()
  28. if (Object.keys(this.data.userInfo).length > 0) {
  29. this.requestAgain()
  30. } else {
  31. getApp().callBack = (res) => {
  32. this.getLocUserInfo()
  33. this.requestAgain()
  34. }
  35. }
  36. },
  37. requestAgain() {
  38. this.resetData()
  39. this.getCategoryList()
  40. },
  41. async loadMore() {
  42. if (!this.data.userInfo.grade) {
  43. return
  44. }
  45. let data = await getResourceList({
  46. grade: this.data.userInfo.grade
  47. })
  48. this.setData({
  49. listOptions: data,
  50. })
  51. console.log(data, );
  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. onUnload() {
  72. this.storeBindings.destroyStoreBindings()
  73. },
  74. async getLocUserInfo() {
  75. this.storeBindings = createStoreBindings(this, {
  76. store,
  77. fields: {
  78. userInfo: 'userInfo'
  79. },
  80. })
  81. this.storeBindings.updateStoreBindings()
  82. },
  83. onUnload() {
  84. this.storeBindings.destroyStoreBindings()
  85. },
  86. /**
  87. * 监听页面滚动事件
  88. */
  89. onPageScroll(e) {
  90. if (e.scrollTop >= 6 && !this.data.isFixed) {
  91. this.setData({
  92. isFixed: true
  93. })
  94. } else if (e.scrollTop < 6 && this.data.isFixed) {
  95. this.setData({
  96. isFixed: false
  97. })
  98. }
  99. },
  100. })