const api = require('../../services/api') const app = getApp() Page({ data: { user: null, items: [], streaks: {}, loading: true }, onShow() { if (!app.globalData.token) { wx.reLaunch({ url: '/pages/login/index' }); return } this.setData({ user: app.globalData.user }) this.loadItems() }, onPullDownRefresh() { this.loadItems().then(() => wx.stopPullDownRefresh()) }, async loadItems() { try { const items = await api.get('/api/checkin/items') const streaks = {} for (const item of items.filter(i => i.status === 'active')) { try { const s = await api.get('/api/checkin/streak/' + item.id); streaks[item.id] = s.streak } catch(e) {} } this.setData({ items: items.filter(i => i.status !== 'deleted'), streaks, loading: false }) } catch(e) { this.setData({ loading: false }) } }, goCreate() { wx.navigateTo({ url: '/pages/checkin/create/index' }) }, goDetail(e) { wx.navigateTo({ url: '/pages/checkin/detail/index?id=' + e.currentTarget.dataset.id }) }, goProfile() { wx.switchTab({ url: '/pages/profile/index/index' }) }, })