ranking.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // pages/ranking/ranking.js
  2. const { formatDate, formatTime2 } = require('../../utils/util.js')
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. baseImgUrl: app.globalData.baseImgUrl,
  10. thumbnail: app.globalData.thumbnail,
  11. maxCreateTime: formatTime2(new Date()),
  12. statusBar: app.globalData.statusBar,
  13. pageSize: 10,
  14. pageNo: 1,
  15. isAll:false,
  16. list: [
  17. // {
  18. // "name": "小明",
  19. // "photo": "",
  20. // "score": 99.9
  21. // },
  22. // {
  23. // "name": "小红",
  24. // "photo": "",
  25. // "score": 89.9
  26. // },
  27. // {
  28. // "name": "小蓝",
  29. // "photo": "",
  30. // "score": 119.9
  31. // },
  32. // {
  33. // "name": "小蓝",
  34. // "photo": "",
  35. // "score": 119.9
  36. // },
  37. ]
  38. },
  39. /**
  40. * 生命周期函数--监听页面加载
  41. */
  42. onLoad: function (options) {
  43. },
  44. /**
  45. * 生命周期函数--监听页面初次渲染完成
  46. */
  47. onReady: function () {
  48. },
  49. /**
  50. * 生命周期函数--监听页面显示
  51. */
  52. onShow: function () {
  53. this.getLibrary();
  54. },
  55. /**
  56. * 生命周期函数--监听页面隐藏
  57. */
  58. onHide: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面卸载
  62. */
  63. onUnload: function () {
  64. },
  65. /**
  66. * 返回上一级页面
  67. */
  68. blockCtl: app.blockCtl,
  69. /**
  70. * 页面相关事件处理函数--监听用户下拉动作
  71. */
  72. onPullDownRefresh: function () {
  73. this.setData({ pageNo: 1 })
  74. this.getLibrary(res => {
  75. wx.stopPullDownRefresh()
  76. })
  77. },
  78. /**
  79. * 页面上拉触底事件的处理函数
  80. */
  81. onReachBottom: function () {
  82. const { isAll } = this.data
  83. // console.log(isAll)
  84. if (isAll) {
  85. return
  86. }
  87. this.getLibrary()
  88. },
  89. /**
  90. * 用户点击右上角分享
  91. */
  92. onShareAppMessage: function () {
  93. if (app.sharePageDefaultCtl) {
  94. return app.sharePageDefaultCtl()
  95. }
  96. },
  97. /**
  98. * 获取排名
  99. */
  100. getLibrary: function () {
  101. const postData = { fn: this.getLibrary, param: { ...arguments } }
  102. let { pageNo, pageSize, maxCreateTime,list } = this.data
  103. app.post('/api/game/v2/rankingList', {
  104. maxCreateTime: formatTime2(new Date()),
  105. pageSize,
  106. pageNo
  107. }, 0, postData).then(res => {
  108. const temp = res.data.list;
  109. const listTemp = (res => {
  110. for (let i in res) {
  111. if (res[i].name.length>5){
  112. res[i].name = res[i].name.substring(0,6)+'~';
  113. }
  114. }
  115. return res
  116. })(temp)
  117. let arr = []
  118. if (pageNo == 1) {
  119. arr = [...listTemp]
  120. } else {
  121. arr = [...list, ...listTemp]
  122. }
  123. this.setData({
  124. list: arr,
  125. pageNo: listTemp.length == pageSize ? pageNo + 1 : pageNo,
  126. isAll: listTemp.length < pageSize
  127. })
  128. })
  129. },
  130. })