index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. const app = getApp()
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '首页', leftArrow: false, useBar: true },
  5. lingdang: '/image/lingdang.png',
  6. user: {},
  7. list: [],
  8. page: 0,
  9. skip: 0,
  10. limit: 5,
  11. total: 0,
  12. },
  13. // 跳转菜单
  14. tabPath(e) {
  15. let { route } = e.detail.detail;
  16. if (route) wx.redirectTo({ url: `/${route}` })
  17. },
  18. toView: function (e) {
  19. const { item } = e.currentTarget.dataset;
  20. wx.navigateTo({ url: `/pages/match/info?id=${item._id}` })
  21. },
  22. // 分页
  23. toPage: function () {
  24. const that = this;
  25. let list = that.data.list;
  26. let limit = that.data.limit;
  27. if (that.data.total > list.length) {
  28. wx.showLoading({ title: '加载中', mask: true })
  29. let page = that.data.page + 1;
  30. that.setData({ page: page })
  31. let skip = page * limit;
  32. that.setData({ skip: skip })
  33. that.watchLogin();
  34. wx.hideLoading()
  35. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  36. },
  37. /**
  38. * 生命周期函数--监听页面加载
  39. */
  40. onLoad: function (options) { },
  41. /**
  42. * 生命周期函数--监听页面初次渲染完成
  43. */
  44. onReady: function () { },
  45. /**
  46. * 生命周期函数--监听页面显示
  47. */
  48. onShow: function () {
  49. const that = this;
  50. // 监听用户是否登录
  51. that.watchLogin();
  52. },
  53. // 监听用户是否登录
  54. watchLogin: async function () {
  55. const that = this;
  56. wx.getStorage({
  57. key: 'user',
  58. success: async res => {
  59. let info = { skip: that.data.skip, limit: that.data.limit };
  60. const arr = await app.$get(`/newCourt/api/match`, { ...info });
  61. if (arr.errcode == '0') {
  62. that.setData({ list: [...that.data.list, ...arr.data] });
  63. that.setData({ total: arr.total })
  64. }
  65. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  66. },
  67. fail: async res => {
  68. wx.redirectTo({ url: '/pages/index/index' })
  69. }
  70. })
  71. },
  72. /**
  73. * 页面上拉触底事件的处理函数
  74. */
  75. /**
  76. * 生命周期函数--监听页面隐藏
  77. */
  78. onHide: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面卸载
  82. */
  83. onUnload: function () {
  84. },
  85. /**
  86. * 页面相关事件处理函数--监听用户下拉动作
  87. */
  88. onPullDownRefresh: function () {
  89. },
  90. /**
  91. * 用户点击右上角分享
  92. */
  93. onShareAppMessage: function () {
  94. }
  95. })