index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. Page({
  16. /**
  17. * 页面的初始数据
  18. */
  19. data: {
  20. list: [],
  21. // true是人气榜,false是参赛作品
  22. currentType: true,
  23. activityUserList: [],
  24. bannerList: [],
  25. myActivityUser: {},
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad(options) {
  31. // 手工绑定
  32. this.storeBindings = createStoreBindings(this, {
  33. store,
  34. fields: {
  35. userInfo: 'userInfo'
  36. },
  37. actions: {
  38. setUser: 'setUser'
  39. }
  40. })
  41. // 立刻更新
  42. this.storeBindings.updateStoreBindings()
  43. this.getModelTexts()
  44. this.getReadRanking()
  45. },
  46. // 获取范文
  47. async getModelTexts() {
  48. let bannerList = await getModelTexts({
  49. grade: 'PRIMARY_FIRST_GRADE' || this.data.userInfo.grade
  50. })
  51. this.setData({
  52. bannerList
  53. })
  54. },
  55. async getReadRanking() {
  56. let {
  57. activityUserList,
  58. myActivityUser
  59. } = await getReadRanking()
  60. this.setData({
  61. activityUserList,
  62. myActivityUser
  63. })
  64. },
  65. async getSelfReadRanking() {
  66. let res = await getSelfReadRanking()
  67. console.log(res);
  68. },
  69. bannelEvent({
  70. target
  71. }) {
  72. wx.navigateTo({
  73. url: `/pages/reading/index?videoId=${target.dataset.id}&readingType=readMatch`
  74. })
  75. },
  76. jumpUserInfo({
  77. currentTarget
  78. }) {
  79. wx.navigateTo({
  80. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}`,
  81. })
  82. },
  83. selectType({
  84. target
  85. }) {
  86. if (target.dataset.type) {
  87. let currentType = JSON.parse(target.dataset.type)
  88. if (!currentType) {
  89. this.getSelfReadRanking()
  90. }
  91. this.setData({
  92. currentType
  93. })
  94. }
  95. },
  96. onShareAppMessage() {
  97. }
  98. })