feat: 引导页阶段按生日推断 + 8 套养护模板按临床共识重配
## 引导页三个逻辑漏洞 1. **阶段和生日脱节**:用户填了 3 个月的生日,却能手选「成年期」, 而阶段决定疫苗针次、驱虫周期和每天要做的事,选错整套计划都是偏的。 现在按生日自动推断(猫狗同:12 月龄成年、7 岁进老年),仍可手改, 但改成矛盾值时会弹框说明代价;服务端 NormalizeStage 兜底。 2. **`goals` 是假选择**:6 个勾选框收上来只存进 pets.goals,一处没用过。 现在真正生效:体重提醒、月度报告按勾选生成,勾了「想控制养宠开销」 会多一条记账任务。疫苗和驱虫不给关——狂犬是法定要求,漏驱虫真会出事。 3. **「刚到家 0-30 天」和年龄阶段互斥**:挤在一个四选一里,刚接回家的 成年猫只能二选一。现在拆开:stage 只存年龄阶段,新增 pets.arrived_at, 到家不满 30 天时把安置期那套任务和计划叠加上去(同标题去重)。 顺带:生日/到家日期不能选未来(前后端各拦一道)、体重范围校验。 ## 疫苗提醒改为按月龄算 原来不管多大都排「14 天后首针」,一只 8 月龄才接回家的猫会被安排去打首免。 现在 dueDaysFor 按真实月龄推:<2 月龄等到 8 周龄、2-5 月龄间隔 21 天、 5-12 月龄两周内补齐、成年走年度加强。标题也跟着改写,否则用户照着 「年度疫苗加强」去打错针。 年度疫苗不再编一个假的到期日(原来写 30 天后),改用频率描述。 ## 8 套模板按临床共识重配 依据 WSAVA 疫苗指南、ESCCAP/CAPC 驱虫建议、AAHA 生命阶段指南整理: 猫三联 3 针间隔 3-4 周末针不早于 16 周龄、犬联苗 2-3 针 + 3 月龄狂犬、 体内驱虫 6 月龄前每月一次之后每 3 个月、幼崽 3-6 月龄每天 3-4 餐、 成年犬每天 2 次共 30-60 分钟遛狗、老年建议半年一次体检。 每套从 11 条扩到 10-14 条,描述写成能直接照做的具体动作。 后台新增「恢复默认」:启动 seed 改为只补缺失、不覆盖已有(管理员可能 改过),内置模板更新后必须从后台显式推一次。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,36 @@ const api = require('../../utils/api.js');
|
||||
|
||||
const GENDERS = ['男孩', '女孩', '不确定'];
|
||||
|
||||
// 与后端 service.AgeStages 一致:「刚到家」不是年龄阶段,它由到家日期单独决定
|
||||
const STAGE_OPTIONS = [
|
||||
{ key: '幼年期', desc: '疫苗针次、驱虫、体重增长、社会化训练' },
|
||||
{ key: '成年期', desc: '体重控制、口腔、日常健康管理' },
|
||||
{ key: '老年期', desc: '慢病监测、半年体检、用药与护理' },
|
||||
];
|
||||
|
||||
function today() {
|
||||
const d = new Date();
|
||||
const p = (n) => (n < 10 ? '0' + n : '' + n);
|
||||
return d.getFullYear() + '-' + p(d.getMonth() + 1) + '-' + p(d.getDate());
|
||||
}
|
||||
|
||||
function monthsSince(dateStr) {
|
||||
const b = new Date(dateStr);
|
||||
const now = new Date();
|
||||
let m = (now.getFullYear() - b.getFullYear()) * 12 + (now.getMonth() - b.getMonth());
|
||||
if (now.getDate() < b.getDate()) m--;
|
||||
return m < 0 ? 0 : m;
|
||||
}
|
||||
|
||||
// 与后端 StageFromBirthday 同一套规则:12 月龄成年、7 岁进入老年
|
||||
function stageFromBirthday(birthday) {
|
||||
if (!birthday) return '';
|
||||
const m = monthsSince(birthday);
|
||||
if (m < 12) return '幼年期';
|
||||
if (m >= 84) return '老年期';
|
||||
return '成年期';
|
||||
}
|
||||
|
||||
function ageFromBirthday(bdayStr) {
|
||||
if (!bdayStr) return '';
|
||||
const b = new Date(bdayStr);
|
||||
@@ -21,7 +51,11 @@ Page({
|
||||
birthday: '',
|
||||
genderIdx: 0,
|
||||
weight: '',
|
||||
stage: '幼年期',
|
||||
arrivedAt: '',
|
||||
today: '',
|
||||
stage: '',
|
||||
stageAuto: '',
|
||||
stageOptions: STAGE_OPTIONS,
|
||||
goals: [
|
||||
{ label: '不知道每天该做什么', on: true },
|
||||
{ label: '疫苗驱虫怕忘记', on: true },
|
||||
@@ -33,6 +67,7 @@ Page({
|
||||
submitting: false,
|
||||
},
|
||||
onLoad() {
|
||||
this.setData({ today: today(), arrivedAt: today() });
|
||||
// 已有宠物则直接进首页
|
||||
store
|
||||
.ready()
|
||||
@@ -52,7 +87,15 @@ Page({
|
||||
},
|
||||
onName(e) { this.setData({ petName: e.detail.value }); },
|
||||
onWeight(e) { this.setData({ weight: e.detail.value }); },
|
||||
onBirthday(e) { this.setData({ birthday: e.detail.value }); },
|
||||
onBirthday(e) {
|
||||
const birthday = e.detail.value;
|
||||
const auto = stageFromBirthday(birthday);
|
||||
const patch = { birthday, stageAuto: auto };
|
||||
// 用户手动选过就尊重他的选择,否则跟着生日走
|
||||
if (!this._stageTouched) patch.stage = auto;
|
||||
this.setData(patch);
|
||||
},
|
||||
onArrived(e) { this.setData({ arrivedAt: e.detail.value }); },
|
||||
selectGender(e) { this.setData({ genderIdx: Number(e.currentTarget.dataset.index) }); },
|
||||
// 先随便看看:不建数据,直接进首页浏览(无宠物时首页显示空态)
|
||||
skipBrowse() { wx.switchTab({ url: '/pages/home/home' }); },
|
||||
@@ -61,10 +104,39 @@ Page({
|
||||
wx.showToast({ title: '给它起个名字吧', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
const w = parseFloat(this.data.weight);
|
||||
// 体重会进趋势图和用药剂量参考,乱填不如不填
|
||||
if (this.data.weight && !(w > 0 && w < 120)) {
|
||||
wx.showToast({ title: '体重看起来不太对', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (!this.data.birthday) {
|
||||
wx.showToast({ title: '生日决定疫苗和驱虫节奏,估个大概也行', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
this.nextStep();
|
||||
},
|
||||
chooseStage(e) {
|
||||
this.setData({ stage: e.currentTarget.dataset.stage });
|
||||
const stage = e.currentTarget.dataset.stage;
|
||||
const auto = this.data.stageAuto;
|
||||
// 改成和生日矛盾的阶段是允许的(领养估的生日可能不准,大型犬发育也慢),
|
||||
// 但要先说清楚代价:阶段决定疫苗针次怎么排,选错会漏针
|
||||
if (auto && stage !== auto) {
|
||||
wx.showModal({
|
||||
title: '和生日对不上',
|
||||
content: `按生日算它应该在「${auto}」。改成「${stage}」的话,疫苗针次和驱虫周期会按${stage}安排。确定要改吗?`,
|
||||
confirmText: '确定改',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this._stageTouched = true;
|
||||
this.setData({ stage });
|
||||
}
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
this._stageTouched = true;
|
||||
this.setData({ stage });
|
||||
},
|
||||
toggleGoal(e) {
|
||||
const i = e.currentTarget.dataset.index;
|
||||
@@ -80,8 +152,9 @@ Page({
|
||||
type: this.data.petType,
|
||||
gender: GENDERS[this.data.genderIdx],
|
||||
birthday: this.data.birthday,
|
||||
arrived_at: this.data.arrivedAt,
|
||||
weight: this.data.weight,
|
||||
stage: this.data.stage,
|
||||
stage: this.data.stage || this.data.stageAuto,
|
||||
age: ageFromBirthday(this.data.birthday),
|
||||
goals: this.data.goals.filter((g) => g.on).map((g) => g.label),
|
||||
};
|
||||
|
||||
@@ -40,10 +40,15 @@
|
||||
<view class="form-card">
|
||||
<view class="field"><label>宠物名字</label>
|
||||
<input class="input" value="{{petName}}" placeholder="例如:奶球" placeholder-class="placeholder" bindinput="onName"/></view>
|
||||
<view class="field"><label>生日 / 到家时间</label>
|
||||
<picker mode="date" value="{{birthday}}" bindchange="onBirthday">
|
||||
<view class="picker-box">{{birthday || '选择日期'}}</view>
|
||||
<view class="field"><label>生日</label>
|
||||
<picker mode="date" value="{{birthday}}" end="{{today}}" bindchange="onBirthday">
|
||||
<view class="picker-box">{{birthday || '选择日期(不确定可以估个大概)'}}</view>
|
||||
</picker></view>
|
||||
<view class="field"><label>到家日期</label>
|
||||
<picker mode="date" value="{{arrivedAt}}" end="{{today}}" bindchange="onArrived">
|
||||
<view class="picker-box">{{arrivedAt || '选择日期'}}</view>
|
||||
</picker>
|
||||
<view class="field-tip">刚到家不满 30 天的话,会额外安排一组安置期任务</view></view>
|
||||
<view class="field"><label>性别</label><view class="seg">
|
||||
<view class="seg-btn {{genderIdx === 0 ? 'selected' : ''}}" data-index="0" bindtap="selectGender">男孩</view>
|
||||
<view class="seg-btn {{genderIdx === 1 ? 'selected' : ''}}" data-index="1" bindtap="selectGender">女孩</view>
|
||||
@@ -58,16 +63,16 @@
|
||||
<!-- step 3 阶段 -->
|
||||
<view wx:elif="{{step === 3}}" class="step">
|
||||
<view class="step-title">它现在处于哪个阶段?</view>
|
||||
<view class="step-sub">阶段会决定今日任务、提醒和 AI 建议。</view>
|
||||
<view class="step-sub">阶段决定疫苗节奏、驱虫周期和每天要做的事,选错整套计划都会偏。</view>
|
||||
<view wx:if="{{stageAuto}}" class="stage-auto">
|
||||
<pt-icon name="check" size="{{28}}"></pt-icon>已按生日自动判断为「{{stageAuto}}」,不对可以改
|
||||
</view>
|
||||
<view class="stage-list">
|
||||
<view class="stage-card {{stage === '幼年期' ? 'selected' : ''}}" data-stage="幼年期" bindtap="chooseStage">
|
||||
<view class="stage-b">幼年期</view><view class="stage-p">疫苗、驱虫、体重增长、行为训练</view></view>
|
||||
<view class="stage-card {{stage === '刚到家 0-30 天' ? 'selected' : ''}}" data-stage="刚到家 0-30 天" bindtap="chooseStage">
|
||||
<view class="stage-b">刚到家 0-30 天</view><view class="stage-p">适应环境、饮食稳定、基础照护</view></view>
|
||||
<view class="stage-card {{stage === '成年期' ? 'selected' : ''}}" data-stage="成年期" bindtap="chooseStage">
|
||||
<view class="stage-b">成年期</view><view class="stage-p">体重、饮食、日常健康管理</view></view>
|
||||
<view class="stage-card {{stage === '老年期' ? 'selected' : ''}}" data-stage="老年期" bindtap="chooseStage">
|
||||
<view class="stage-b">老年期</view><view class="stage-p">慢病、体检、用药和护理</view></view>
|
||||
<view wx:for="{{stageOptions}}" wx:key="key"
|
||||
class="stage-card {{stage === item.key ? 'selected' : ''}}" data-stage="{{item.key}}" bindtap="chooseStage">
|
||||
<view class="stage-b">{{item.key}}<text wx:if="{{item.key === stageAuto}}" class="stage-hint">按生日推荐</text></view>
|
||||
<view class="stage-p">{{item.desc}}</view>
|
||||
</view>
|
||||
</view>
|
||||
<button class="btn btn-primary btn-block" bindtap="nextStep">下一步</button>
|
||||
</view>
|
||||
@@ -75,7 +80,7 @@
|
||||
<!-- step 4 目标 -->
|
||||
<view wx:elif="{{step === 4}}" class="step">
|
||||
<view class="step-title">你最想解决什么?</view>
|
||||
<view class="step-sub">多选,我们会据此为你定制计划。</view>
|
||||
<view class="step-sub">勾上的会变成真的提醒和任务,没勾的不会打扰你。</view>
|
||||
<view class="check-list">
|
||||
<view wx:for="{{goals}}" wx:key="label" class="check {{item.on ? 'selected' : ''}}" data-index="{{index}}" bindtap="toggleGoal">
|
||||
<view class="box"><pt-icon wx:if="{{item.on}}" name="check" size="{{26}}"></pt-icon></view>{{item.label}}
|
||||
|
||||
@@ -57,3 +57,14 @@
|
||||
width:44rpx;height:44rpx;border-radius:50%;background:var(--green);color:#fff;
|
||||
display:flex;align-items:center;justify-content:center;flex:none;
|
||||
}
|
||||
|
||||
.field-tip{margin-top:var(--sp-2);color:var(--muted);font-size:var(--fs-cap);line-height:1.5}
|
||||
.stage-auto{
|
||||
display:flex;align-items:center;gap:var(--sp-2);margin-bottom:var(--sp-3);
|
||||
padding:var(--sp-3) var(--sp-4);border-radius:var(--r-md);
|
||||
background:var(--green-soft);color:var(--green-ink);font-size:var(--fs-sm);
|
||||
}
|
||||
.stage-hint{
|
||||
margin-left:var(--sp-2);padding:2rpx var(--sp-2);border-radius:var(--r-full);
|
||||
background:var(--primary-soft);color:var(--primary-ink);font-size:var(--fs-cap);font-weight:var(--fw);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user