index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: false, name: '首页', leftArrow: false, useBar: true },
  8. // 主体高度
  9. infoHeight: '',
  10. // 首页背景
  11. homeBg: '/image/home_1.png',
  12. // 比赛列表
  13. list: []
  14. },
  15. back: function () {
  16. wx.navigateBack({ url: '/pages/home/index' })
  17. },
  18. tabPath: function (e) {
  19. let { route } = e.detail.detail;
  20. if (route) wx.redirectTo({ url: `/${route}` })
  21. },
  22. // 查看比赛详情
  23. toView: function (e) {
  24. const { id } = e.currentTarget.dataset;
  25. wx.navigateTo({ url: `/pages/match/info?id=${id}` })
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. // 计算高度
  32. this.searchHeight();
  33. // 监听用户是否登录
  34. this.watchLogin();
  35. },
  36. // 监听用户是否登录
  37. watchLogin: function () {
  38. const that = this;
  39. wx.getStorage({
  40. key: 'token',
  41. success: res => {
  42. wx.request({
  43. url: `${app.globalData.publicUrl}/courtAdmin/api/match`, //接口地址
  44. method: 'get',
  45. data: {},
  46. success(res) {
  47. if (res.data.errcode == 0) {
  48. that.setData({ list: res.data.data })
  49. } else {
  50. wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
  51. }
  52. }
  53. })
  54. },
  55. fail: res => {
  56. wx.redirectTo({ url: '/pages/index/index', })
  57. }
  58. })
  59. },
  60. // 计算高度
  61. searchHeight: function () {
  62. let frameStyle = this.data.frameStyle;
  63. let client = app.globalData.client;
  64. let infoHeight = client.windowHeight;
  65. // 是否去掉状态栏
  66. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  67. // 是否减去底部菜单
  68. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  69. if (infoHeight) this.setData({ infoHeight: infoHeight })
  70. },
  71. /**
  72. * 生命周期函数--监听页面初次渲染完成
  73. */
  74. onReady: function () {
  75. },
  76. /**
  77. * 生命周期函数--监听页面显示
  78. */
  79. onShow: function () {
  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. })