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:
@@ -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' });
|
||||
|
||||
@@ -188,36 +188,8 @@ module.exports.sel = function (map, key, index, def) {
|
||||
</block>
|
||||
|
||||
<!-- 添加宠物 -->
|
||||
<block wx:elif="{{innerType === 'addPet' || innerType === 'editPet'}}">
|
||||
<view class="sheet-h3">{{innerType === 'editPet' ? '编辑档案' : '添加毛孩子'}}</view>
|
||||
<view class="field"><label>名字</label><input class="input" placeholder="例如:布丁" placeholder-class="placeholder" value="{{addName}}" bindinput="onAddName"/></view>
|
||||
<view class="field"><label>类型</label><view class="seg">
|
||||
<view class="seg-btn {{u.sel(segSel,'addType',0,0)?'selected':''}}" data-group="addType" data-index="0" bindtap="onSeg">猫猫</view>
|
||||
<view class="seg-btn {{u.sel(segSel,'addType',1,0)?'selected':''}}" data-group="addType" data-index="1" bindtap="onSeg">狗狗</view>
|
||||
</view></view>
|
||||
<view class="field"><label>性别</label><view class="seg">
|
||||
<view class="seg-btn {{u.sel(segSel,'addGender',0,0)?'selected':''}}" data-group="addGender" data-index="0" bindtap="onSeg">男孩</view>
|
||||
<view class="seg-btn {{u.sel(segSel,'addGender',1,0)?'selected':''}}" data-group="addGender" data-index="1" bindtap="onSeg">女孩</view>
|
||||
<view class="seg-btn {{u.sel(segSel,'addGender',2,0)?'selected':''}}" data-group="addGender" data-index="2" bindtap="onSeg">不确定</view>
|
||||
</view></view>
|
||||
<view class="field"><label>生日 / 到家时间</label>
|
||||
<picker mode="date" value="{{addBirthday}}" bindchange="onAddBirthday">
|
||||
<view class="picker-box">{{addBirthday || '选择日期'}}</view>
|
||||
</picker></view>
|
||||
<view class="field"><label>毛色</label><input class="input" placeholder="例如:橘白 / 奶牛 / 黑" placeholder-class="placeholder" value="{{addColor}}" bindinput="onAddColor"/></view>
|
||||
<view class="field"><label>品种</label><input class="input" placeholder="例如:中华田园猫 / 柯基" placeholder-class="placeholder" value="{{addBreed}}" bindinput="onAddBreed"/></view>
|
||||
<view class="field"><label>当前体重</label><input class="input" placeholder="例如:2.8" placeholder-class="placeholder" type="digit" value="{{addWeight}}" bindinput="onAddWeight"/></view>
|
||||
<view class="field"><label>当前阶段</label><view class="mini-options">
|
||||
<view class="option {{u.sel(optSel,'addStage',0,0)?'selected':''}}" data-group="addStage" data-index="0" bindtap="onOpt">刚到家</view>
|
||||
<view class="option {{u.sel(optSel,'addStage',1,0)?'selected':''}}" data-group="addStage" data-index="1" bindtap="onOpt">幼年期</view>
|
||||
<view class="option {{u.sel(optSel,'addStage',2,0)?'selected':''}}" data-group="addStage" data-index="2" bindtap="onOpt">成年期</view>
|
||||
<view class="option {{u.sel(optSel,'addStage',3,0)?'selected':''}}" data-group="addStage" data-index="3" bindtap="onOpt">老年期</view>
|
||||
</view></view>
|
||||
<button class="btn btn-primary btn-block" bindtap="onPetSubmit">{{innerType === 'editPet' ? '保存修改' : '添加宠物'}}</button>
|
||||
<button wx:if="{{innerType === 'editPet'}}" class="btn btn-block del-btn" style="margin-top:16rpx" bindtap="onDeletePet">删除该宠物</button>
|
||||
</block>
|
||||
|
||||
<!-- 发布图文 -->
|
||||
<!-- 添加/编辑宠物已经整体搬到 pages/petform:三步向导(名字+头像 → 猫狗+品种
|
||||
→ 其他资料),品种从后端 breeds 表来、按首字母索引。弹层塞不下这些 -->
|
||||
<block wx:elif="{{innerType === 'createPost'}}">
|
||||
<view class="sheet-h3">发布图文</view>
|
||||
<view class="sheet-p">选择发布身份,分享你的养宠日常。</view>
|
||||
|
||||
Reference in New Issue
Block a user