const store = require('../../utils/store.js'); const recordTypes = require('../../utils/recordTypes.js'); // 这一页只干一件事:把后端配置的记录事项按分组列出来,点一个进添加页。 // 原来它还带着健康洞察、体重趋势、健康时间轴——那三块搬到 pages/history 了, // 从报告页进。一个「我要记一笔」的页面上摆着三块只读图表, // 用户每次都得先滚过去才能找到要点的东西。 // tone-N 只给格子用(它自带背景色);组标题的颜色走 g-N。 // short 是去掉「记录」后缀的组名——「日常记录」在标题位置念着啰嗦 const G = { 'tone-1': 'g-1', 'tone-2': 'g-2', 'tone-3': 'g-3', 'tone-4': 'g-4' }; function decorate(g) { return { ...g, g: G[g.tone] || 'g-1', short: (g.label || '').replace(/记录$/, '') }; } Page({ data: { pet: {}, typeGroups: [], sheetShow: false, sheetType: '' }, onLoad() { this._unsub = store.subscribe((pet) => this.setData({ pet })); }, onUnload() { if (this._unsub) this._unsub(); }, onShow() { this.loadTypes(); store .ready() .then(() => this.setData({ pet: store.getPet() })) .catch((e) => wx.showToast({ title: e.message || '加载失败', icon: 'none' })); }, loadTypes() { if (this.data.typeGroups.length) return; recordTypes .load() .then((groups) => this.setData({ typeGroups: groups.map(decorate) })) .catch(() => {}); }, goAdd(e) { wx.navigateTo({ url: '/pages/addrecord/addrecord?type=' + e.currentTarget.dataset.type }); }, // 没建档时要能建档,所以这页留一个只用于 addPet 的弹层 onAddPet() { wx.navigateTo({ url: '/pages/petform/petform' }); }, closeSheet() { this.setData({ sheetShow: false }); }, onShareAppMessage() { return { title: '用肉垫计划记录毛孩子的成长', path: '/pages/record/record' }; }, onShareTimeline() { return { title: '用肉垫计划记录毛孩子的成长' }; }, });