index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. jumpUserInfo({
  71. currentTarget
  72. }) {
  73. wx.navigateTo({
  74. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}`,
  75. })
  76. },
  77. selectType({
  78. target
  79. }) {
  80. if (target.dataset.type) {
  81. let currentType = JSON.parse(target.dataset.type)
  82. if (!currentType) {
  83. this.getSelfReadRanking()
  84. }
  85. this.setData({
  86. currentType
  87. })
  88. }
  89. },
  90. onShareAppMessage() {
  91. }
  92. })