index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. },
  51. onShow() {
  52. if (typeof this.getTabBar === 'function') {
  53. this.getTabBar().setData({
  54. selected: 2
  55. })
  56. }
  57. },
  58. requestAgain() {
  59. this.getBannerList()
  60. this.getResource()
  61. this.getCategoryList()
  62. },
  63. async getLocUserInfo() {
  64. this.storeBindings = createStoreBindings(this, {
  65. store,
  66. fields: {
  67. userInfo: 'userInfo'
  68. },
  69. })
  70. this.storeBindings.updateStoreBindings()
  71. },
  72. async getCategoryList() {
  73. let grade = this.data.userInfo.grade
  74. let categoryList = await getCategoryList({
  75. grade
  76. })
  77. this.setData({
  78. categoryList
  79. })
  80. },
  81. async getResource() {
  82. let data = await getResourceList({
  83. grade: this.data.userInfo.grade
  84. })
  85. this.setData({
  86. listOptions: data,
  87. })
  88. },
  89. async getBannerList() {
  90. let bannerList = await getBannerList({
  91. grade: this.data.userInfo.grade,
  92. })
  93. this.setData({
  94. bannerList,
  95. })
  96. },
  97. jumpChildClassify({
  98. currentTarget
  99. }) {
  100. let firstInfo = currentTarget.dataset.item
  101. wx.navigateTo({
  102. url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&id=${firstInfo.id}`,
  103. })
  104. },
  105. showTips() {
  106. wx.showModal({
  107. title: '新栏目更新中',
  108. content: '敬请期待….',
  109. showCancel: false,
  110. confirmColor: '#333333',
  111. success(res) {}
  112. })
  113. },
  114. closeDesktop() {
  115. this.setData({
  116. desktopTips: false
  117. })
  118. wx.setStorage({
  119. key: "preDesktopTime",
  120. data: new Date()
  121. })
  122. },
  123. jumpSearch() {
  124. wx.navigateTo({
  125. url: '/pages/childClassify/index?type=search',
  126. })
  127. },
  128. onUnload() {
  129. this.storeBindings.destroyStoreBindings()
  130. },
  131. })