feat(fe): Phase B —— 计划并进首页,日期条能展开成整月
## 日期条 → 可展开日历 首页那条七天日期带下面加了「展开整月」。展开后是整月网格(有安排的 日子带绿点),点任意一天,任务卡跟着切到那天。收起来还是七天,默认 不拉日历接口。 这块原来是计划页的「日历」tab,现在从计划页整个摘掉了——「哪天要做 什么」和「今天要做什么」本来就是一件事,分在两个 tab 里只是让人多点 两下。日历样式(.cal-* / .day-detail / .dd-*)跟着从 plan.wxss 搬到 home.wxss,plan.wxss 里没留死规则。 ## 任务卡下面挂当天的计划节点和提醒 day-plan 接口本来就返回 plan_nodes / reminders / tasks 三份。这里只取 前两份,任务列表仍然走 /tasks——因为 /tasks 会补生成当天任务而 day-plan 不会,拿它的 tasks 覆盖列表会让今天的任务凭空少掉。 ## 「接下来」卡 30 天计划里最近 3 个还没做的节点,日期显示成「今天/明天/3 天后」而不是 7月31日。带完成度进度条,右上角「完整计划」进计划页。 计划页降级成二级页之后,这张卡是它在首页的唯一露出;没有它,计划这个 功能对用户来说就等于消失了。 ## AI 计划入口 AI 页快捷区加了「生成养护计划」,直达 /pages/plan/plan?tab=aiPlan。 没有把这个表单搬进 AI 聊天页:它要渲染 extracted 四宫格和可勾选的任务 节点,塞进聊天流意味着同一个页面维护两套完全不同的渲染,收益只是少跳 一次。原本要解决的是「计划页降级后 AI 计划找不到了」,一个入口就够了。 顺带:iconfont 补了 up / down 两个 chevron(展开收起用)。 联调验证(本地 9090,新建幼犬档案): day-plan 今天 → plan_nodes=['确认免疫与驱虫计划'] plan → completion_pct=0,4 个节点,date 字段齐全 接下来筛出 → 07-29 确认免疫与驱虫计划 / 08-01 观察饮水与排便 / 08-05 体重趋势检查 calendar → 2026-7,today=29,tasked_days=[29] day-plan 未来日 → 08-01、08-05 各自返回对应节点 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,38 @@ function todayStr() {
|
||||
return d.getFullYear() + '-' + p(d.getMonth() + 1) + '-' + p(d.getDate());
|
||||
}
|
||||
|
||||
function pad2(n) {
|
||||
return n < 10 ? '0' + n : '' + n;
|
||||
}
|
||||
|
||||
// 整月网格。周一为一周起点,前面补空格子对齐星期。
|
||||
// 与计划页原来的实现同源——计划页的日历 tab 已并到这里,那边删掉了
|
||||
function buildCells(year, month, taskedDays, today) {
|
||||
const first = new Date(year, month - 1, 1);
|
||||
const lead = (first.getDay() + 6) % 7;
|
||||
const daysInMonth = new Date(year, month, 0).getDate();
|
||||
const set = {};
|
||||
(taskedDays || []).forEach((d) => (set[d] = true));
|
||||
const cells = [];
|
||||
for (let i = 0; i < lead; i++) cells.push({ day: 0 });
|
||||
for (let d = 1; d <= daysInMonth; d++) {
|
||||
cells.push({ day: d, date: year + '-' + pad2(month) + '-' + pad2(d), tasked: !!set[d], today: d === today });
|
||||
}
|
||||
return cells;
|
||||
}
|
||||
|
||||
// 「接下来」用的相对日期,比 7月31日 更好读
|
||||
function whenLabel(date, today) {
|
||||
if (!date) return '';
|
||||
const diff = Math.round((new Date(date + 'T00:00:00') - new Date(today + 'T00:00:00')) / 86400000);
|
||||
if (diff <= 0) return '今天';
|
||||
if (diff === 1) return '明天';
|
||||
if (diff === 2) return '后天';
|
||||
if (diff < 7) return diff + ' 天后';
|
||||
const p = date.split('-');
|
||||
return +p[1] + '月' + +p[2] + '日';
|
||||
}
|
||||
|
||||
function mapTask(t) {
|
||||
return {
|
||||
id: t.id,
|
||||
@@ -56,6 +88,13 @@ Page({
|
||||
selectedDate: '',
|
||||
taskLabel: '今日任务',
|
||||
todayDate: '',
|
||||
calOpen: false,
|
||||
calCells: [],
|
||||
calLabel: '',
|
||||
dayNodes: [],
|
||||
dayReminders: [],
|
||||
upcoming: [],
|
||||
planPct: -1,
|
||||
sheetShow: false,
|
||||
sheetType: '',
|
||||
},
|
||||
@@ -84,6 +123,10 @@ Page({
|
||||
loadAll() {
|
||||
this.loadSummary();
|
||||
this.loadTasks();
|
||||
this.loadDayExtra();
|
||||
this.loadUpcoming();
|
||||
// 日历只在展开过之后才跟着刷新,没展开就别白拉一次
|
||||
if (this.data.calOpen) this.loadCalendar();
|
||||
if (!this.data.firstArticle) {
|
||||
api
|
||||
.listArticles()
|
||||
@@ -122,6 +165,57 @@ Page({
|
||||
: undone > 0 ? '还有 ' + undone + ' 件事没做完' : '今天的事都做完啦',
|
||||
});
|
||||
},
|
||||
// 这天挂着的计划节点和到期提醒。任务列表仍走 /tasks(那边会补生成当天任务),
|
||||
// day-plan 只取 tasks 之外的两类,不拿它的 tasks 覆盖列表
|
||||
loadDayExtra() {
|
||||
const id = store.currentPetId();
|
||||
if (!id) return;
|
||||
const date = this.data.selectedDate || this.data.todayDate;
|
||||
api
|
||||
.dayPlan(id, date)
|
||||
.then((res) => {
|
||||
this.setData({
|
||||
dayNodes: (res.plan_nodes || []).map((n) => ({ title: n.title, done: n.done })),
|
||||
dayReminders: (res.reminders || []).map((r) => ({ title: r.title })),
|
||||
});
|
||||
})
|
||||
.catch(() => this.setData({ dayNodes: [], dayReminders: [] }));
|
||||
},
|
||||
// 30 天计划里最近 3 个还没做的节点
|
||||
loadUpcoming() {
|
||||
const id = store.currentPetId();
|
||||
if (!id) return;
|
||||
const today = this.data.todayDate;
|
||||
api
|
||||
.getPlan(id)
|
||||
.then((plan) => {
|
||||
const list = ((plan && plan.tasks) || [])
|
||||
.filter((t) => !t.done && t.date && t.date >= today)
|
||||
.sort((a, b) => (a.date < b.date ? -1 : 1))
|
||||
.slice(0, 3)
|
||||
.map((t) => ({ id: t.id, title: t.title, description: t.description, whenLabel: whenLabel(t.date, today) }));
|
||||
this.setData({ upcoming: list, planPct: plan ? plan.completion_pct || 0 : -1 });
|
||||
})
|
||||
.catch(() => this.setData({ upcoming: [], planPct: -1 }));
|
||||
},
|
||||
loadCalendar() {
|
||||
const id = store.currentPetId();
|
||||
if (!id) return;
|
||||
api
|
||||
.planCalendar(id)
|
||||
.then((res) => {
|
||||
this.setData({
|
||||
calCells: buildCells(res.year, res.month, res.tasked_days, res.today),
|
||||
calLabel: `${res.year} 年 ${res.month} 月`,
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
},
|
||||
toggleCal() {
|
||||
const open = !this.data.calOpen;
|
||||
this.setData({ calOpen: open });
|
||||
if (open && !this.data.calCells.length) this.loadCalendar();
|
||||
},
|
||||
onTapDay(e) {
|
||||
const { date, active } = e.currentTarget.dataset;
|
||||
if (!date) return;
|
||||
@@ -131,10 +225,15 @@ Page({
|
||||
taskLabel: active ? '今日任务' : +parts[1] + '月' + +parts[2] + '日',
|
||||
});
|
||||
this.loadTasks();
|
||||
this.loadDayExtra();
|
||||
},
|
||||
backToToday() {
|
||||
this.setData({ selectedDate: this.data.todayDate, taskLabel: '今日任务' });
|
||||
this.loadTasks();
|
||||
this.loadDayExtra();
|
||||
},
|
||||
goPlan() {
|
||||
wx.navigateTo({ url: '/pages/plan/plan' });
|
||||
},
|
||||
onTapTask(e) {
|
||||
const i = e.currentTarget.dataset.index;
|
||||
@@ -178,6 +277,8 @@ Page({
|
||||
onSheetSave() {
|
||||
this.loadTasks();
|
||||
this.loadSummary();
|
||||
this.loadDayExtra();
|
||||
if (this.data.calOpen) this.loadCalendar(); // 加了任务,格子上的圆点要跟着变
|
||||
},
|
||||
onAddPet() {
|
||||
this.openSheetType('addPet');
|
||||
|
||||
Reference in New Issue
Block a user