index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: false, name: '首页', leftArrow: false, useBar: true, tabSelectid: '0' },
  10. src: '/image/home.png',
  11. // 主体高度
  12. infoHeight: '',
  13. teamlist: [],
  14. },
  15. // 跳转菜单
  16. tabPath(e) {
  17. let { route } = e.detail.detail;
  18. if (route) wx.redirectTo({ url: `/${route}` })
  19. },
  20. //跳转详情
  21. tiao: function (e) {
  22. let id = e.currentTarget.dataset.id;
  23. wx.navigateTo({
  24. url: '/pages/list/index?id=' + id,
  25. })
  26. },
  27. //跳转循环赛
  28. xun: function (e) {
  29. let id = e.currentTarget.dataset.id;
  30. wx.navigateTo({
  31. url: '/pages/match/detail?id=' + id,
  32. })
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad: function (options) {
  38. // 计算高度
  39. this.searchHeight();
  40. // 监听用户是否登录
  41. this.watchLogin();
  42. },
  43. // 计算高度
  44. searchHeight: function () {
  45. let frameStyle = this.data.frameStyle;
  46. let client = app.globalData.client;
  47. let infoHeight = client.windowHeight;
  48. // 减去状态栏
  49. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2)
  50. // 是否减去底部菜单
  51. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  52. if (infoHeight) this.setData({ infoHeight: infoHeight })
  53. },
  54. // 监听用户是否登录
  55. watchLogin: function () {
  56. const that = this;
  57. wx.getStorage({
  58. key: 'token',
  59. success: res => {
  60. wx.request({
  61. url: `${app.globalData.publicUrl}/courtAdmin/api/match`,
  62. method: 'get',
  63. data: {},
  64. success(res) {
  65. if (res.data.errcode == 0) {
  66. for (const val of res.data.data) {
  67. if (val.status == '3') {
  68. wx.request({
  69. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule`,
  70. method: 'get',
  71. data: { match_id: val._id },
  72. success(res) {
  73. if (res.data.errcode == 0) {
  74. val.schedulelist = res.data.data;
  75. } else {
  76. wx.showToast({ title: res.data.errmsg, icon: 'none', duration: 2000 })
  77. }
  78. }
  79. })
  80. }
  81. }
  82. that.setData({ teamlist: res.data.data })
  83. } else {
  84. wx.showToast({ title: res.data.errmsg, icon: 'none', duration: 2000 })
  85. }
  86. }
  87. })
  88. },
  89. fail: res => {
  90. return wx.redirectTo({ url: '/pages/login/index', })
  91. }
  92. })
  93. },
  94. /**
  95. * 生命周期函数--监听页面初次渲染完成
  96. */
  97. onReady: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面显示
  101. */
  102. onShow: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面隐藏
  106. */
  107. onHide: function () {
  108. },
  109. /**
  110. * 生命周期函数--监听页面卸载
  111. */
  112. onUnload: function () {
  113. },
  114. /**
  115. * 页面相关事件处理函数--监听用户下拉动作
  116. */
  117. onPullDownRefresh: function () {
  118. },
  119. /**
  120. * 页面上拉触底事件的处理函数
  121. */
  122. onReachBottom: function () {
  123. },
  124. /**
  125. * 用户点击右上角分享
  126. */
  127. onShareAppMessage: function () {
  128. }
  129. })