index.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {
  2. getRankingData,
  3. getRankedDay
  4. } from '~/api/global'
  5. import event from '~/mixins/event'
  6. Page({
  7. behaviors: [event],
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. userList: [],
  13. //2:邀新榜,3:热播榜,4:挑战pk榜
  14. rankingType: '',
  15. icon: '',
  16. podiumBoxBg: '',
  17. historyList: []
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. async onLoad(options) {
  23. let historyList = await getRankedDay()
  24. console.log(historyList);
  25. this.setData({
  26. historyList
  27. },()=>{
  28. this.getRankInfo(options)
  29. })
  30. },
  31. async getRankInfo(options) {
  32. this.setData({
  33. rankingType: options.type,
  34. icon: options.type == '2' ? '/static/yx.png' : options.type == '3' ? '/static/play.png' : '/static/win.png',
  35. podiumBoxBg: options.type == '2' ? 'invitation' : options.type == '3' ? 'hot' : 'pk',
  36. })
  37. wx.setNavigationBarColor({
  38. frontColor: '#ffffff',
  39. backgroundColor: options.type == '2' ? '#50AE75' : options.type == '3' ? '#FF7E6C' : '#8468FA',
  40. })
  41. console.log(this.data.historyList);
  42. let {
  43. userList,
  44. } = await getRankingData({
  45. type: options.type,
  46. day: this.data.historyList[this.data.historyList.length - 1]
  47. })
  48. this.setData({
  49. userList,
  50. })
  51. },
  52. switchType({
  53. target
  54. }) {
  55. let rankingType = target.dataset.type
  56. if (rankingType && rankingType != this.data.rankingType) {
  57. this.getRankInfo({
  58. type: rankingType
  59. })
  60. }
  61. },
  62. jumpIndex() {
  63. wx.switchTab({
  64. url: '/pages/index/index',
  65. })
  66. },
  67. jumpUserInfo({
  68. currentTarget
  69. }) {
  70. if (!currentTarget.dataset.uid) {
  71. return
  72. }
  73. wx.navigateTo({
  74. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=${this.data.rankingType==4?'pk':'user'}`,
  75. })
  76. },
  77. onShareAppMessage() {
  78. return {
  79. title: this.data.rankingType == 3 ? '我要上热门,就差你的一个赞,快来帮帮我吧!' : '这个小程序太赞了!孩子朗读能力蹭蹭上涨,推荐你试试!',
  80. path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
  81. imageUrl: this.data.rankingType == 3 ? 'http://reader-wx.ai160.com/images/reader/v3/375-300-3.jpg' : 'http://reader-wx.ai160.com/images/reader/v3/375-300-2.jpg'
  82. }
  83. }
  84. })