feat(fe): Phase D —— 主页装扮,「我的」和「宠友主页」共用一套渲染

## profile-head 组件
头图 / 头像 / 昵称 / 签名 / 帖子关注粉丝 / 养宠数据 / 宠物名片墙,
pages/mine 和 pages/user 用的是同一个组件、同一个接口
(GET /users/:id/profile)。

这件事必须一开始就做对:自己看和别人看要是两套渲染,会慢慢长歪,
装扮功能也就失去意义了——你调半天颜色,结果只有自己那页变了。
两边唯一的差别是底部按钮:自己看是「装扮我的主页」,别人看是「关注 TA」。

顺带把 mine 的头部从 /user/summary 切到了 /users/:id/profile。原来两边
字段对不上,装扮效果在「我的」页根本预览不到。

主题只在组件 wxss 里定义 --pf-a/--pf-b/--pf-ink 三个变量,下面所有着色
都走变量。后端存 key 不存色值,就是为了这套配色随时能在前端改。

## pages/decorate 装扮页
头图上传 / 五套主题色 / 个性签名 60 字 / 宠物墙开关,顶部实时预览。

预览用的就是 profile-head 本身,不是仿一个——仿的迟早会和真的长得不一样。
喂给它一份改过的 card 就行,组件那边不需要知道自己在被预览。

头图有个坑单独处理了:bg_file_id 只在真动过的时候才传。新上传带新 id,
点「恢复默认渐变」带空串,都没动就不传字段。否则「只改个主题色」会把
已有头图冲掉。上传时先用本地临时路径顶上,不让用户对着转圈等。

