diff --git a/pets-fe/components/bottom-sheet/bottom-sheet.js b/pets-fe/components/bottom-sheet/bottom-sheet.js
index 6694adc..cde30cf 100644
--- a/pets-fe/components/bottom-sheet/bottom-sheet.js
+++ b/pets-fe/components/bottom-sheet/bottom-sheet.js
@@ -207,6 +207,18 @@ Component({
const pet = this.data.pet || {};
const p = this.data.poster || {};
+ // 头像是远程图,异步加载。加载完(或没有头像)再往下画,
+ // 否则头像会画不上。加载失败当没有头像处理
+ const loadAvatar = () =>
+ new Promise((res) => {
+ if (!pet.avatar_url) return res(null);
+ const img = node.createImage();
+ img.onload = () => res(img);
+ img.onerror = () => res(null);
+ img.src = pet.avatar_url;
+ });
+
+ loadAvatar().then((avatar) => {
const bg = ctx.createLinearGradient(0, 0, W, H);
bg.addColorStop(0, '#FFF7E8');
bg.addColorStop(1, '#FFFFFF');
@@ -220,9 +232,22 @@ Component({
ctx.font = '600 40px sans-serif';
ctx.fillText((pet.name || '毛孩子') + ' 的成长报告', W / 2, 96);
- ctx.font = '96px sans-serif';
- ctx.fillText(pet.emoji || '🐾', W / 2, 216);
+ // 上传过照片就画圆形头像,没有才退回 emoji(默认头像太丑)
+ const avD = 132, avX = (W - avD) / 2, avY = 132;
+ if (avatar) {
+ ctx.save();
+ ctx.beginPath();
+ ctx.arc(W / 2, avY + avD / 2, avD / 2, 0, Math.PI * 2);
+ ctx.closePath();
+ ctx.clip();
+ ctx.drawImage(avatar, avX, avY, avD, avD);
+ ctx.restore();
+ } else {
+ ctx.font = '96px sans-serif';
+ ctx.fillText(pet.emoji || '🐾', W / 2, 216);
+ }
+ ctx.textAlign = 'center';
ctx.fillStyle = '#8D8277';
ctx.font = '24px sans-serif';
ctx.fillText([pet.age, pet.weight, pet.stage].filter(Boolean).join(' | '), W / 2, 268);
@@ -255,7 +280,7 @@ Component({
ctx.font = '22px sans-serif';
ctx.fillText('生成自 · 肉垫计划', W / 2, 780);
- // canvas 2d 是同步绘制,画完直接导出
+ // 头像加载完(或没有)才走到这里,此刻画布已完整
wx.canvasToTempFilePath(
{
canvas: node,
@@ -265,6 +290,7 @@ Component({
},
this,
);
+ }); // loadAvatar().then
});
});
},
diff --git a/pets-fe/components/pet-switch/pet-switch.wxml b/pets-fe/components/pet-switch/pet-switch.wxml
index 4907990..092ec9f 100644
--- a/pets-fe/components/pet-switch/pet-switch.wxml
+++ b/pets-fe/components/pet-switch/pet-switch.wxml
@@ -2,7 +2,10 @@
- {{item.emoji}}{{item.name}}
+
+
+ {{item.emoji}}
+ {{item.name}}
添加
diff --git a/pets-fe/components/pet-switch/pet-switch.wxss b/pets-fe/components/pet-switch/pet-switch.wxss
index 6c71022..7614a6e 100644
--- a/pets-fe/components/pet-switch/pet-switch.wxss
+++ b/pets-fe/components/pet-switch/pet-switch.wxss
@@ -3,3 +3,5 @@
}
.pet-switch .pet-chip{margin-right:20rpx}
.pet-switch .pet-chip:last-child{margin-right:0}
+.mini-avatar{overflow:hidden}
+.mini-avatar-img{width:100%;height:100%;display:block}
diff --git a/pets-fe/pages/home/home.js b/pets-fe/pages/home/home.js
index 52b4b40..ee6953c 100644
--- a/pets-fe/pages/home/home.js
+++ b/pets-fe/pages/home/home.js
@@ -199,6 +199,16 @@ Page({
},
// 去建档页改阶段。改完回来 onShow 会重新拉一次漂移状态,提示自然消失。
// 不在首页直接改:改阶段之后要不要套新方案是同一件事,放在一起做才连贯
+ // 点「一起生活的天数」空态,去建档页补到家日期
+ onDaysTap() {
+ const id = this.data.pet && this.data.pet.id;
+ if (!this.data.daysTogether && id) wx.navigateTo({ url: '/pages/petform/petform?id=' + id });
+ },
+ // 身份卡:门面卡右上角进,用当前宠物
+ goIDCard() {
+ const id = this.data.pet && this.data.pet.id;
+ if (id) wx.navigateTo({ url: '/pages/idcard/idcard?id=' + id });
+ },
goStageUpdate() {
const id = this.data.pet && this.data.pet.id;
if (id) wx.navigateTo({ url: '/pages/petform/petform?id=' + id });
diff --git a/pets-fe/pages/home/home.wxml b/pets-fe/pages/home/home.wxml
index 7465beb..964ee0e 100644
--- a/pets-fe/pages/home/home.wxml
+++ b/pets-fe/pages/home/home.wxml
@@ -21,9 +21,15 @@
{{zodiac}}
-
+
+ 身份卡
+
+
+
+
+ 我们一起生活的第 {{daysTogether}} 天
+ 还没填到家日期,一起生活的天数显示 -
- 我们一起生活的第 {{daysTogether}} 天