const app = getApp() Page({ data: { frameStyle: { useTop: true, name: '话题', leftArrow: false, useBar: true }, searchInfo: {}, list: [{ id: '1', title: '【单项】2022年运城市青少年羽毛球比赛', create_time: '2022-09-02', brief: '【单项】2022年运城市青少年羽毛球比赛就要开始了,在你心中的最强王者会是谁?' }, { id: '2', title: '【单项】2022年运城市青少年羽毛球比赛', create_time: '2022-09-02', brief: '【单项】2022年运城市青少年羽毛球比赛就要开始了,在你心中的最强王者会是谁?' }], //分页 skip: 0, page: 0, limit: 5, }, // 跳转菜单 tabPath(e) { let { route } = e.detail.detail; if (route) wx.redirectTo({ url: `/${route}` }) }, toJoin(e) { let { id } = e.currentTarget.dataset; wx.navigateTo({ url: `/pages/topic/info?id=${id}` }) }, // 查询 search: function (e) { const that = this; that.setData({ 'searchInfo.title': e.detail.value }); that.watchLogin() }, //分页 toPage: function () { const that = this; let page = that.data.page + 1; that.setData({ page }) let skip = page * that.data.limit; that.setData({ skip }) that.watchLogin(); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, // 监听用户是否登录 watchLogin: async function () { const that = this; let searchInfo = that.data.searchInfo; wx.getStorage({ key: 'user', success: async (res) => { let info = { skip: that.data.skip, limit: that.data.limit }; if (searchInfo && searchInfo.title) info.title = searchInfo.title; // const arr = await app.$get(`/newCourt/api/topic`, { ...info }); // if (arr.errcode == '0') { that.setData({ list: [...that.data.list, ...arr.data] }) } // else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) } }, // fail: async (res) => { // wx.redirectTo({ url: '/pages/index/index' }); // }, }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { const that = this; // 监听用户是否登录 that.watchLogin(); }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })