feat: 计划按自然月管理,加「应用到每天」和下月未排提醒
## 为什么不是「从计划开始日起 30 天」 上一版是那样做的,截图一看就不对:计划是月中建的,日历显示 「7月26日 — 8月25日」,既不像本月也不像下月,用户想问「这个月还剩什么」 根本对不上。改成自然月,日历就是一眼能认的月历。 能翻到下月 —— 否则「做下月计划」这件事本身做不了。 ## 校验从「Day 上限」改成「日期」 PlanTask.Day 是相对计划开始日的,月份边界是相对今天的,两者会错开。 原来卡 Day<=30,计划建了几天之后下月末就换算成 Day=40 多, 用户在日历上明明看得到那格、点进去却存不了。 现在的规则:不早于计划开始日(下界放到开始日而不是本月 1 号——模板生成的 历史节点可能在上个月,那些要允许原地改),不晚于下月月底。 ## 应用到每天 一天建一条,不做「一条 + repeat 字段读时展开」:勾选状态是按天的, 展开方案还得再开一张表记「哪天打过勾」,而直接建 N 条天然就有这个能力。 范围止于**这一天所在那个月**的月底,不跨月——「应用到每天」说的是这个月每天, 跨过去就变成用户没要求的事了。只有新增能选,已有的那条改成每天等于凭空 复制 N 份(用户想要的是「以后每天」,不是「把这条撒开」)。 ## 首页那个提醒 GET /pets/:id/plan/month-status 返回本月件数/剩余、下月件数、need_next。 need_next 只在**月末最后 7 天**且下月为空时为真:月初就催「排下个月」太早, 用户会当成噪音。角标做在图标上而不是弹 toast——每次进首页弹一下很烦, 而这件事不紧急、看见就行。 副标题有优先级:「8 月计划还没排」压过「本月都做完了」,因为前者有时效。 四种状态实跑验过,包括让位关系。 ## 顺手 pet-switch 加 show-add 属性。计划页只需要在既有宠物之间切,建档入口在首页 和「我的」就够了,到处摆一个「添加」会让这条 chip 变得很长。 本月/下月的切换用新的 .link-tabs 而不是挂在 .head-links 上:首页的 「管理 / 全部完成」也用 head-links,那是两个并列动作,不该有一个是灰的。 ## 验证(预生产库实跑) 月边界 本月末通过、下月末通过、下下月拒(报出具体日期) 应用到每天 今天→本月末 2 条,没跨月 month-status 下月清空 → need_next 翻 true;补一条 → 翻回 false 四种副标题 下月未排 / 本月还有 N 件 / 本月都做完了 / 还没有安排,含优先级 测试数据全部还原 上一条 cd 打错目录,导致「日期窗口」那次改动没写进文件、只有批量那半截进去了, 所以中间出现过一次 planWindow undefined。这次一并改对。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -120,6 +120,12 @@ page{scrollbar-width:none;-ms-overflow-style:none}
|
||||
}
|
||||
.section-head .sh-title{font-size:var(--fs-lg);letter-spacing:-.4rpx;font-weight:var(--fw-b)}
|
||||
.link{color:var(--primary-dark);font-weight:var(--fw-b);font-size:var(--fs-md)}
|
||||
/* 一组 .link 当「切换」用时:未选中压成灰,不然两个都是橙的、看不出当前在哪。
|
||||
单独一个 .link-tabs 而不是挂在 .head-links 上——首页的「管理 / 全部完成」
|
||||
也用 head-links,那是两个并列动作,不该有一个是灰的 */
|
||||
.link-tabs{display:flex;gap:var(--sp-4)}
|
||||
.link-tabs .link{color:var(--muted)}
|
||||
.link-tabs .link.on{color:var(--primary-dark)}
|
||||
.head-links{display:flex;align-items:center;gap:var(--sp-4)}
|
||||
|
||||
/* 页面标题。
|
||||
|
||||
@@ -2,6 +2,11 @@ const store = require('../../utils/store.js');
|
||||
|
||||
Component({
|
||||
options: { addGlobalClass: true },
|
||||
properties: {
|
||||
// 「添加」这一格不是每个页面都该有:计划页/记录页只是在既有宠物之间切,
|
||||
// 建档入口在首页和「我的」就够了,到处摆一个会让这条 chip 变得很长
|
||||
showAdd: { type: Boolean, value: true },
|
||||
},
|
||||
data: {
|
||||
pets: [],
|
||||
currentId: 0,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
data-id="{{item.id}}" bindtap="onPick">
|
||||
<view class="mini-avatar">{{item.emoji}}</view>{{item.name}}
|
||||
</view>
|
||||
<view class="pet-chip" bindtap="onAdd">
|
||||
<view wx:if="{{showAdd}}" class="pet-chip" bindtap="onAdd">
|
||||
<view class="mini-avatar"><pt-icon name="plus" size="{{30}}"></pt-icon></view>添加
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
@@ -33,7 +33,8 @@ Page({
|
||||
sexIcon: '',
|
||||
sexTone: '',
|
||||
tasks: [],
|
||||
planUndone: 0,
|
||||
planHint: '',
|
||||
needNextPlan: false,
|
||||
monthCost: 0,
|
||||
timeline: [],
|
||||
tlPage: 1,
|
||||
@@ -93,10 +94,24 @@ Page({
|
||||
loadEntries() {
|
||||
const id = store.currentPetId();
|
||||
if (!id) return;
|
||||
// 副标题优先说「该排下月计划了」——那是有时效的事;
|
||||
// 本月还剩几件是随时能看的,让位给它
|
||||
api
|
||||
.getPlan(id)
|
||||
.then((plan) => this.setData({ planUndone: ((plan && plan.tasks) || []).filter((t) => !t.done).length }))
|
||||
.catch(() => this.setData({ planUndone: 0 }));
|
||||
.planMonthStatus(id)
|
||||
.then((st) => {
|
||||
const s = st || {};
|
||||
this.setData({
|
||||
needNextPlan: !!s.need_next,
|
||||
planHint: s.need_next
|
||||
? (s.next_label || '下月') + '计划还没排'
|
||||
: s.this_undone > 0
|
||||
? '本月还有 ' + s.this_undone + ' 件'
|
||||
: s.this_month > 0
|
||||
? '本月都做完了'
|
||||
: '还没有安排',
|
||||
});
|
||||
})
|
||||
.catch(() => this.setData({ needNextPlan: false, planHint: '' }));
|
||||
api
|
||||
.getBill(id, 'month')
|
||||
.then((b) => this.setData({ monthCost: (b && b.total) || 0 }))
|
||||
|
||||
@@ -29,9 +29,14 @@
|
||||
<!-- 两个入口。竞品那一排是买商品/上豪车/领猫砂盆,是电商和广告位,去掉 -->
|
||||
<view class="card entry-card">
|
||||
<view class="entry" bindtap="goPlan">
|
||||
<view class="entry-ic tone-1"><pt-icon name="plan" size="{{48}}"></pt-icon></view>
|
||||
<view class="entry-ic tone-1">
|
||||
<pt-icon name="plan" size="{{48}}"></pt-icon>
|
||||
<!-- 月底还没排下月计划时提醒。角标做在图标上而不是弹 toast:
|
||||
每次进首页弹一下会很烦,而这件事不紧急、看见就行 -->
|
||||
<view wx:if="{{needNextPlan}}" class="entry-dot"></view>
|
||||
</view>
|
||||
<view class="entry-b">管理计划</view>
|
||||
<view class="entry-p">{{planUndone > 0 ? '还有 ' + planUndone + ' 件没做' : '30 天安排'}}</view>
|
||||
<view class="entry-p {{needNextPlan ? 'warn' : ''}}">{{planHint}}</view>
|
||||
</view>
|
||||
<view class="entry" bindtap="goExpense">
|
||||
<view class="entry-ic tone-2"><pt-icon name="cost" size="{{48}}"></pt-icon></view>
|
||||
|
||||
@@ -71,3 +71,10 @@
|
||||
.tl-desc{font-size:var(--fs-sm);color:var(--text-2);margin-top:6rpx;line-height:1.5}
|
||||
.tl-img{width:100%;height:320rpx;border-radius:var(--r-sm);margin-top:var(--sp-3);display:block}
|
||||
.tl-more{text-align:center;padding:var(--sp-4);font-size:var(--fs-sm);color:var(--muted)}
|
||||
|
||||
.entry-ic{position:relative}
|
||||
.entry-dot{
|
||||
position:absolute;top:-2rpx;right:-2rpx;width:18rpx;height:18rpx;
|
||||
border-radius:50%;background:var(--red);border:3rpx solid #fff;
|
||||
}
|
||||
.entry-p.warn{color:var(--red-ink);font-weight:var(--fw-b)}
|
||||
|
||||
+63
-38
@@ -18,45 +18,53 @@ function parseYMD(s) {
|
||||
return p.length < 3 ? null : new Date(+p[0], +p[1] - 1, +p[2]);
|
||||
}
|
||||
|
||||
// 计划覆盖的天数。内置模板会生成 day=30 的节点(第 31 天),所以是 31 格不是 30 格;
|
||||
// 按 30 画的话模板自己的最后一个节点在日历上没有格子——看得到、点不到。
|
||||
// 和后端 service/plan.go 的 planSpanDays 必须一致。
|
||||
const SPAN = 31;
|
||||
|
||||
// 只画计划覆盖的这段,不画整月:整月会多出一堆空白格子、跨月还要翻页。
|
||||
// 按周对齐排 31 天,首尾补几个空格就够,一屏看完。
|
||||
function buildCells(startStr, byDate, todayStr) {
|
||||
const start = parseYMD(startStr);
|
||||
if (!start) return [];
|
||||
const lead = (start.getDay() + 6) % 7; // 周一为一周起点
|
||||
// 自然月网格。周一为一周起点,首尾补空格对齐星期。
|
||||
// 按月切而不是「从计划开始日起 30 天」:那样窗口跨两个月,
|
||||
// 用户看着一个 7月26日—8月25日 的日历,既不像本月也不像下月。
|
||||
function buildCells(year, month, byDate, todayStr) {
|
||||
const first = new Date(year, month - 1, 1);
|
||||
const lead = (first.getDay() + 6) % 7;
|
||||
const total = new Date(year, month, 0).getDate();
|
||||
const cells = [];
|
||||
for (let i = 0; i < lead; i++) cells.push({ blank: true });
|
||||
for (let i = 0; i < SPAN; i++) {
|
||||
const d = new Date(start.getFullYear(), start.getMonth(), start.getDate() + i);
|
||||
const s = ymd(d);
|
||||
cells.push({ day: d.getDate(), date: s, count: (byDate[s] || []).length, today: s === todayStr });
|
||||
for (let d = 1; d <= total; d++) {
|
||||
const s = year + '-' + pad2(month) + '-' + pad2(d);
|
||||
cells.push({ day: d, date: s, count: (byDate[s] || []).length, today: s === todayStr });
|
||||
}
|
||||
// 末尾补齐整周,否则最后一行格子宽度会被 grid 拉歪
|
||||
while (cells.length % 7) cells.push({ blank: true });
|
||||
return cells;
|
||||
}
|
||||
|
||||
// off=0 本月,off=1 下月
|
||||
function monthOf(off) {
|
||||
const n = new Date();
|
||||
const d = new Date(n.getFullYear(), n.getMonth() + off, 1);
|
||||
return { year: d.getFullYear(), month: d.getMonth() + 1 };
|
||||
}
|
||||
function monthEnd(off) {
|
||||
const m = monthOf(off);
|
||||
return m.year + '-' + pad2(m.month) + '-' + pad2(new Date(m.year, m.month, 0).getDate());
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
pet: {},
|
||||
plan: null,
|
||||
doneCount: 0,
|
||||
cells: [],
|
||||
calRange: '',
|
||||
planStart: '',
|
||||
planEnd: '',
|
||||
monthOff: 0,
|
||||
monthLabel: '',
|
||||
monthEndLabel: '',
|
||||
nextCount: 0,
|
||||
pickStart: '',
|
||||
pickEnd: '',
|
||||
selDate: '',
|
||||
selLabel: '',
|
||||
dayTasks: [],
|
||||
allOpen: false,
|
||||
editShow: false,
|
||||
editId: '',
|
||||
form: { title: '', date: '', description: '' },
|
||||
form: { title: '', date: '', description: '', daily: false },
|
||||
saving: false,
|
||||
sheetShow: false,
|
||||
sheetType: '',
|
||||
@@ -95,22 +103,40 @@ Page({
|
||||
if (!t.date) return;
|
||||
(byDate[t.date] = byDate[t.date] || []).push(t);
|
||||
});
|
||||
const start = (plan.start_date || '').slice(0, 10);
|
||||
const end = start ? ymd(new Date(parseYMD(start).getTime() + (SPAN - 1) * 86400000)) : '';
|
||||
const todayStr = ymd(new Date());
|
||||
this._byDate = byDate;
|
||||
|
||||
// 默认选今天;今天不在计划范围内(计划早就过期了)就选开始那天
|
||||
const sel = byDate[todayStr] !== undefined || (todayStr >= start && todayStr <= end) ? todayStr : start;
|
||||
this.setData({
|
||||
plan: { ...plan, tasks },
|
||||
doneCount: tasks.filter((t) => t.done).length,
|
||||
cells: buildCells(start, byDate, todayStr),
|
||||
calRange: start ? fmtMD(start) + ' — ' + fmtMD(end) : '',
|
||||
planStart: start,
|
||||
planEnd: end,
|
||||
// 能排的区间:不早于计划开始日,不晚于下月月底。和后端 dayOffset 的校验一致
|
||||
pickStart: (plan.start_date || '').slice(0, 10),
|
||||
pickEnd: monthEnd(1),
|
||||
});
|
||||
this.selectDay(sel, todayStr);
|
||||
this.renderMonth(this.data.monthOff);
|
||||
if (this._pendingSel) {
|
||||
// 刚加/改完,跳到那一天,不然用户看不到东西去哪了
|
||||
this.selectDay(this._pendingSel);
|
||||
this._pendingSel = '';
|
||||
}
|
||||
},
|
||||
renderMonth(off) {
|
||||
const m = monthOf(off);
|
||||
const todayStr = ymd(new Date());
|
||||
const byDate = this._byDate || {};
|
||||
const prefix = m.year + '-' + pad2(m.month);
|
||||
this.setData({
|
||||
monthOff: off,
|
||||
monthLabel: m.year + ' 年 ' + m.month + ' 月',
|
||||
monthEndLabel: fmtMD(monthEnd(off)),
|
||||
cells: buildCells(m.year, m.month, byDate, todayStr),
|
||||
nextCount: Object.keys(byDate).filter((d) => d.indexOf(monthOf(1).year + '-' + pad2(monthOf(1).month)) === 0)
|
||||
.reduce((n, d) => n + byDate[d].length, 0),
|
||||
});
|
||||
// 切到本月默认选今天;切到下月默认选 1 号(今天不在那个月里)
|
||||
const inMonth = todayStr.indexOf(prefix) === 0;
|
||||
this.selectDay(inMonth ? todayStr : prefix + '-01', todayStr);
|
||||
},
|
||||
switchMonth(e) {
|
||||
this.renderMonth(Number(e.currentTarget.dataset.off));
|
||||
},
|
||||
selectDay(date, todayStr) {
|
||||
const t = todayStr || ymd(new Date());
|
||||
@@ -124,11 +150,7 @@ Page({
|
||||
const d = e.currentTarget.dataset.date;
|
||||
if (d) this.selectDay(d);
|
||||
},
|
||||
backToToday() {
|
||||
const t = ymd(new Date());
|
||||
// 今天不在这 30 天里就退回开始日,否则选中一个日历上不存在的格子
|
||||
this.selectDay(t >= this.data.planStart && t <= this.data.planEnd ? t : this.data.planStart);
|
||||
},
|
||||
|
||||
toggleAll() {
|
||||
this.setData({ allOpen: !this.data.allOpen });
|
||||
},
|
||||
@@ -143,7 +165,7 @@ Page({
|
||||
openAdd() {
|
||||
this.setData({
|
||||
editShow: true, editId: '',
|
||||
form: { title: '', date: this.data.selDate || this.data.planStart, description: '' },
|
||||
form: { title: '', date: this.data.selDate || ymd(new Date()), description: '', daily: false },
|
||||
});
|
||||
},
|
||||
openEdit(e) {
|
||||
@@ -151,7 +173,7 @@ Page({
|
||||
if (!t) return;
|
||||
this.setData({
|
||||
editShow: true, editId: t.id,
|
||||
form: { title: t.title, date: t.date || this.data.selDate, description: t.description || '' },
|
||||
form: { title: t.title, date: t.date || this.data.selDate, description: t.description || '', daily: false },
|
||||
});
|
||||
},
|
||||
closeEdit() {
|
||||
@@ -167,6 +189,9 @@ Page({
|
||||
onFormDesc(e) {
|
||||
this.setData({ 'form.description': e.detail.value });
|
||||
},
|
||||
onFormDaily(e) {
|
||||
this.setData({ 'form.daily': e.detail.value });
|
||||
},
|
||||
onSubmit() {
|
||||
if (this.data.saving) return;
|
||||
const f = this.data.form;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<nav-bar title="养宠计划" show-back="{{true}}"></nav-bar>
|
||||
|
||||
<view class="top-bar"><pet-switch bind:add="onAddPet"></pet-switch></view>
|
||||
<view class="top-bar"><pet-switch show-add="{{false}}"></pet-switch></view>
|
||||
|
||||
<scroll-view class="page-scroll" scroll-y="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}">
|
||||
<view class="page-body">
|
||||
@@ -21,12 +21,19 @@
|
||||
<view class="bar"><view class="bar-fill" style="width:{{plan.completion_pct || 0}}%"></view></view>
|
||||
</view>
|
||||
|
||||
<!-- 日历:只画计划覆盖的这 30 天。有安排的日子带点,点一天下面就列那天的事。
|
||||
整月网格会画出一半空白格子——计划本来就只有 30 天,按周排比按月排更贴合 -->
|
||||
<!-- 月历。按自然月切而不是「从计划开始日起 30 天」:那样窗口会跨两个月,
|
||||
用户看着 7月26日—8月25日 既不像本月也不像下月,「这个月还剩什么」对不上。
|
||||
能翻到下月,否则「做下月计划」这件事本身做不了 -->
|
||||
<view class="card">
|
||||
<view class="section-head">
|
||||
<view class="sh-title">{{calRange}}</view>
|
||||
<view class="link" bindtap="backToToday">回今天</view>
|
||||
<view class="sh-title">{{monthLabel}}</view>
|
||||
<view class="link-tabs">
|
||||
<view class="link {{monthOff === 0 ? 'on' : ''}}" data-off="0" bindtap="switchMonth">本月</view>
|
||||
<view class="link {{monthOff === 1 ? 'on' : ''}}" data-off="1" bindtap="switchMonth">下月</view>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{monthOff === 1 && !nextCount}}" class="plan-tip">
|
||||
<pt-icon name="warn" size="{{28}}"></pt-icon>{{monthLabel}}还没有安排,点某天加几件
|
||||
</view>
|
||||
<view class="cal-grid">
|
||||
<text class="cal-w">一</text><text class="cal-w">二</text><text class="cal-w">三</text><text class="cal-w">四</text><text class="cal-w">五</text><text class="cal-w">六</text><text class="cal-w">日</text>
|
||||
@@ -89,14 +96,23 @@
|
||||
<input class="input" placeholder="比如 带去打第二针" placeholder-class="placeholder"
|
||||
value="{{form.title}}" bindinput="onFormTitle"/></view>
|
||||
<view class="field"><label>哪天</label>
|
||||
<picker mode="date" value="{{form.date}}" start="{{planStart}}" end="{{planEnd}}" bindchange="onFormDate">
|
||||
<picker mode="date" value="{{form.date}}" start="{{pickStart}}" end="{{pickEnd}}" bindchange="onFormDate">
|
||||
<view class="picker-box">{{form.date}}</view>
|
||||
</picker>
|
||||
<view class="tiny">只能安排 {{planStart}} 到 {{planEnd}} 之间</view>
|
||||
<view class="tiny">只能安排 {{pickStart}} 到 {{pickEnd}} 之间</view>
|
||||
</view>
|
||||
<view class="field"><label>备注</label>
|
||||
<textarea class="textarea" placeholder="可不填" placeholder-class="placeholder"
|
||||
value="{{form.description}}" bindinput="onFormDesc"></textarea></view>
|
||||
<!-- 只有新增能选「每天」:已有的那条改成每天等于凭空复制 29 份,
|
||||
用户想要的是「以后每天」,不是「把这条撒开」 -->
|
||||
<view wx:if="{{!editId}}" class="field pe-daily">
|
||||
<view class="pe-daily-main">
|
||||
<view class="tt-b">应用到每天</view>
|
||||
<view class="tt-p">从这天排到 {{monthEndLabel}},每天一条,可以分别打勾</view>
|
||||
</view>
|
||||
<switch checked="{{form.daily}}" color="#F5A947" bindchange="onFormDaily"></switch>
|
||||
</view>
|
||||
<view class="btn btn-primary btn-block" bindtap="onSubmit">{{saving ? '保存中…' : '保存'}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -43,3 +43,14 @@
|
||||
box-shadow:var(--sd-3);max-height:82vh;overflow-y:auto;
|
||||
}
|
||||
.pe-h{font-size:var(--fs-lg);font-weight:var(--fw-b);margin-bottom:var(--sp-4);text-align:center}
|
||||
|
||||
/* 下月还空着时的提示。放在月历里而不是弹 toast——用户切到下月本来就是来排的 */
|
||||
.plan-tip{
|
||||
display:flex;align-items:center;gap:var(--sp-2);
|
||||
background:var(--primary-soft);color:var(--primary-ink);
|
||||
border-radius:var(--r-sm);padding:var(--sp-3);
|
||||
font-size:var(--fs-sm);margin-bottom:var(--sp-3);
|
||||
}
|
||||
|
||||
.pe-daily{display:flex;align-items:center;gap:var(--sp-4)}
|
||||
.pe-daily-main{flex:1;min-width:0}
|
||||
|
||||
@@ -90,6 +90,7 @@ const api = {
|
||||
// createAIPlan: (id, input) => request({ url: `/api/pets/${id}/ai-plan`, method: 'POST', data: { input } }),
|
||||
// applyAIPlan: (planId) => request({ url: `/api/ai-plan/${planId}/apply`, method: 'POST' }),
|
||||
// 用户自己管理计划节点
|
||||
planMonthStatus: (petId) => request({ url: `/api/pets/${petId}/plan/month-status` }),
|
||||
addPlanTask: (petId, body) => request({ url: `/api/pets/${petId}/plan-tasks`, method: 'POST', data: body }),
|
||||
updatePlanTask: (taskId, body) => request({ url: `/api/plan-tasks/${taskId}`, method: 'PUT', data: body }),
|
||||
deletePlanTask: (taskId) => request({ url: `/api/plan-tasks/${taskId}`, method: 'DELETE' }),
|
||||
|
||||
Reference in New Issue
Block a user