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:
@@ -127,6 +127,11 @@ export const api = {
|
||||
}),
|
||||
saveCareTemplate: (species: string, stage: string, items: any[]) =>
|
||||
http.put<any, { items: any[] }>('/admin/care-templates', { species, stage, items }),
|
||||
resetCareTemplate: (species: string, stage: string) =>
|
||||
http.post<any, { species: string; stage: string; items: any[] }>('/admin/care-templates/reset', {
|
||||
species,
|
||||
stage,
|
||||
}),
|
||||
genCareTemplate: (species: string, stage: string) =>
|
||||
http.post<any, { species: string; stage: string; items: any[] }>('/admin/care-templates/generate', {
|
||||
species,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { Cat, Dog, Wand2, Plus, Trash2, Save, Info } from 'lucide-react'
|
||||
import { Cat, Dog, Wand2, Plus, Trash2, Save, Info, RotateCcw } from 'lucide-react'
|
||||
import { api } from '@/lib/api'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Button } from '@/components/ui/button'
|
||||
@@ -106,6 +106,24 @@ export default function CareTemplates() {
|
||||
setDirty(true)
|
||||
}
|
||||
|
||||
// 恢复内置默认。启动时的 seed 只补缺失、不覆盖已有,
|
||||
// 所以内置模板更新后必须从这里显式推一次
|
||||
async function reset() {
|
||||
if (!confirm(`把【${species === 'dog' ? '狗' : '猫'} · ${stage}】恢复成内置默认?当前改动会被覆盖。`)) return
|
||||
setGen(true)
|
||||
setMsg('')
|
||||
try {
|
||||
const data = await api.resetCareTemplate(species, stage)
|
||||
setItems(normalize(data.items))
|
||||
setDirty(false)
|
||||
setMsg('已恢复为内置默认模板')
|
||||
} catch (e: any) {
|
||||
setMsg(e.message || '恢复失败')
|
||||
} finally {
|
||||
setGen(false)
|
||||
}
|
||||
}
|
||||
|
||||
async function generate() {
|
||||
setGen(true)
|
||||
setMsg('')
|
||||
@@ -149,6 +167,9 @@ export default function CareTemplates() {
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" onClick={reset} disabled={gen}>
|
||||
<RotateCcw className="h-4 w-4" /> 恢复默认
|
||||
</Button>
|
||||
<Button variant="outline" onClick={generate} disabled={gen}>
|
||||
<Wand2 className="h-4 w-4" /> {gen ? '生成中…' : 'AI 生成草稿'}
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user