0dee6e27d2
报告页 → 分享卡片,弹层底部那个「保存 / 分享卡片」按钮绑的是 bindtap="close" —— 点了只是把弹层关掉,既不保存也不分享。按钮文案 承诺了两件事,一件也没做。 拆成两个真按钮: - 分享给朋友:走微信原生 open-type="share",转发标题带上宠物名 - 保存到相册:把海报画进离屏 canvas 再存相册 canvas 部分的几个坑: - 画布用 position:fixed 挪到屏幕外,不能 display:none —— 那样 selectorQuery 取不到节点 - 按 pixelRatio 放大再 scale,否则高分屏上导出的图是糊的 - 相册权限被拒过一次后 wx.authorize 不会再弹,必须 wx.openSetting 引导,否则这里会永远静默失败——正是这次要修的那类问题 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
74 lines
2.0 KiB
JavaScript
74 lines
2.0 KiB
JavaScript
const store = require('../../utils/store.js');
|
|
const api = require('../../utils/api.js');
|
|
|
|
Page({
|
|
data: {
|
|
pet: {},
|
|
report: null,
|
|
gainText: '+0.0',
|
|
bill: null,
|
|
summary: null,
|
|
sheetShow: false,
|
|
sheetType: '',
|
|
},
|
|
onLoad() {
|
|
this._unsub = store.subscribe((pet) => {
|
|
this.setData({ pet });
|
|
if (!this._inited) return; // 首次由 onShow 加载
|
|
this.loadData();
|
|
});
|
|
},
|
|
onUnload() {
|
|
if (this._unsub) this._unsub();
|
|
},
|
|
onShow() {
|
|
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
|
this.getTabBar().setData({ selected: 3 });
|
|
}
|
|
store
|
|
.ready()
|
|
.then(() => {
|
|
this._inited = true;
|
|
this.setData({ pet: store.getPet() });
|
|
this.loadData();
|
|
})
|
|
.catch((e) => wx.showToast({ title: e.message || '加载失败', icon: 'none' }));
|
|
},
|
|
loadData() {
|
|
const id = store.currentPetId();
|
|
if (!id) return;
|
|
Promise.all([api.weeklyReport(id), api.getBill(id, 'month'), api.healthSummary(id)])
|
|
.then(([report, bill, summary]) => {
|
|
const g = report.weight_gain || 0;
|
|
this.setData({
|
|
report,
|
|
gainText: (g >= 0 ? '+' : '') + g.toFixed(1),
|
|
bill,
|
|
summary,
|
|
});
|
|
})
|
|
.catch(() => {});
|
|
},
|
|
openSheet(e) {
|
|
this.setData({ sheetType: e.currentTarget.dataset.type, sheetShow: true });
|
|
},
|
|
closeSheet() {
|
|
this.setData({ sheetShow: false });
|
|
},
|
|
onAddPet() {
|
|
this.setData({ sheetType: 'addPet', sheetShow: true });
|
|
},
|
|
onFab() {
|
|
wx.navigateTo({ url: '/pages/ai/ai' });
|
|
},
|
|
onShareAppMessage() {
|
|
// 带上宠物名,转发出去别人一眼知道是谁家的
|
|
const n = (this.data.pet && this.data.pet.name) || '我家毛孩子';
|
|
return { title: `${n} 的成长报告`, path: '/pages/report/report' };
|
|
},
|
|
onShareTimeline() {
|
|
const n = (this.data.pet && this.data.pet.name) || '我家毛孩子';
|
|
return { title: `${n} 的成长报告` };
|
|
},
|
|
});
|