index.js 2.7 KB

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