index.js 2.8 KB

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