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 为空时直接显示空态,不再发起错误请求
This commit is contained in:
2026-07-22 15:30:28 +08:00
parent 70ff806042
commit 06bd96a473
17 changed files with 24 additions and 9 deletions

View File

@@ -21,6 +21,11 @@ Page({
const id = query.id || '';
const planId = query.planId || '';
this.setData({ statusBarHeight: app.globalData.statusBarHeight || 20, id, planId });
// 防御id 缺失直接显示空态,避免请求 /api/exercises/ 导致错乱或 404
if (!id) {
this.setData({ loading: false });
return;
}
this.load();
if (auth.isLogin()) {
favSvc.exerciseStatus(id).then((r) => {
@@ -117,6 +122,7 @@ Page({
},
onExercise(e) {
if (!e || !e.detail || !e.detail.id) return;
wx.navigateTo({ url: '/pages/detail/detail?id=' + encodeURIComponent(e.detail.id) });
},

View File

@@ -60,7 +60,7 @@
<view class="block__h eyebrow">相关推荐</view>
<scroll-view scroll-x class="hscroll">
<view class="hscroll__item" wx:for="{{related}}" wx:key="id">
<exercise-card exercise="{{item}}" compact bind:tap="onExercise" />
<exercise-card exercise="{{item}}" compact catch:tap="onExercise" />
</view>
</scroll-view>
</view>