index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. categoryList: []
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onShow() {
  33. if (typeof this.getTabBar === 'function') {
  34. this.getTabBar().setData({
  35. selected: 1
  36. })
  37. }
  38. getApp().callBack = (res) => {
  39. this.getLocUserInfo()
  40. this.resetData()
  41. }
  42. // 1023 安卓系统桌面图标,1104微信聊天主界面下拉,「我的小程序」栏(基础库2.2.4-2.29.0版本废弃,2.29.1版本起生效)
  43. let {
  44. isIOS,
  45. scene
  46. } = app.globalData
  47. this.setData({
  48. desktopTips: isIOS ? scene != 1104 : scene != 1023
  49. })
  50. console.log(isIOS ? scene != 1104 : scene != 1023);
  51. let uid = wx.getStorageSync('uid')
  52. /* if (uid) {
  53. this.getLocUserInfo()
  54. this.resetData()
  55. } else {
  56. getApp().callBack = (res) => {
  57. this.getLocUserInfo()
  58. this.resetData()
  59. }
  60. } */
  61. },
  62. onUnload() {
  63. this.storeBindings.destroyStoreBindings()
  64. },
  65. async getLocUserInfo() {
  66. this.storeBindings = createStoreBindings(this, {
  67. store,
  68. fields: {
  69. userInfo: 'userInfo'
  70. },
  71. })
  72. this.storeBindings.updateStoreBindings()
  73. },
  74. loadMore() {
  75. if (this.data.currentType == '1') {
  76. this.getData(getHotrecommendList, {
  77. grade: this.data.userInfo.grade
  78. })
  79. } else if (this.data.currentType == '2') {
  80. this.getData(getAuthorityList, {
  81. grade: this.data.userInfo.grade
  82. })
  83. }
  84. this.getCategoryList()
  85. },
  86. jumpChildClassify({
  87. currentTarget
  88. }) {
  89. let firstInfo = currentTarget.dataset.item
  90. let params = firstInfo.childList.length > 0 ? `list=${encodeURIComponent(JSON.stringify(firstInfo.childList))}` : `id=${firstInfo.id}`
  91. wx.navigateTo({
  92. url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&${params}`,
  93. })
  94. },
  95. jumpSearch() {
  96. wx.navigateTo({
  97. url: '/pages/childClassify/index?type=search',
  98. })
  99. },
  100. /**
  101. * 监听页面滚动事件
  102. */
  103. onPageScroll(e) {
  104. if (e.scrollTop >= 103 && !this.data.isFixed) {
  105. this.setData({
  106. isFixed: true
  107. })
  108. } else if (e.scrollTop < 103 && this.data.isFixed) {
  109. this.setData({
  110. isFixed: false
  111. })
  112. }
  113. },
  114. onReachBottom() {
  115. this.loadMore()
  116. },
  117. async getCategoryList() {
  118. let grade = this.data.userInfo.grade
  119. let categoryList = await getCategoryList({
  120. grade
  121. })
  122. this.setData({
  123. categoryList
  124. })
  125. },
  126. selectType({
  127. target
  128. }) {
  129. if (target.dataset.type) {
  130. this.setData({
  131. currentType: target.dataset.type
  132. })
  133. if (target.dataset.type != '3') {
  134. this.resetData()
  135. this.selectComponent('#worksList').resetAudio()
  136. }
  137. }
  138. },
  139. })