index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. ranking: '',
  14. //2:邀新榜,3:热播榜,4:挑战pk榜
  15. rankingType: '',
  16. icon: '',
  17. podiumBoxBg: '',
  18. historyList: [],
  19. selector: {
  20. currentDay: '',
  21. next: true,
  22. previous: true,
  23. },
  24. backgroundColor: ''
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. async onLoad(options) {
  30. let historyList = await getRankedDay()
  31. this.setData({
  32. historyList,
  33. selector: {
  34. currentDay: historyList.length - 1,
  35. next: false,
  36. previous: historyList.length - 1 > 0
  37. }
  38. }, () => {
  39. this.getRankInfo(options)
  40. })
  41. },
  42. async getRankInfo(options) {
  43. let backgroundColor = options.type == '2' ? '#50AE75' : options.type == '3' ? '#FF7E6C' : '#8468FA';
  44. this.setData({
  45. rankingType: options.type,
  46. icon: options.type == '2' ? '/static/yx.png' : options.type == '3' ? '/static/play.png' : '/static/win.png',
  47. podiumBoxBg: options.type == '2' ? 'invitation' : options.type == '3' ? 'hot' : 'pk',
  48. backgroundColor
  49. })
  50. wx.setNavigationBarColor({
  51. frontColor: '#ffffff',
  52. backgroundColor
  53. })
  54. let {
  55. userList,
  56. ranking
  57. } = await getRankingData({
  58. type: options.type,
  59. day: this.data.historyList[this.data.selector.currentDay]
  60. })
  61. this.setData({
  62. userList,
  63. ranking
  64. })
  65. },
  66. switchType({
  67. target
  68. }) {
  69. let rankingType = target.dataset.type
  70. if (rankingType && rankingType != this.data.rankingType) {
  71. this.getRankInfo({
  72. type: rankingType
  73. })
  74. }
  75. },
  76. bindDateChange({
  77. currentTarget
  78. }) {
  79. let type = currentTarget.dataset.type
  80. let currentDay = this.data.selector.currentDay
  81. if (type == 'next' && currentDay < this.data.historyList.length - 1) {
  82. currentDay = ++currentDay
  83. } else if (type == 'previous' && currentDay > 0) {
  84. currentDay = --currentDay
  85. }
  86. this.setData({
  87. selector: {
  88. currentDay,
  89. next: currentDay < this.data.historyList.length - 1,
  90. previous: currentDay > 0
  91. }
  92. })
  93. this.getRankInfo({
  94. type: this.data.rankingType
  95. })
  96. },
  97. jumpIndex() {
  98. wx.switchTab({
  99. url: '/pages/index/index',
  100. })
  101. },
  102. jumpUserInfo({
  103. currentTarget
  104. }) {
  105. if (!currentTarget.dataset.uid) {
  106. return
  107. }
  108. wx.navigateTo({
  109. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=${this.data.rankingType==4?'pk':'user'}`,
  110. })
  111. },
  112. onShareAppMessage() {
  113. // #if MP
  114. return {
  115. title: this.data.rankingType == 3 ? '我要上热门,就差你的一个赞,快来帮帮我吧!' : '这个小程序太赞了!孩子朗读能力蹭蹭上涨,推荐你试试!',
  116. path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
  117. imageUrl: this.data.rankingType == 3 ? '/static/375-300-3.jpg' : '/static/375-300-2.jpg'
  118. }
  119. // #elif ANDROID
  120. return {
  121. title: this.data.rankingType == 3 ? '我要上热门,就差你的一个赞,快来帮帮我吧!' : '这个小程序太赞了!孩子朗读能力蹭蹭上涨,推荐你试试!',
  122. userName: 'gh_50f61361ad1d',
  123. path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
  124. imagePath: this.data.rankingType == 3 ? '/static/375-300-3.jpg' : '/static/375-300-2.jpg',
  125. webpageUrl: 'http://www.efunbox.cn',
  126. withShareTicket: true,
  127. miniprogramType: 1,
  128. scene: 0,
  129. }
  130. // #endif
  131. }
  132. })