联调验证(本地 9090,真上传了一张图走完存储链路):
  上传             → file id + MinIO url
  保存装扮          → bg_url 落库,主题 violet,签名落库
  主页读回          → bio/theme/show_pets/bg_url/宠物墙/养宠数据 全对
  只改主题          → theme 变 sky,头图还在(没被冲掉)
  恢复默认渐变       → bg_url 清空,theme 和 bio 都没被动
  别人视角          → is_self=false、followed=false,装扮和宠物墙都能看到

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-07-29 18:02:07 +08:00
parent 8606c1dfc8
commit 1584aabcc5
18 changed files with 426 additions and 100 deletions
+18 -13
View File
@@ -3,7 +3,7 @@ const api = require('../../utils/api.js');
const { toastErr } = require('../../utils/ui.js');
Page({
data: { user: {}, pets: [], summary: {}, initial: '', sheetShow: false, sheetType: '' },
data: { user: {}, pets: [], card: null, sheetShow: false, sheetType: '' },
onLoad() {
this._unsub = store.subscribe(() => this.applyUser());
},
@@ -15,19 +15,21 @@ Page({
.ready()
.then(() => {
this.applyUser();
this.loadSummary();
this.loadCard();
})
.catch((e) => toastErr(e));
},
applyUser() {
const user = store.getUser() || {};
// WXML 取不了字符串下标,首字在这里算
this.setData({ pets: store.getPets(), user, initial: (user.nickname || '?').slice(0, 1) });
this.setData({ pets: store.getPets(), user: store.getUser() || {} });
},
loadSummary() {
// 头部数据走 /users/:id/profile,和别人看我时是同一个接口——
// 换成 /user/summary 的话两边字段会对不上,装扮效果也预览不到
loadCard() {
const uid = (this.data.user && this.data.user.id) || '';
if (!uid) return;
api
.userSummary()
.then((summary) => this.setData({ summary }))
.userCard(uid)
.then((card) => this.setData({ card }))
.catch(() => {});
},
// 看自己的公开主页,和别人看到的是同一个页面、同一套渲染
@@ -41,16 +43,19 @@ Page({
goRelations(e) {
const uid = (this.data.user && this.data.user.id) || '';
if (!uid) return wx.showToast({ title: '登录信息还没就绪', icon: 'none' });
wx.navigateTo({ url: `/pages/relations/relations?id=${uid}&kind=${e.currentTarget.dataset.kind}` });
wx.navigateTo({ url: `/pages/relations/relations?id=${uid}&kind=${e.detail.kind}` });
},
goDecorate() {
wx.navigateTo({ url: '/pages/decorate/decorate' });
},
goPlan() {
wx.navigateTo({ url: '/pages/plan/plan' });
},
goRecord() {
wx.switchTab({ url: '/pages/record/record' });
},
// 列表行传 dataset,宠物名片墙传 detail,两边都进这里
onPickPet(e) {
store.switchPet(e.currentTarget.dataset.id);
const id = (e.detail && e.detail.id) || e.currentTarget.dataset.id;
if (!id) return;
store.switchPet(id);
wx.switchTab({ url: '/pages/home/home' });
},
openSheet(e) {
+2 -1
View File
@@ -3,6 +3,7 @@
"nav-bar": "/components/nav-bar/nav-bar",
"bottom-sheet": "/components/bottom-sheet/bottom-sheet",
"fab": "/components/fab/fab",
"pt-icon": "/components/pt-icon/index"
"pt-icon": "/components/pt-icon/index",
"profile-head": "/components/profile-head/index"
}
}
+6 -29
View File
@@ -2,35 +2,12 @@
<scroll-view class="page-scroll" scroll-y="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}">
<view class="page-body">
<!-- 个人名片。点进去看的是「别人眼里的我」,和 pages/user 同一个页面 -->
<view class="card me-card">
<view class="me-top">
<view class="me-av">
<image wx:if="{{user.avatar_url}}" class="me-av-img" src="{{user.avatar_url}}" mode="aspectFill"></image>
<block wx:else>{{initial}}</block>
</view>
<view class="me-main">
<view class="me-name">{{user.nickname || '毛孩子家长'}}</view>
<view class="me-bio">{{user.bio || '还没有个性签名'}}</view>
</view>
<view class="me-gear" catchtap="goSettings"><pt-icon name="settings" size="{{36}}"></pt-icon></view>
</view>
<!-- 和「宠友主页」同一个组件。自己看到的就是别人看到的,装扮才有意义 -->
<profile-head card="{{card}}" bind:relations="goRelations"
bind:decorate="goDecorate" bind:pet="onPickPet"></profile-head>
<view class="me-stats">
<view class="me-stat" data-kind="following" bindtap="goRelations">
<text class="me-n">{{summary.following || 0}}</text><text class="me-l">关注</text>
</view>
<view class="me-stat" data-kind="followers" bindtap="goRelations">
<text class="me-n">{{summary.followers || 0}}</text><text class="me-l">粉丝</text>
</view>
<view class="me-stat" bindtap="goRecord">
<text class="me-n">{{summary.records || 0}}</text><text class="me-l">记录</text>
</view>
</view>
<view class="btn btn-ghost btn-block" bindtap="previewPublic">
<pt-icon name="user" size="{{30}}"></pt-icon>看看别人眼里的我
</view>
<view class="btn btn-ghost btn-block me-preview" bindtap="previewPublic">
<pt-icon name="user" size="{{30}}"></pt-icon>看看别人眼里的我
</view>
<!-- 我的毛孩子 -->
@@ -62,7 +39,7 @@
</view>
<view class="profile-row" data-type="managePets" bindtap="openSheet">
<view class="pr-ic"><pt-icon name="community" size="{{34}}"></pt-icon></view>
<text class="pr-label">多宠物管理</text><text class="pr-val">{{summary.pets || 0}} 只</text>
<text class="pr-label">多宠物管理</text><text class="pr-val">{{card.stats.pet_count || 0}} 只</text>
<view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view>
</view>
<view class="profile-row" bindtap="goSettings">
+2 -16
View File
@@ -1,19 +1,3 @@
.me-card{padding:var(--sp-5)}
.me-top{display:flex;align-items:center;gap:var(--sp-3)}
.me-av{
width:110rpx;height:110rpx;border-radius:50%;flex:none;overflow:hidden;
display:flex;align-items:center;justify-content:center;
background:var(--primary-soft);color:var(--primary-ink);font-size:44rpx;font-weight:var(--fw-b);
}
.me-av-img{width:100%;height:100%}
.me-main{flex:1;min-width:0}
.me-name{font-size:var(--fs-lg);font-weight:var(--fw-b)}
.me-bio{color:var(--muted);font-size:var(--fs-sm);margin-top:6rpx}
.me-gear{flex:none;color:var(--muted)}
.me-stats{display:flex;margin:var(--sp-4) 0}
.me-stat{flex:1;display:flex;flex-direction:column;align-items:center;gap:4rpx}
.me-n{font-size:var(--fs-lg);font-weight:var(--fw-b)}
.me-l{font-size:var(--fs-cap);color:var(--muted)}
.pet-row{display:flex;align-items:center;gap:var(--sp-3);padding:var(--sp-3) 0;border-bottom:1rpx solid var(--line)}
.pet-row:last-child{border-bottom:0}
@@ -23,3 +7,5 @@
background:var(--primary-soft);font-size:40rpx;
}
.pet-info{flex:1;min-width:0}
.me-preview{margin-bottom:var(--sp-5)}