From 96c92f2cfbd227500a5be4d7331a0414224a676c Mon Sep 17 00:00:00 2001 From: Blizzard Date: Fri, 31 Jul 2026 09:03:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(fe):=20=E4=BB=8A=E6=97=A5=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=AE=8C=E6=88=90=E8=B5=B0=E8=AE=B0=E5=BD=95=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=EF=BC=8C=E5=8E=BB=E6=8E=89=E3=80=8C=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 去掉首页「全部完成」按钮,避免一键刷完不留记录 - 勾选带记录类型的任务 → 跳记录表单,保存成功后才回填任务完成, 返回首页 onShow 自动刷新任务勾选 + 最近记录(带 taskId 传参) - 只对未完成任务传 taskId,避免重复完成把已完成任务 toggle 回去 - 无记录类型的任务(如遛狗)仍直接勾选完成 Co-Authored-By: Claude Opus 5 --- pets-fe/pages/addrecord/addrecord.js | 8 +++++++- pets-fe/pages/home/home.js | 16 ++++++---------- pets-fe/pages/home/home.wxml | 1 - 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pets-fe/pages/addrecord/addrecord.js b/pets-fe/pages/addrecord/addrecord.js index 5b6843e..bd7d4f6 100644 --- a/pets-fe/pages/addrecord/addrecord.js +++ b/pets-fe/pages/addrecord/addrecord.js @@ -41,6 +41,8 @@ Page({ }, onLoad(q) { const code = (q && q.type) || ''; + // 从首页「今日任务」勾选进来会带 taskId:这一笔记录保存后要把那条任务标完成 + this.taskId = (q && q.taskId) || ''; const d = today(); this.setData({ code, date: d, dateLabel: fmtDate(d) }); store @@ -151,9 +153,13 @@ Page({ this.setData({ saving: true }); api .createRecord(id, this.buildBody()) + .then(() => { + // 从任务勾选进来的:记录存好后把那条任务标完成(失败不影响记录已保存) + if (this.taskId) return api.toggleTask(this.taskId).catch(() => {}); + }) .then(() => { this.setData({ saving: false }); - wx.showToast({ title: '已记录', icon: 'success' }); + wx.showToast({ title: this.taskId ? '已完成' : '已记录', icon: 'success' }); setTimeout(() => wx.navigateBack(), 600); }) .catch((e) => { diff --git a/pets-fe/pages/home/home.js b/pets-fe/pages/home/home.js index ee6953c..36b649a 100644 --- a/pets-fe/pages/home/home.js +++ b/pets-fe/pages/home/home.js @@ -172,11 +172,15 @@ Page({ onTapTask(e) { const i = e.currentTarget.dataset.index; const t = this.data.tasks[i]; - // 任务关联了记录类型就直接去记那一笔 + // 任务关联了记录类型:去记那一笔。未完成的带上 taskId, + // 在记录页保存成功后才回填这条任务完成(onShow 回来自动刷新任务+最近记录) if (t.sheet) { - wx.navigateTo({ url: '/pages/addrecord/addrecord?type=' + t.sheet }); + let url = '/pages/addrecord/addrecord?type=' + t.sheet; + if (!t.done) url += '&taskId=' + t.id; + wx.navigateTo({ url }); return; } + // 没有关联记录类型的任务(如遛狗),直接切换完成 api .toggleTask(t.id) .then((res) => { @@ -186,14 +190,6 @@ Page({ }) .catch((err) => toastErr(err, '操作失败')); }, - completeTasks() { - const id = store.currentPetId(); - if (!id) return; - api - .completeAllTasks(id) - .then((tasks) => this.setData({ tasks: (tasks || []).map(mapTask) })) - .catch((e) => toastErr(e, '操作失败')); - }, goPlan() { wx.navigateTo({ url: '/pages/plan/plan' }); }, diff --git a/pets-fe/pages/home/home.wxml b/pets-fe/pages/home/home.wxml index dc86625..078bad3 100644 --- a/pets-fe/pages/home/home.wxml +++ b/pets-fe/pages/home/home.wxml @@ -71,7 +71,6 @@ 管理 - 全部完成