index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. const app = getApp()
  2. import {
  3. getHotrecommendList,
  4. getAuthorityList,
  5. getCategoryList
  6. } from "~/api/works"
  7. import reachBottom from '~/mixins/reachBottom'
  8. import share from '~/mixins/share'
  9. import {
  10. createStoreBindings
  11. } from 'mobx-miniprogram-bindings'
  12. import {
  13. store
  14. } from '~/store/index'
  15. Page({
  16. behaviors: [reachBottom, share],
  17. /**
  18. * 页面的初始数据
  19. */
  20. data: {
  21. navBarHeight: app.globalData.navBarHeight,
  22. background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
  23. currentType: '1',
  24. // 控制一级分类是否固定
  25. isFixed: false,
  26. desktopTips: false,
  27. isIOS: false,
  28. categoryList: []
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onShow() {
  34. if (typeof this.getTabBar === 'function') {
  35. this.getTabBar().setData({
  36. selected: 1
  37. })
  38. }
  39. let uid = wx.getStorageSync('uid')
  40. if (uid) {
  41. getApp().callBack = (res) => {
  42. this.getLocUserInfo()
  43. this.resetData()
  44. }
  45. } else {
  46. getApp().callBack = (res) => {
  47. this.getLocUserInfo()
  48. this.resetData()
  49. }
  50. }
  51. /* getApp().callBack = (res) => {
  52. this.getLocUserInfo()
  53. this.resetData()
  54. } */
  55. // 1023 安卓系统桌面图标,1104微信聊天主界面下拉,「我的小程序」栏(基础库2.2.4-2.29.0版本废弃,2.29.1版本起生效)
  56. let {
  57. isIOS,
  58. scene
  59. } = app.globalData
  60. let desktopTips = isIOS ? scene != 1104 : scene != 1023
  61. if (desktopTips) {
  62. this.setData({
  63. isIOS,
  64. desktopTips
  65. })
  66. setTimeout(() => {
  67. this.setData({
  68. desktopTips: false
  69. })
  70. }, 6000)
  71. }
  72. },
  73. onUnload() {
  74. this.storeBindings.destroyStoreBindings()
  75. },
  76. async getLocUserInfo() {
  77. this.storeBindings = createStoreBindings(this, {
  78. store,
  79. fields: {
  80. userInfo: 'userInfo'
  81. },
  82. })
  83. this.storeBindings.updateStoreBindings()
  84. },
  85. loadMore() {
  86. if (this.data.currentType == '1') {
  87. this.getData(getHotrecommendList, {
  88. grade: this.data.userInfo.grade
  89. })
  90. } else if (this.data.currentType == '2') {
  91. this.getData(getAuthorityList, {
  92. grade: this.data.userInfo.grade
  93. })
  94. }
  95. this.getCategoryList()
  96. },
  97. jumpChildClassify({
  98. currentTarget
  99. }) {
  100. let firstInfo = currentTarget.dataset.item
  101. let params = firstInfo.childList.length > 0 ? `list=${encodeURIComponent(JSON.stringify(firstInfo.childList))}` : `id=${firstInfo.id}`
  102. wx.navigateTo({
  103. url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&${params}`,
  104. })
  105. },
  106. jumpSearch() {
  107. wx.navigateTo({
  108. url: '/pages/childClassify/index?type=search',
  109. })
  110. },
  111. /**
  112. * 监听页面滚动事件
  113. */
  114. onPageScroll(e) {
  115. if (e.scrollTop >= 103 && !this.data.isFixed) {
  116. this.setData({
  117. isFixed: true
  118. })
  119. } else if (e.scrollTop < 103 && this.data.isFixed) {
  120. this.setData({
  121. isFixed: false
  122. })
  123. }
  124. },
  125. onReachBottom() {
  126. this.loadMore()
  127. },
  128. async getCategoryList() {
  129. let grade = this.data.userInfo.grade
  130. let categoryList = await getCategoryList({
  131. grade
  132. })
  133. this.setData({
  134. categoryList
  135. })
  136. },
  137. selectType({
  138. target
  139. }) {
  140. if (target.dataset.type) {
  141. this.setData({
  142. currentType: target.dataset.type
  143. })
  144. if (target.dataset.type != '3') {
  145. this.resetData()
  146. this.selectComponent('#worksList').resetAudio()
  147. }
  148. }
  149. },
  150. closeDesktop() {
  151. this.setData({
  152. desktopTips: false
  153. })
  154. }
  155. })