feat: 建档改成三步向导页,品种改成后台可配的选择器

## pages/petform 三步向导
  ① 名字 + 传头像
  ② 猫还是狗 → 选品种
  ③ 性别 / 生日 / 到家日期 / 体重 / 毛色 / 阶段

**编辑时不分步**,一屏全放开:用户是来改某一项的,不该被按顺序走一遍。
同一个页面两种形态,靠 ?id= 区分。

每一步只校验这一步的东西。三步全填完才校验的话,用户在第三步才被告知
第一步没填名字,还得翻回去。

进度条没用 seg-tabs:那是「可以随意切」的语义,这里有顺序,
点第三步跳过前两步会拿到一份没名字的档案。

## 生日和到家日期分开
原来是一个「生日 / 到家时间」字段。领养的成年猫狗生日常常是不知道的,
而「一起生活了多少天」要按到家日算——合成一个字段两件事都说不准。
验过:到家 4 个月前 → 第 121 天;按生日算会是 801 天。

模型里 Birthday 和 ArrivedAt 本来就是两个字段,只是表单没露出来。

## 品种:自由文本 → 后台可配的选择器
原来品种是个输入框,用户手打「柯基」「柯基犬」「威尔士柯基」算三个品种,
以后想按品种做体重基准、常见病提示这类事就没法做。

新增 breeds 表,预置 34 种猫 + 45 种狗,按首字母分组、右侧 A-Z 索引跳转、
首字母吸顶。留了「不确定」——领养的串串确实说不出品种,逼着选一个只会
得到假数据。换物种会清掉已选品种(原来那个一定不对了)。

**首字母存字段不运行时算**:Go 没有标准拼音库,而多音字自动转常出错——
「藏獒」按 cang 还是 zang 分组、「柴犬」的柴,人来定比库来猜靠谱。
后台新增品种时手填这一位,服务端校验必须是单个 A-Z。

已有档案在用的品种不许删(删了那些档案的品种就变成查不到的字符串),
想隐藏用 enabled=false。同物种下不许重名——品种是统计口径,重名会把
同一种猫劈成两半。

预置数据自己填错了两条,实跑时看出来的:「苏格兰柯利犬」我按「柯利」
填了 K,应该按「苏格兰」算 S;「双血统边牧」根本不是品种,是血统描述。
seed 源和库里都改了。

## 弹层继续瘦
addPet/editPet 两支删掉,连带 10 个方法、ageFromBirthday/GENDERS/STAGES
和 5 个 add* 字段。累计(从记录表单搬走那次算起):
  js   1110 → 734 行
  wxml  485 → 307 行

多宠管理里「点某只去编辑」原来是 setType('editPet'),那支没了会开一个
空白弹层——改成关弹层再跳页。8 个页面的入口全换完,grep 无残留。

