fix(miniprogram): F1-5b MP-4 coach-detail id 边界保护 (W1)
走查发现 pages/coach-detail 在某种入口下 data.coachId 为 undefined /
空字符串,导致后端 /api/xcx/coaches/undefined 请求 422,体现为助教
详情页加载失败。后端日志多次出现该 422 记录。
变更:
- apps/miniprogram/miniprogram/pages/coach-detail/coach-detail.ts:247
onLoad 加 guard(参考 coach-service-records.ts 同款模式):
- 检查 options.id 非空 + 非字面 'undefined'
- 数字格式校验 (^\d+$)
- 失败时 wx.showToast("缺少助教标识") + 1s 后 navigateBack
(失败时 fallback switchTab board-finance)
双口径验证(weixin-devtools-mcp):
- 缺参入口 /pages/coach-detail/coach-detail(无 query) → guard 触发,
toast 显示 + 退回 board-finance,不再发出 422 请求
- 正常入口 ?id=3148987180059141 → 通过 guard,pageState=normal 加载成功
§3.3 标"sandbox 无关",4b 跳过(权限/参数路径与 sandbox 无关联)。
审计:docs/audit/changes/2026-05-05__wave1_f1_5b_mp4_coach_detail_id_guard.md
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -244,10 +244,22 @@ Page({
|
||||
_longPressed: false,
|
||||
_animTimer: null as ReturnType<typeof setTimeout> | null,
|
||||
|
||||
// CHANGE 2026-05-05 | F1-5b MP-4: 补 id 边界保护,
|
||||
// 防止 options.id 缺失或为字符串 'undefined' 时调用 /api/xcx/coaches/undefined 触发 422
|
||||
onLoad(options: { id?: string }) {
|
||||
const id = options?.id || ''
|
||||
this.setData({ coachId: id })
|
||||
this.loadData(id)
|
||||
const raw = options?.id
|
||||
const idStr = (raw && raw !== 'undefined') ? String(raw) : ''
|
||||
if (!idStr || !/^\d+$/.test(idStr)) {
|
||||
wx.showToast({ title: '缺少助教标识', icon: 'none' })
|
||||
setTimeout(() => {
|
||||
wx.navigateBack({
|
||||
fail: () => wx.switchTab({ url: '/pages/board-finance/board-finance' }),
|
||||
})
|
||||
}, 1000)
|
||||
return
|
||||
}
|
||||
this.setData({ coachId: idStr })
|
||||
this.loadData(idStr)
|
||||
},
|
||||
|
||||
onHide() {
|
||||
|
||||
Reference in New Issue
Block a user