index.js 2.9 KB

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