## 验证(预生产库实跑)
  品种接口   猫 34 种 16 个首字母、狗 45 种 17 个首字母;非法 species 返回 []
  建档      生日 / 到家日期 分别落库,品种毛色阶段都对
  编辑      只改名字,到家日期没被冲掉
  修正      柯利犬 K→S、双血统边牧已删

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-07-30 11:26:51 +08:00
parent 2aaae2b917
commit aefb1bc103
23 changed files with 748 additions and 166 deletions
+6 -125
View File
@@ -33,18 +33,6 @@ function fmtAgo(iso) {
return (sameYear ? '' : d.getFullYear() + '-') + p(d.getMonth() + 1) + '-' + p(d.getDate());
}
function ageFromBirthday(bday) {
if (!bday) return '';
const b = new Date(bday);
const now = new Date();
let months = (now.getFullYear() - b.getFullYear()) * 12 + (now.getMonth() - b.getMonth());
if (months < 0) months = 0;
return months < 24 ? months + '个月' : Math.floor(months / 12) + '岁';
}
const GENDERS = ['男孩', '女孩', '不确定'];
const STAGES = ['刚到家 0-30 天', '幼年期', '成年期', '老年期'];
// 任务可关联的记录弹层类型
// 任务能关联的记录类型。原来这里也是写死的 6 种,后台加了类型这个下拉里看不到,
// 于是「自定义任务关联新类型」这条路是断的。改成读同一份类型缓存
@@ -95,11 +83,6 @@ Component({
fbContent: '',
fbContact: '',
fbDone: false,
addName: '',
addBirthday: '',
addWeight: '',
addColor: '',
addBreed: '',
commentText: '',
comments: [],
reminders: [],
@@ -147,11 +130,6 @@ Component({
patch.fbContent = '';
patch.fbContact = '';
patch.fbDone = false;
patch.addName = '';
patch.addBirthday = '';
patch.addWeight = '';
patch.addColor = '';
patch.addBreed = '';
patch.commentText = '';
patch.commentImages = [];
patch.replyTo = {};
@@ -159,19 +137,6 @@ Component({
patch.kbHeight = 0;
patch.saving = false;
}
if (type === 'editPet') {
// 预填当前宠物档案
patch.addName = pet.name || '';
patch.addColor = pet.color || '';
patch.addBreed = pet.breed || '';
patch.addWeight = (pet.weight || '').replace('kg', '');
patch.addBirthday = pet.birthday ? String(pet.birthday).slice(0, 10) : '';
patch.segSel = {
addType: pet.type === '狗狗' ? 1 : 0,
addGender: Math.max(0, GENDERS.indexOf(pet.gender)),
};
patch.optSel = { addStage: Math.max(0, STAGES.indexOf(pet.stage)) };
}
this.setData(patch);
this.loadSheetData(type);
},
@@ -426,9 +391,13 @@ Component({
wx.showToast({ title: '已切换', icon: 'success' });
setTimeout(() => this.close(), 500);
},
// 多宠管理里点某只去编辑。editPet 那支已经搬到 pages/petform
// 这里必须关掉弹层再跳页 —— 留着 setType('editPet') 会开一个空白弹层
onEditPetFromList(e) {
store.switchPet(e.currentTarget.dataset.id);
this.setType('editPet', true);
const id = e.currentTarget.dataset.id;
store.switchPet(id);
this.close();
wx.navigateTo({ url: '/pages/petform/petform?id=' + id });
},
// ---- 导出健康档案 ----
@@ -618,11 +587,6 @@ Component({
arr.splice(i, 1);
this.setData({ postImages: arr });
},
onAddName(e) { this.setData({ addName: e.detail.value }); },
onAddBirthday(e) { this.setData({ addBirthday: e.detail.value }); },
onAddWeight(e) { this.setData({ addWeight: e.detail.value }); },
onAddColor(e) { this.setData({ addColor: e.detail.value }); },
onAddBreed(e) { this.setData({ addBreed: e.detail.value }); },
onCommentInput(e) { this.setData({ commentText: e.detail.value }); },
segIdx(group) {
@@ -669,89 +633,6 @@ Component({
onSave() {
this.createAndClose(this.buildRecord());
},
petFormBody() {
const isDog = this.segIdx('addType') === 1;
return {
name: (this.data.addName || '').trim(),
type: isDog ? '狗狗' : '猫猫',
emoji: isDog ? '🐶' : '🐱',
gender: GENDERS[this.segIdx('addGender')],
birthday: this.data.addBirthday,
weight: this.data.addWeight,
color: (this.data.addColor || '').trim(),
breed: (this.data.addBreed || '').trim(),
stage: STAGES[this.optIdx('addStage')],
age: ageFromBirthday(this.data.addBirthday),
};
},
// 添加/编辑 共用提交入口
onPetSubmit() {
if (this.data.innerType === 'editPet') return this.onEditPetSubmit();
return this.onAddPetSubmit();
},
async onAddPetSubmit() {
const body = this.petFormBody();
if (!body.name) return wx.showToast({ title: '请输入名字', icon: 'none' });
if (this.data.saving) return;
this.setData({ saving: true });
try {
await api.createPet(body);
await store.loadPets();
this.triggerEvent('petadded');
this.close();
} catch (e) {
wx.showToast({ title: e.message || '添加失败', icon: 'none' });
this.setData({ saving: false });
}
},
async onEditPetSubmit() {
const body = this.petFormBody();
if (!body.name) return wx.showToast({ title: '请输入名字', icon: 'none' });
const id = store.currentPetId();
if (!id) return this.close();
if (this.data.saving) return;
this.setData({ saving: true });
try {
await api.updatePet(id, body);
await store.loadPets();
this.triggerEvent('petadded');
this.close();
} catch (e) {
wx.showToast({ title: e.message || '保存失败', icon: 'none' });
this.setData({ saving: false });
}
},
onDeletePet() {
const id = store.currentPetId();
const name = this.data.pet.name || '这只宠物';
if (!id) return;
wx.showModal({
title: '删除宠物',
content: `删除「${name}」后,它的记录、计划、提醒都会一并移除,且不可恢复。确定删除吗?`,
confirmText: '删除',
confirmColor: '#EE7D73',
success: (res) => {
if (!res.confirm) return;
api
.deletePet(id)
.then(async () => {
await store.loadPets();
this.triggerEvent('petadded');
this.close();
if (store.getPets().length === 0) {
wx.reLaunch({ url: '/pages/onboarding/onboarding' });
}
})
.catch((e) => wx.showToast({ title: e.message || '删除失败', icon: 'none' }));
},
});
},
// 发帖
async onCreatePost() {
const content = (this.data.postContent || '').trim();
if (!content) return wx.showToast({ title: '写点什么吧', icon: 'none' });