From 54a5ae858d5b5233f3a57ed3eb67a540940d66ae Mon Sep 17 00:00:00 2001 From: wm <2747639460@qq.com> Date: Wed, 22 Jul 2026 23:58:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(plan-detail):=20=E5=A2=9E=E5=8A=A0=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD/=E9=94=99=E8=AF=AF/=E9=87=8D=E8=AF=95/=E6=9C=AA?= =?UTF-8?q?=E6=89=BE=E5=88=B0=E5=9B=9B=E6=80=81=EF=BC=8C=E6=9D=9C=E7=BB=9D?= =?UTF-8?q?=E9=9D=99=E9=BB=98=E7=A9=BA=E7=99=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 此前详情页请求失败时仅 setData(loading:false),plan 仍为 null, 整页只显示一行小字,用户感知为「空白」且无法定位原因。 - 现明确区分 loading / error(带重试按钮) / not-found 三种空态; request 失败时按 statusCode 给具体提示(401 登录失效 / 404 未找到 / 其他网络错误)。 - onLoad 对 getApp().globalData 取值加防御;缺失 id 直接报错不发起请求。 --- miniprogram/pages/plan-detail/plan-detail.js | 35 +++++++++++++++---- .../pages/plan-detail/plan-detail.wxml | 8 ++++- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/miniprogram/pages/plan-detail/plan-detail.js b/miniprogram/pages/plan-detail/plan-detail.js index fb4fab1..49fcbec 100644 --- a/miniprogram/pages/plan-detail/plan-detail.js +++ b/miniprogram/pages/plan-detail/plan-detail.js @@ -8,18 +8,30 @@ Page({ id: '', plan: null, exercises: [], - loading: true + loading: true, + error: false, + errorMsg: '' }, onLoad(query) { const id = query.id || ''; - this.setData({ statusBarHeight: app.globalData.statusBarHeight || 20, id }); + const h = (app && app.globalData && app.globalData.statusBarHeight) || 20; + this.setData({ statusBarHeight: h, id }); this.load(); }, load() { - this.setData({ loading: true }); - planSvc.get(this.data.id).then((plan) => { + const id = this.data.id; + if (!id) { + this.setData({ loading: false, error: true, errorMsg: '缺少计划标识,无法打开' }); + return; + } + this.setData({ loading: true, error: false }); + planSvc.get(id).then((plan) => { + if (!plan || !plan.id) { + this.setData({ loading: false, error: true, errorMsg: '未找到该计划' }); + return; + } const raw = plan && plan.updatedAt; const updatedAtText = typeof raw === 'string' ? raw.slice(0, 10) @@ -27,13 +39,22 @@ Page({ this.setData({ plan: { ...plan, updatedAtText, icon: iconName(plan.emoji) }, exercises: (plan && plan.exercises) || [], - loading: false + loading: false, + error: false }); - }).catch(() => { - this.setData({ loading: false }); + }).catch((err) => { + const status = err && err.statusCode; + const msg = status === 404 + ? '未找到该计划' + : (status === 401 ? '登录已失效,请重新登录' : '加载失败,请检查网络后重试'); + this.setData({ loading: false, error: true, errorMsg: msg }); }); }, + onRetry() { + this.load(); + }, + onRemoveExercise(e) { const exerciseId = e.currentTarget.dataset.id; planSvc.removeExercise(this.data.id, exerciseId).then(() => { diff --git a/miniprogram/pages/plan-detail/plan-detail.wxml b/miniprogram/pages/plan-detail/plan-detail.wxml index 9e40023..b77c862 100644 --- a/miniprogram/pages/plan-detail/plan-detail.wxml +++ b/miniprogram/pages/plan-detail/plan-detail.wxml @@ -35,5 +35,11 @@ - {{ loading ? '加载中…' : '未找到该计划' }} + 加载中… + + + {{errorMsg || '加载失败'}} + 重试 + + 未找到该计划