index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. rankingList: [],
  24. bannerList: []
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad(options) {
  30. // 手工绑定
  31. this.storeBindings = createStoreBindings(this, {
  32. store,
  33. fields: {
  34. userInfo: 'userInfo'
  35. },
  36. actions: {
  37. setUser: 'setUser'
  38. }
  39. })
  40. // 立刻更新
  41. this.storeBindings.updateStoreBindings()
  42. this.getModelTexts()
  43. this.getReadRanking()
  44. },
  45. // 获取范文
  46. async getModelTexts() {
  47. let bannerList = await getModelTexts({
  48. grade: 'PRIMARY_FIRST_GRADE' || this.data.userInfo.grade
  49. })
  50. this.setData({
  51. bannerList
  52. })
  53. },
  54. async getReadRanking() {
  55. let rankingList = await getReadRanking()
  56. this.setData({
  57. rankingList
  58. })
  59. },
  60. async getSelfReadRanking() {
  61. let res = await getSelfReadRanking()
  62. console.log(res);
  63. },
  64. bannelEvent() {},
  65. jumpUserInfo({
  66. currentTarget
  67. }) {
  68. wx.navigateTo({
  69. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}`,
  70. })
  71. },
  72. selectType({
  73. target
  74. }) {
  75. if (target.dataset.type) {
  76. let currentType = JSON.parse(target.dataset.type)
  77. if (!currentType) {
  78. this.getSelfReadRanking()
  79. }
  80. this.setData({
  81. currentType
  82. })
  83. }
  84. },
  85. onShareAppMessage() {
  86. }
  87. })