Files
wm 06bd96a473 fix: 修复动作卡片点击双触发导致跳 404
- 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 为空时直接显示空态,不再发起错误请求
2026-07-22 15:30:28 +08:00

30 lines
795 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 });
}
}
});