feat(fe): 今日任务完成走记录表单,去掉「全部完成」

- 去掉首页「全部完成」按钮,避免一键刷完不留记录
- 勾选带记录类型的任务 → 跳记录表单,保存成功后才回填任务完成,
  返回首页 onShow 自动刷新任务勾选 + 最近记录(带 taskId 传参)
- 只对未完成任务传 taskId,避免重复完成把已完成任务 toggle 回去
- 无记录类型的任务(如遛狗)仍直接勾选完成

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-07-31 09:03:27 +08:00
parent 603bd5773e
commit 96c92f2cfb
3 changed files with 13 additions and 12 deletions
+7 -1
View File
@@ -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) => {
+6 -10
View File
@@ -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' });
},
-1
View File
@@ -71,7 +71,6 @@
<!-- 任务的增删改都在计划页 —— 合并之后首页这个「管理」不该再开一个弹层 -->
<view class="head-links">
<view class="link" bindtap="goPlan">管理</view>
<view class="link" bindtap="completeTasks">全部完成</view>
</view>
</view>
<view class="task-list">