const app = getApp(); const svc = require('../../services/exercise'); Page({ data: { statusBarHeight: 20, stats: null, bodyParts: [], equipment: [], featured: [], collections: [], loading: true, quickEntries: [ { key: 'recommend', label: '智能推荐', emoji: '✨', url: '/pages/recommend/recommend' }, { key: 'bodyPart', label: '按部位', emoji: '💪', url: '/pages/category/category?dimension=bodyPart' }, { key: 'equipment', label: '按器械', emoji: '🏋️', url: '/pages/category/category?dimension=equipment' }, { key: 'official', label: '官方计划', emoji: '📋', url: '/pages/collection/collection' }, { key: 'myPlans', label: '我的计划', emoji: '🗂️', url: '/pages/my-plans/my-plans' }, { key: 'mine', label: '我的', emoji: '👤', url: '/pages/profile/profile' } ] }, onLoad() { this.setData({ statusBarHeight: app.globalData.statusBarHeight || 20 }); this.loadData(); }, loadData() { this.setData({ loading: true }); Promise.all([ svc.getStats().catch(() => null), svc.listExercises({ pageSize: 8 }).catch(() => ({ items: [] })), svc.listCollections().catch(() => []) ]).then(([stats, list, collections]) => { this.setData({ stats, bodyParts: (stats && stats.bodyParts) || [], equipment: (stats && stats.equipment) || [], featured: (list && list.items) || [], collections: collections || [], loading: false }); }).catch(() => { this.setData({ loading: false }); }); }, goRecommend() { wx.navigateTo({ url: '/pages/recommend/recommend' }); }, onQuick(e) { wx.navigateTo({ url: e.currentTarget.dataset.url }); }, onSearch() { wx.navigateTo({ url: '/pages/search/search' }); }, onScanBodyPart(e) { const { value, label } = e.currentTarget.dataset; wx.navigateTo({ url: '/pages/category/category?dimension=bodyPart&value=' + encodeURIComponent(value) + '&title=' + encodeURIComponent(label) }); }, onScanEquipment(e) { const { value, label } = e.currentTarget.dataset; wx.navigateTo({ url: '/pages/category/category?dimension=equipment&value=' + encodeURIComponent(value) + '&title=' + encodeURIComponent(label) }); }, onCollection(e) { wx.navigateTo({ url: '/pages/collection-detail/collection-detail?slug=' + encodeURIComponent(e.currentTarget.dataset.slug) }); }, onExercise(e) { wx.navigateTo({ url: '/pages/detail/detail?id=' + encodeURIComponent(e.detail.id) }); } });