index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. const app = getApp()
  2. import {
  3. getCategoryList,
  4. getResourceList
  5. } from "~/api/works"
  6. import {
  7. getBannerList
  8. } from '~/api/global'
  9. import event from '~/mixins/event'
  10. import share from '~/mixins/share'
  11. import {
  12. createStoreBindings
  13. } from 'mobx-miniprogram-bindings'
  14. import {
  15. store
  16. } from '~/store/index'
  17. Page({
  18. behaviors: [share, event],
  19. data: {
  20. navBarHeight: app.globalData.navBarHeight,
  21. desktopTips: app.globalData.desktopTips,
  22. bannerList: [],
  23. categoryList: [],
  24. listOptions: {},
  25. },
  26. onLoad(options) {
  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. let {
  37. desktopTips
  38. } = app.globalData
  39. if (desktopTips) {
  40. setTimeout(() => {
  41. this.setData({
  42. desktopTips: false
  43. })
  44. wx.setStorage({
  45. key: "preDesktopTime",
  46. data: new Date()
  47. })
  48. }, 6000)
  49. }
  50. this.requestMessage()
  51. },
  52. onShow() {
  53. if (typeof this.getTabBar === 'function') {
  54. this.getTabBar().setData({
  55. selected: 2
  56. })
  57. }
  58. },
  59. requestAgain() {
  60. this.getBannerList()
  61. this.getResource()
  62. this.getCategoryList()
  63. },
  64. async getLocUserInfo() {
  65. this.storeBindings = createStoreBindings(this, {
  66. store,
  67. fields: {
  68. userInfo: 'userInfo'
  69. },
  70. })
  71. this.storeBindings.updateStoreBindings()
  72. },
  73. async getCategoryList() {
  74. let grade = this.data.userInfo.grade
  75. let categoryList = await getCategoryList({
  76. grade
  77. })
  78. this.setData({
  79. categoryList
  80. })
  81. },
  82. async getResource() {
  83. let data = await getResourceList({
  84. grade: this.data.userInfo.grade
  85. })
  86. this.setData({
  87. listOptions: data,
  88. })
  89. },
  90. async getBannerList() {
  91. let bannerList = await getBannerList({
  92. grade: this.data.userInfo.grade,
  93. })
  94. this.setData({
  95. bannerList,
  96. })
  97. },
  98. jumpChildClassify({
  99. currentTarget
  100. }) {
  101. let firstInfo = currentTarget.dataset.item
  102. wx.navigateTo({
  103. url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&id=${firstInfo.id}`,
  104. })
  105. },
  106. showTips() {
  107. wx.showModal({
  108. title: '新栏目更新中',
  109. content: '敬请期待….',
  110. showCancel: false,
  111. confirmColor: '#333333',
  112. success(res) {}
  113. })
  114. },
  115. closeDesktop() {
  116. this.setData({
  117. desktopTips: false
  118. })
  119. wx.setStorage({
  120. key: "preDesktopTime",
  121. data: new Date()
  122. })
  123. },
  124. jumpSearch() {
  125. wx.navigateTo({
  126. url: '/pages/childClassify/index?type=search',
  127. })
  128. },
  129. requestMessage() {
  130. /* wx.requestSubscribeMessage({
  131. tmplIds: [''],
  132. success(res) {}
  133. }) */
  134. },
  135. onUnload() {
  136. this.storeBindings.destroyStoreBindings()
  137. },
  138. })