29d2cd3faf
## tabBar 首页 / 报告 / 社区 / 我的。记录不再是 tab。 因为高亮是 tabBar 组件按当前路由自己算的(Phase A 那次改的),删一个 tab 只需要动 LIST 一处,四个页面一行都没改。 ## 快速记录独立成页 —— 但没有新建页面 弹层里塞 24 项确实挤(用户原话「很丑」)。撤掉上一版加的 quickRecord 分支。 **pages/record/record 本身就是那个页面**:它顶部已经是 24 项 4 组宫格, 下面接着健康洞察、体重趋势、健康时间轴。再单独建一个只放宫格的页面,等于同一个 宫格维护两份,而且那页除了宫格什么都没有,进去点一下就得退出来。 所以把它从 tab 降级成二级页:nav 标题从「快速记录」改成「记录」+ 返回键, 移除 tabBar 同步。首页右下角悬浮键直接跳它,落地就是宫格。 pet-switch 保留 —— 时间轴/趋势/洞察都是按宠物看的,而且计划页作为二级页 也是这么处理的,一致。 ## 入口 首页悬浮键 → 记录页(全部 24 项) 首页「快速记录」卡 → 8 个高频项直接开表单,「更多」→ 记录页 文章页 / 设置页 → 记录页 三处 switchTab 改成 navigateTo(记录页已经不是 tab,switchTab 会静默失败)。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
80 lines
2.5 KiB
JavaScript
80 lines
2.5 KiB
JavaScript
const store = require('../../utils/store.js');
|
|
const api = require('../../utils/api.js');
|
|
const upload = require('../../utils/upload.js');
|
|
|
|
function completion(pet) {
|
|
if (!pet) return 0;
|
|
const fields = ['name', 'emoji', 'type', 'gender', 'birthday', 'weight', 'stage', 'age', 'color', 'breed'];
|
|
const filled = fields.filter((f) => pet[f]).length;
|
|
return Math.round((filled / fields.length) * 100);
|
|
}
|
|
|
|
Page({
|
|
data: {
|
|
pet: {},
|
|
user: {},
|
|
summary: { pets: 0, records: 0, reminders: 0, pro_status: 'none' },
|
|
profilePct: 0,
|
|
sheetShow: false,
|
|
sheetType: '',
|
|
},
|
|
onLoad() {
|
|
this._unsub = store.subscribe((pet) => this.setData({ pet, profilePct: completion(pet) }));
|
|
},
|
|
onUnload() {
|
|
if (this._unsub) this._unsub();
|
|
},
|
|
onShow() {
|
|
store
|
|
.ready()
|
|
.then(() => {
|
|
const pet = store.getPet();
|
|
this.setData({ pet, user: store.getUser() || {}, profilePct: completion(pet) });
|
|
this.loadSummary();
|
|
})
|
|
.catch((e) => wx.showToast({ title: e.message || '加载失败', icon: 'none' }));
|
|
},
|
|
loadSummary() {
|
|
api.userSummary().then((summary) => this.setData({ summary })).catch(() => {});
|
|
},
|
|
openSheet(e) {
|
|
this.setData({ sheetType: e.currentTarget.dataset.type, sheetShow: true });
|
|
},
|
|
// 自己的关注/粉丝。之前只有帖子上的「+关注」按钮,关注完没有任何地方能看
|
|
goRelations(e) {
|
|
const uid = (this.data.user && this.data.user.id) || '';
|
|
if (!uid) return wx.showToast({ title: '登录信息还没就绪', icon: 'none' });
|
|
wx.navigateTo({ url: `/pages/relations/relations?id=${uid}&kind=${e.currentTarget.dataset.kind}` });
|
|
},
|
|
goRecord() {
|
|
wx.navigateTo({ url: '/pages/record/record' });
|
|
},
|
|
onPickAvatar() {
|
|
upload
|
|
.chooseAndUploadImage()
|
|
.then((f) => api.updateProfile({ avatar_file_id: f.id }))
|
|
.then((user) => {
|
|
this.setData({ user });
|
|
store.setUser(user);
|
|
wx.showToast({ title: '头像已更新', icon: 'success' });
|
|
})
|
|
.catch((e) => {
|
|
if (e && e.canceled) return;
|
|
wx.showToast({ title: (e && e.message) || '上传失败', icon: 'none' });
|
|
});
|
|
},
|
|
onAddPet() {
|
|
this.setData({ sheetType: 'addPet', sheetShow: true });
|
|
},
|
|
onEditPet() {
|
|
this.setData({ sheetType: 'editPet', sheetShow: true });
|
|
},
|
|
closeSheet() {
|
|
this.setData({ sheetShow: false });
|
|
this.loadSummary();
|
|
},
|
|
onShareAppMessage() {
|
|
return { title: '肉垫计划 · 新手养宠助手', path: '/pages/home/home' };
|
|
},
|
|
});
|