feat: login rest

This commit is contained in:
Blizzard
2026-02-12 09:26:39 +08:00
parent e97fd30fa3
commit 5553e2711a
115 changed files with 4090 additions and 3499 deletions
+28 -16
View File
@@ -172,36 +172,48 @@ Page({
const taskId = this.data.completingTask.id;
const remark = this.data.remark || '';
wx.showLoading({ title: '提交中...' });
// Optimistic Update immediately for better feel?
// Or wait for server? Wait is safer.
wx.showLoading({ title: '提交中...', mask: true });
request.post('/plant/completeTask', {
taskId: taskId,
remark: remark
}).then(() => {
wx.hideLoading();
wx.showToast({ title: '已完成', icon: 'success' });
// Optimistic UI Update
// Optimistic UI Update Logic
const groups = this.data.groupedTasks;
let updated = false;
// Need to deep clone possibly, but here we modify and set back
for (let g of groups) {
const t = g.tasks.find(x => x.id === taskId);
if (t) {
t.isCompleted = true;
t.isOverdue = false;
// Do NOT sort. Just update status.
updated = true;
break;
// g is an object. groupedTasks is array of objects.
if (g.tasks) {
const t = g.tasks.find(x => x && x.id === taskId);
if (t) {
t.isCompleted = true;
t.isOverdue = false;
updated = true;
break;
}
}
}
if (updated) {
this.setData({ groupedTasks: groups, tasks: groups, completingTask: null, remark: '' });
} else {
this.setData({ completingTask: null, remark: '' });
}
// Trigger Animation and Close Modal
this.setData({
completingTask: null,
remark: '',
groupedTasks: groups, // Update UI
tasks: groups,
showSunshine: true
});
// Sync with backend
// Hide Animation after duration
setTimeout(() => {
this.setData({ showSunshine: false });
}, 3000);
// Sync with backend silently
this.fetchTodayTasks();
}).catch(err => {