refactor(be): 养护模板也从代码里移出,只从数据库读
和文章同一个理由:模板是运营内容,不是代码。留一套内置默认还额外带来 一个坏处——库里配的和代码里写的会悄悄分叉,出问题时分不清用户拿到的 到底是哪一套。 删掉: - builtinCat / builtinDog / builtinCareItems(8 套 × 96 条) - SeedCareTemplates(启动时写内置默认) - ResetCareTemplate + 后台「恢复默认」按钮 —— 已经没有默认可恢复 careTemplateItems 现在查不到就返回空。这意味着后台把某个组合配空了, 新用户会拿到一个什么都没有的首页而且不报错,所以 seedPetDefaults 里 加了一条 log:模板为空时打出 species/stage/petID,否则没人能发现。 「AI 生成草稿」原来在 AI 未开启或调用失败时静默返回内置默认,看起来 像是 AI 生成的。现在直接报错说清原因,让管理员知道要么开 AI 要么手填。 数据在库里,删代码不影响:预生产 8 套 96 条原样在,建档端到端复测通过 (3 月龄幼猫仍拿到「下一针疫苗·21 天后」,成年犬仍有疫苗驱虫提醒)。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { Cat, Dog, Wand2, Plus, Trash2, Save, Info, RotateCcw } from 'lucide-react'
|
||||
import { Cat, Dog, Wand2, Plus, Trash2, Save, Info } from 'lucide-react'
|
||||
import { api } from '@/lib/api'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Button } from '@/components/ui/button'
|
||||
@@ -106,24 +106,6 @@ 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('')
|
||||
@@ -167,9 +149,6 @@ 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