3ad1516aa4
三个都是我上一轮引入或没顾上的。
## 「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>
91 lines
3.0 KiB
JavaScript
91 lines
3.0 KiB
JavaScript
const api = require('../../utils/api.js');
|
|
const { toastErr } = require('../../utils/ui.js');
|
|
|
|
const TAG_CLASS = { 求助: 'warn', 经验: 'blue', 精选: 'purple', 避坑: 'red', 晒宠: '' };
|
|
|
|
function fmtAgo(iso) {
|
|
if (!iso) return '';
|
|
const d = new Date(iso);
|
|
if (isNaN(d.getTime())) return '';
|
|
const min = Math.floor((Date.now() - d.getTime()) / 60000);
|
|
if (min < 1) return '刚刚';
|
|
if (min < 60) return min + ' 分钟前';
|
|
if (min < 60 * 24) return Math.floor(min / 60) + ' 小时前';
|
|
if (min < 60 * 24 * 7) return Math.floor(min / 1440) + ' 天前';
|
|
const p = (n) => (n < 10 ? '0' + n : '' + n);
|
|
return p(d.getMonth() + 1) + '-' + p(d.getDate());
|
|
}
|
|
|
|
Page({
|
|
data: { uid: '', card: null, posts: [], page: 1, hasMore: false, loading: true },
|
|
onLoad(q) {
|
|
const uid = q && q.id;
|
|
if (!uid) return wx.showToast({ title: '缺少用户', icon: 'none' });
|
|
this.setData({ uid });
|
|
this.loadCard();
|
|
this.loadPosts(1);
|
|
},
|
|
loadCard() {
|
|
api
|
|
.userCard(this.data.uid)
|
|
.then((card) =>
|
|
this.setData({
|
|
card: { ...card, initial: (card.nickname || '?').slice(0, 1) },
|
|
loading: false,
|
|
}),
|
|
)
|
|
.catch((e) => {
|
|
this.setData({ loading: false });
|
|
toastErr(e);
|
|
});
|
|
},
|
|
loadPosts(page) {
|
|
api
|
|
.userPosts(this.data.uid, page)
|
|
.then((res) => {
|
|
const list = (res.list || []).map((p) => {
|
|
const tag = (p.tags || [])[0] || '';
|
|
return {
|
|
...p,
|
|
timeText: fmtAgo(p.created_at),
|
|
author_emoji: p.author_emoji || '🐾',
|
|
tag,
|
|
tagClass: TAG_CLASS[tag] || '',
|
|
};
|
|
});
|
|
const merged = page === 1 ? list : this.data.posts.concat(list);
|
|
this.setData({ posts: merged, page, hasMore: merged.length < (res.total || 0) });
|
|
})
|
|
.catch(() => {});
|
|
},
|
|
loadMore() {
|
|
if (this.data.hasMore) this.loadPosts(this.data.page + 1);
|
|
},
|
|
// 关注状态先本地翻转,请求失败再翻回去——等接口返回按钮才变会显得很迟钝
|
|
toggleFollow() {
|
|
const c = this.data.card;
|
|
if (!c || c.is_self) return;
|
|
const next = !c.followed;
|
|
this.setData({
|
|
'card.followed': next,
|
|
'card.follower_count': Math.max(0, c.follower_count + (next ? 1 : -1)),
|
|
});
|
|
(next ? api.followUser(c.id) : api.unfollowUser(c.id)).catch((e) => {
|
|
this.setData({ 'card.followed': !next, 'card.follower_count': c.follower_count });
|
|
toastErr(e, '操作失败');
|
|
});
|
|
},
|
|
goRelations(e) {
|
|
const kind = e.currentTarget.dataset.kind;
|
|
wx.navigateTo({ url: `/pages/relations/relations?id=${this.data.uid}&kind=${kind}` });
|
|
},
|
|
previewImage(e) {
|
|
const { urls, cur } = e.currentTarget.dataset;
|
|
if (urls && urls.length) wx.previewImage({ urls, current: cur });
|
|
},
|
|
onShareAppMessage() {
|
|
const n = (this.data.card && this.data.card.nickname) || '宠友';
|
|
return { title: `${n} 的主页`, path: `/pages/user/user?id=${this.data.uid}` };
|
|
},
|
|
});
|