feat: 补齐关注的入口——用户主页 + 关注/粉丝列表

关注之前只做了一半:能从帖子上点「+关注」,也有「关注」信息流,但
关注完就石沉大海——没有用户主页、看不到自己关注了谁、也不知道谁关注
了自己。功能是通的,路是断的。

后端新增:
- GET /api/users/:id/profile  公开资料 + 帖子/关注/粉丝三个计数 + 我是否已关注
- GET /api/users/:id/posts    TA 发布的帖子
- GET /api/users/:id/relations?kind=following|followers
- /api/user/summary 补 following / followers,否则「我的」页那两行永远是 0

关系列表里「我是否关注了这批人」用一次 IN 查询查完,不是每行一次。

小程序端新增两个页面:
- pages/user/user      用户主页:头像/昵称/三项计数/关注按钮 + TA 的帖子
- pages/relations      关注列表与粉丝列表(同一页,kind 区分)

入口:
- 社区点头像或昵称 → TA 的主页
- 主页点「关注/粉丝」数字 → 对应列表
- 「我的」页新增「我的关注」「我的粉丝」两行

关注按钮先本地翻转再发请求,失败回滚——等接口返回按钮才变会显得很迟钝。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-07-29 17:13:04 +08:00
parent b8b3ba99b4
commit 25f655a6fc
18 changed files with 415 additions and 3 deletions
+41
View File
@@ -0,0 +1,41 @@
const api = require('../../utils/api.js');
const { toastErr } = require('../../utils/ui.js');
Page({
data: { uid: '', kind: 'following', title: '关注', list: [], page: 1, hasMore: false, loaded: false },
onLoad(q) {
const kind = q && q.kind === 'followers' ? 'followers' : 'following';
this.setData({ uid: (q && q.id) || '', kind, title: kind === 'followers' ? '粉丝' : '关注' });
this.load(1);
},
load(page) {
api
.relations(this.data.uid, this.data.kind, page)
.then((res) => {
const merged = page === 1 ? res.list || [] : this.data.list.concat(res.list || []);
this.setData({ list: merged, page, loaded: true, hasMore: merged.length < (res.total || 0) });
})
.catch((e) => {
this.setData({ loaded: true });
toastErr(e);
});
},
loadMore() {
if (this.data.hasMore) this.load(this.data.page + 1);
},
goUser(e) {
wx.navigateTo({ url: `/pages/user/user?id=${e.currentTarget.dataset.id}` });
},
// 同样先本地翻转再发请求,失败回滚
toggleFollow(e) {
const i = e.currentTarget.dataset.index;
const u = this.data.list[i];
if (!u || u.is_self) return;
const next = !u.followed;
this.setData({ [`list[${i}].followed`]: next });
(next ? api.followUser(u.id) : api.unfollowUser(u.id)).catch((err) => {
this.setData({ [`list[${i}].followed`]: !next });
toastErr(err, '操作失败');
});
},
});
+6
View File
@@ -0,0 +1,6 @@
{
"usingComponents": {
"nav-bar": "/components/nav-bar/nav-bar",
"pt-icon": "/components/pt-icon/index"
}
}
+20
View File
@@ -0,0 +1,20 @@
<nav-bar title="{{title}}" show-back="{{true}}"></nav-bar>
<scroll-view class="page-scroll" scroll-y="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}"
bindscrolltolower="loadMore">
<view class="page-body no-fab">
<view wx:for="{{list}}" wx:key="id" class="rel" bindtap="goUser" data-id="{{item.id}}">
<view class="rel-av">
<image wx:if="{{item.avatar_url}}" class="rel-av-img" src="{{item.avatar_url}}" mode="aspectFill"></image>
<block wx:else>{{item.nickname[0]}}</block>
</view>
<view class="rel-name">{{item.nickname}}<text wx:if="{{item.is_bot}}" class="ai-tag">AI</text></view>
<view wx:if="{{!item.is_self}}" class="follow-btn {{item.followed ? 'on' : ''}}"
catchtap="toggleFollow" data-index="{{index}}">{{item.followed ? '已关注' : '+ 关注'}}</view>
</view>
<view wx:if="{{loaded && !list.length}}" class="empty lg">
{{kind === 'followers' ? '还没有人关注 TA' : '还没有关注任何人,去宠友圈逛逛'}}
</view>
</view>
</scroll-view>
+12
View File
@@ -0,0 +1,12 @@
.rel{
display:flex;align-items:center;gap:var(--sp-3);
background:#fff;border-radius:var(--r-md);box-shadow:var(--sd-1);
padding:var(--sp-3) var(--sp-4);margin-bottom:var(--sp-2);
}
.rel-av{
width:80rpx;height:80rpx;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:var(--fs-lg);font-weight:var(--fw-b);
}
.rel-av-img{width:100%;height:100%}
.rel-name{flex:1;min-width:0;font-size:var(--fs-md);font-weight:var(--fw-b)}