- 8 个页面 exercise-card 由 bind:tap 改为 catch:tap,拦截原生 tap 冒泡 避免一次点击被『自定义事件 + 原生冒泡』触发两次, 第二次 e.detail 无 id → navigateTo detail?id=undefined → 404 - 所有 onExercise 顶部加 id 守卫,无 id 直接 return - exercise-card 点击前校验 exercise.id,缺失不触发 - detail onLoad 的 id 为空时直接显示空态,不再发起错误请求
90 lines
2.6 KiB
JavaScript
90 lines
2.6 KiB
JavaScript
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) {
|
|
if (!e || !e.detail || !e.detail.id) return;
|
|
wx.navigateTo({
|
|
url: '/pages/detail/detail?id=' + encodeURIComponent(e.detail.id)
|
|
});
|
|
}
|
|
});
|