index.js 3.1 KB

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