Files
kairos_miniapp/pages/home/index.js
2026-03-27 17:55:18 +08:00

48 lines
870 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import request from "@/utils/request"
Page({
data: {
detail: {
overview: {},
tasks: [{}, {}, {}],
},
loading: true,
},
onLoad() {
this.init()
},
onShow() {
this.getTabBar((tabBar) => {
tabBar.setData({
selected: '首页',
})
})
},
async init() {
let res = await request.get("/home")
this.setData({
detail: res,
loading: false,
})
},
//手动标记是否完成
handDone(e) {
const { data } = e.currentTarget.dataset;
const newTasks = this.data.detail.tasks.map(v => {
if (v.task_id == data.task_id) {
// 如果当前是 1 则变为 0如果是 0 则变为 1
return { ...v, is_completed: v.is_completed == 1 ? 0 : 1 };
}
return v;
});
request.post("/home/task-record", {
...data,
is_completed: data.is_completed == 1 ? 0 : 1
})
this.setData({
'detail.tasks': newTasks
});
}
})