rank.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // pages/rank/rank.js
  2. const app = getApp();
  3. var host = app.globalData.host;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. datas: {},
  10. userInfo: {}
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad() {
  16. wx.showNavigationBarLoading()
  17. /**获取token */
  18. wx.getStorage({
  19. key: 'userInfo',
  20. success: res => {
  21. if (res.data) {
  22. this.setData({
  23. userInfo: res.data
  24. })
  25. this.getData();
  26. } else {
  27. wx.switchTab({
  28. url: '../user/user',
  29. })
  30. }
  31. },
  32. fail: error => {
  33. //跳转到登陆页面
  34. wx.switchTab({
  35. url: '../user/user',
  36. })
  37. }
  38. })
  39. },
  40. onShow() {
  41. if (!this.data.userInfo.token) {
  42. this.onLoad()
  43. } else {
  44. console.log(233)
  45. wx.showNavigationBarLoading()
  46. this.getData()
  47. }
  48. },
  49. getData() {
  50. wx.request({
  51. url: host + '/api/wx/group/rank/list',
  52. header: {
  53. 'Authorization': this.data.userInfo.token
  54. },
  55. success: res => {
  56. console.log(res)
  57. this.setData({
  58. datas: res.data.data
  59. })
  60. wx.setNavigationBarTitle({
  61. title: res.data.data.match.name,
  62. })
  63. wx.hideNavigationBarLoading()
  64. },
  65. fail: error => {
  66. //跳转到登陆页面
  67. wx.switchTab({
  68. url: '../user/user',
  69. })
  70. }
  71. })
  72. },
  73. /**
  74. * 生命周期函数--监听页面初次渲染完成
  75. */
  76. onReady: function () {
  77. },
  78. /**
  79. * 生命周期函数--监听页面显示
  80. */
  81. /**
  82. * 生命周期函数--监听页面隐藏
  83. */
  84. onHide: function () {
  85. },
  86. /**
  87. * 生命周期函数--监听页面卸载
  88. */
  89. onUnload: function () {
  90. },
  91. /**
  92. * 页面相关事件处理函数--监听用户下拉动作
  93. */
  94. onPullDownRefresh: function () {
  95. },
  96. /**
  97. * 页面上拉触底事件的处理函数
  98. */
  99. onReachBottom: function () {
  100. },
  101. /**
  102. * 用户点击右上角分享
  103. */
  104. onShareAppMessage: function () {
  105. }
  106. })