603bd5773e
- 发帖后若未直接过审,弹窗明确「审核中,通过后才出现在社区」, 不再让用户以为发失败/是 bug - 后端 ListUserPosts:看自己主页时返回待审核/未通过的帖子(带状态), 看别人仍只返回已发布 - 个人主页帖子加「审核中/未通过」状态标 + 说明 - 我的页加「我的帖子」入口,进自己主页看审核状态 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
102 lines
3.6 KiB
JavaScript
102 lines
3.6 KiB
JavaScript
const api = require('../../utils/api.js');
|
|
const store = require('../../utils/store.js');
|
|
const { toastErr } = require('../../utils/ui.js');
|
|
|
|
const TAG_CLASS = { 求助: 'warn', 经验: 'blue', 精选: 'purple', 避坑: 'red', 晒宠: '' };
|
|
// 审核状态 → 展示文案(只在看自己主页时出现)
|
|
const STATUS_TEXT = { pending: '审核中', rejected: '未通过' };
|
|
|
|
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, 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] || '',
|
|
// 只有看自己主页才会拿到非「已发布」的帖子,给个审核状态标
|
|
statusText: STATUS_TEXT[p.status] || '',
|
|
};
|
|
});
|
|
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.detail.kind;
|
|
wx.navigateTo({ url: `/pages/relations/relations?id=${this.data.uid}&kind=${kind}` });
|
|
},
|
|
// 自己看自己的主页时,头部按钮是「装扮」而不是「关注」
|
|
goDecorate() {
|
|
wx.navigateTo({ url: '/pages/decorate/decorate' });
|
|
},
|
|
// 别人的宠物只是名片,点了不跳;自己的才切过去看
|
|
goPet(e) {
|
|
const c = this.data.card;
|
|
if (!c || !c.is_self) return;
|
|
store.switchPet(e.detail.id);
|
|
wx.switchTab({ url: '/pages/home/home' });
|
|
},
|
|
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}` };
|
|
},
|
|
});
|