- 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 为空时直接显示空态,不再发起错误请求
30 lines
795 B
JavaScript
30 lines
795 B
JavaScript
Component({
|
||
properties: {
|
||
exercise: { type: Object, value: {} },
|
||
score: { type: Number, value: 0 },
|
||
reason: { type: String, value: '' },
|
||
compact: { type: Boolean, value: false }
|
||
},
|
||
data: {
|
||
imgSrc: '',
|
||
imgError: false
|
||
},
|
||
observers: {
|
||
// 卡片用轻量静态图(~6KB),避免 91KB 的 GIF 拖慢列表
|
||
exercise(ex) {
|
||
this.setData({ imgSrc: (ex && ex.image) || '', imgError: false });
|
||
}
|
||
},
|
||
methods: {
|
||
onImgError() {
|
||
this.setData({ imgError: true });
|
||
},
|
||
onTap() {
|
||
const ex = this.data.exercise || {};
|
||
// 防御:id 缺失时绝不跳转(避免 navigate 到 /api/exercises/undefined 触发 404)
|
||
if (!ex || !ex.id) return;
|
||
this.triggerEvent('tap', { id: ex.id, exercise: ex });
|
||
}
|
||
}
|
||
});
|