Files
sundynix-pets/pets-fe/pages/relations/relations.js
T
Blizzard 3ad1516aa4 fix(fe): 按钮长文案撑爆 + 用户主页帖子没样式 + 首字头像空白
三个都是我上一轮引入或没顾上的。

## 「Pro 会员(即将开放)」把按钮撑爆

.btn 同时用了 flex 垂直居中和 line-height:96rpx。flex 已经负责居中了,
line-height 纯属多余,而且文案一换行就被这个固定行高顶到按钮外面——
「我的」页底部那颗按钮正好触发。改成 min-height + line-height:1.3,
按钮能随文案长高,短文案的高度不变。

## 用户主页的帖子没有任何样式

.post-card 那一整套只写在 pages/community/community.wxss 里,而页面级
wxss 不跨页生效,所以用户主页上的帖子退化成裸文本。整块提到 app.wxss。
顺带给主页的帖子补上作者行和标签,和社区保持一致。

## 头像圈里空白

WXML 表达式不支持字符串下标,{{nickname[0]}} 求值为空。改成在 js 里
slice 好再传给模板。

另外确认一下:粉丝列表本来就能点进主页——关注和粉丝共用 pages/relations
一个页面,每行都绑了 goUser,和关注列表走同一个 pages/user 主页。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-29 17:19:18 +08:00

44 lines
1.6 KiB
JavaScript

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) => {
// WXML 表达式不支持字符串下标,首字母得在这里算好
const list = (res.list || []).map((u) => ({ ...u, initial: (u.nickname || '?').slice(0, 1) }));
const merged = page === 1 ? list : this.data.list.concat(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, '操作失败');
});
},
});