history.js 2.5 KB

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