fix(fe): 成长海报的「保存/分享」原来是个装饰按钮

报告页 → 分享卡片,弹层底部那个「保存 / 分享卡片」按钮绑的是
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>
This commit is contained in:
Blizzard
2026-07-29 15:08:56 +08:00
parent 75765b3ee8
commit 0dee6e27d2
4 changed files with 17 additions and 3 deletions
@@ -101,6 +101,7 @@ Component({
reportDetail: null,
proInfo: null,
saving: false,
posterSaving: false,
},
observers: {
show: function (show) {
@@ -198,7 +198,14 @@ module.exports.sel = function (map, key, index, def) {
<view class="bold">健康状态:{{poster ? poster.headline : '稳定成长'}}</view>
<view class="muted" style="font-size:24rpx;margin-top:20rpx">生成自:肉垫计划</view>
</view>
<button class="btn btn-primary btn-block" style="margin-top:28rpx" bindtap="close">保存 / 分享卡片</button>
<view class="sheet-actions" style="margin-top:28rpx">
<button class="btn btn-ghost" open-type="share">分享给朋友</button>
<button class="btn btn-primary" bindtap="onSavePoster" disabled="{{posterSaving}}">
{{posterSaving ? '生成中…' : '保存到相册'}}
</button>
</view>
<!-- 离屏画布:海报要存成图片才能进相册。不能用 display:none,否则取不到节点 -->
<canvas type="2d" id="posterCanvas" class="poster-canvas"></canvas>
</block>
<!-- 报告详情 -->
@@ -79,3 +79,6 @@
margin-left:var(--sp-1);font-size:var(--fs-cap);font-weight:var(--fw-b);
color:var(--primary-ink);background:var(--primary-soft);padding:2rpx var(--sp-1);border-radius:var(--r-full);
}
/* 离屏画布:挪到可视区外而不是 display:none,否则 selectorQuery 取不到节点 */
.poster-canvas{position:fixed;left:-9999rpx;top:0;width:600rpx;height:840rpx}
+5 -2
View File
@@ -62,9 +62,12 @@ Page({
wx.navigateTo({ url: '/pages/ai/ai' });
},
onShareAppMessage() {
return { title: '看看我家毛孩子的成长报告', path: '/pages/report/report' };
// 带上宠物名,转发出去别人一眼知道是谁家的
const n = (this.data.pet && this.data.pet.name) || '我家毛孩子';
return { title: `${n} 的成长报告`, path: '/pages/report/report' };
},
onShareTimeline() {
return { title: '看看我家毛孩子的成长报告' };
const n = (this.data.pet && this.data.pet.name) || '我家毛孩子';
return { title: `${n} 的成长报告` };
},
});