index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import {
  2. getSelfRead
  3. } from '~/api/user'
  4. import {
  5. getModelTexts,
  6. getReadRanking,
  7. getSelfReadRanking
  8. } from '~/api/global'
  9. import {
  10. store
  11. } from '~/store/index'
  12. import {
  13. createStoreBindings
  14. } from 'mobx-miniprogram-bindings'
  15. import share from '~/mixins/share'
  16. Page({
  17. behaviors: [share],
  18. /**
  19. * 页面的初始数据
  20. */
  21. data: {
  22. list: [],
  23. // true是人气榜,false是参赛作品
  24. currentType: true,
  25. activityUserList: [],
  26. bannerList: [],
  27. myActivityUser: {},
  28. explain: ''
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad(options) {
  34. this.getLocUserInfo()
  35. if (Object.keys(this.data.userInfo).length > 0) {
  36. this.reload()
  37. } else {
  38. getApp().callBack = (res) => {
  39. this.getLocUserInfo()
  40. this.reload()
  41. }
  42. }
  43. },
  44. getLocUserInfo() {
  45. this.storeBindings = createStoreBindings(this, {
  46. store,
  47. fields: {
  48. userInfo: 'userInfo'
  49. },
  50. actions: {
  51. setUser: 'setUser'
  52. }
  53. })
  54. this.storeBindings.updateStoreBindings()
  55. },
  56. reload() {
  57. this.getModelTexts()
  58. this.getReadRanking()
  59. },
  60. // 获取范文
  61. async getModelTexts() {
  62. let bannerList = await getModelTexts({
  63. grade: this.data.userInfo.grade
  64. })
  65. this.setData({
  66. bannerList
  67. })
  68. },
  69. async getReadRanking() {
  70. let {
  71. activityUserList,
  72. myActivityUser,
  73. activity
  74. } = await getReadRanking()
  75. this.setData({
  76. activityUserList,
  77. myActivityUser,
  78. explain: activity.explain
  79. })
  80. },
  81. async getSelfReadRanking() {
  82. let list = await getSelfReadRanking()
  83. this.setData({
  84. list
  85. })
  86. },
  87. bannelEvent({
  88. target
  89. }) {
  90. wx.navigateTo({
  91. url: `/pages/reading/index?videoId=${target.dataset.id}&readingType=readMatch`
  92. })
  93. },
  94. jumpUserInfo({
  95. currentTarget
  96. }) {
  97. wx.navigateTo({
  98. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}`,
  99. })
  100. },
  101. jumpIntro() {
  102. wx.navigateTo({
  103. url: `/pages/rankIntro/index?title=活动规则&img=${this.data.explain}`,
  104. })
  105. },
  106. selectType({
  107. target
  108. }) {
  109. if (target.dataset.type) {
  110. let currentType = JSON.parse(target.dataset.type)
  111. if (!currentType) {
  112. this.getSelfReadRanking()
  113. }
  114. this.setData({
  115. currentType
  116. })
  117. }
  118. },
  119. onShareAppMessage({
  120. from,
  121. target
  122. }) {
  123. if (from == 'menu') {
  124. return {
  125. title: '这个小程序太赞了!孩子朗读能力蹭蹭上涨,推荐你试试!',
  126. path: `/pages/match/index?uid=${wx.getStorageSync('uid')}`,
  127. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-1.jpg'
  128. }
  129. }
  130. },
  131. })