609f7d06cf
- pets-fe: 微信原生小程序(首页/计划/记录/报告/社区/引导), 服务端驱动、无假数据;弹层改用 scroll-view,打开时隐藏自定义 tabBar - pets-be: Gin + GORM(MySQL, sundynix_ 前缀) + MinIO,统一响应/分页, 微信 code2session 登录,provider-neutral AI(DeepSeek),go:embed React 后台 - 修复:分段选择类型不匹配(字符串 vs 数字)导致选不中 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
80 lines
1.9 KiB
JavaScript
80 lines
1.9 KiB
JavaScript
const store = require('../../utils/store.js');
|
||
const api = require('../../utils/api.js');
|
||
|
||
function pad(n) {
|
||
return n < 10 ? '0' + n : '' + n;
|
||
}
|
||
function fmtTime(iso) {
|
||
if (!iso) return '';
|
||
const d = new Date(iso);
|
||
const now = new Date();
|
||
const hm = pad(d.getHours()) + ':' + pad(d.getMinutes());
|
||
if (d.toDateString() === now.toDateString()) return '今天 ' + hm;
|
||
const y = new Date(now.getTime() - 86400000);
|
||
if (d.toDateString() === y.toDateString()) return '昨天 ' + hm;
|
||
return d.getMonth() + 1 + '月' + d.getDate() + '日';
|
||
}
|
||
function mapRecord(r) {
|
||
return {
|
||
icon: r.icon || '✍️',
|
||
title: r.title,
|
||
desc: fmtTime(r.occurred_at) + (r.description ? '|' + r.description : ''),
|
||
};
|
||
}
|
||
|
||
Page({
|
||
data: {
|
||
pet: {},
|
||
timeline: [],
|
||
sheetShow: false,
|
||
sheetType: '',
|
||
},
|
||
onLoad() {
|
||
this._unsub = store.subscribe((pet) => {
|
||
this.setData({ pet });
|
||
this.loadRecords();
|
||
});
|
||
},
|
||
onUnload() {
|
||
if (this._unsub) this._unsub();
|
||
},
|
||
onShow() {
|
||
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
||
this.getTabBar().setData({ selected: 2 });
|
||
}
|
||
store
|
||
.ready()
|
||
.then(() => {
|
||
this.setData({ pet: store.getPet() });
|
||
this.loadRecords();
|
||
})
|
||
.catch((e) => wx.showToast({ title: e.message || '加载失败', icon: 'none' }));
|
||
},
|
||
loadRecords() {
|
||
const id = store.currentPetId();
|
||
if (!id) return;
|
||
api
|
||
.getRecords(id)
|
||
.then((records) => this.setData({ timeline: (records || []).map(mapRecord) }))
|
||
.catch(() => {});
|
||
},
|
||
openSheet(e) {
|
||
this.openSheetType(e.currentTarget.dataset.type);
|
||
},
|
||
openSheetType(type) {
|
||
this.setData({ sheetType: type, sheetShow: true });
|
||
},
|
||
closeSheet() {
|
||
this.setData({ sheetShow: false });
|
||
},
|
||
onSheetSaved() {
|
||
this.loadRecords();
|
||
},
|
||
onAddPet() {
|
||
this.openSheetType('addPet');
|
||
},
|
||
onFab() {
|
||
this.openSheetType('ai');
|
||
},
|
||
});
|