chore(prod): 移除全部社区/社交相关前端代码(过审用)
- 删除页面:community(社区)、comments(评论)、user(他人主页)、relations(关注/粉丝) - app.json 去掉四个页面注册与社区 tab;tabBar 只剩 首页/报告/我的 - bottom-sheet 移除发帖(createPost)与评论(comments)整块 UI 及对应 JS/数据/常量 - profile-head 移除帖子/关注/粉丝社交数与关注按钮 - mine 去掉「我的帖子」「别人眼里的我」及关注/粉丝跳转 - api.js 移除 posts/comments/follow/relations 等社区接口(保留 userCard 供我的页头部) 说明:后端社区接口未动(微信审核只看小程序包,前端已无任何引用); 完整社区代码保留在 feat/dev 分支与 git 历史。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,178 +0,0 @@
|
||||
const api = require('../../utils/api.js');
|
||||
const upload = require('../../utils/upload.js');
|
||||
|
||||
// 相对时间:社区里关心「多久以前」,精确到秒没意义
|
||||
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);
|
||||
const sameYear = d.getFullYear() === new Date().getFullYear();
|
||||
return (sameYear ? '' : d.getFullYear() + '-') + p(d.getMonth() + 1) + '-' + p(d.getDate());
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
postId: '',
|
||||
total: 0,
|
||||
comments: [],
|
||||
commentText: '',
|
||||
commentImages: [],
|
||||
replyTo: {},
|
||||
cmFocus: false,
|
||||
sendingComment: false,
|
||||
kbHeight: 0,
|
||||
},
|
||||
|
||||
onLoad(query) {
|
||||
this.setData({ postId: query.postId || '' });
|
||||
this.loadComments();
|
||||
},
|
||||
|
||||
// 把当前已发布评论数回传给社区列表,卡片上的评论数实时跟着变
|
||||
syncCountBack() {
|
||||
const ch = this.getOpenerEventChannel && this.getOpenerEventChannel();
|
||||
if (ch && ch.emit) ch.emit('commentChanged', { postId: this.data.postId, count: this.data.total });
|
||||
},
|
||||
|
||||
loadComments() {
|
||||
if (!this.data.postId) return;
|
||||
api
|
||||
.listComments(this.data.postId)
|
||||
.then((page) => {
|
||||
this.setData({
|
||||
total: page.total || 0,
|
||||
comments: (page.list || []).map((c) => ({
|
||||
...c,
|
||||
timeText: fmtAgo(c.created_at),
|
||||
initial: (c.author_name || '?').slice(0, 1),
|
||||
imgs: Array.isArray(c.images) ? c.images : [],
|
||||
replies: (c.replies || []).map((r) => ({
|
||||
...r,
|
||||
timeText: fmtAgo(r.created_at),
|
||||
initial: (r.author_name || '?').slice(0, 1),
|
||||
})),
|
||||
})),
|
||||
});
|
||||
this.syncCountBack();
|
||||
})
|
||||
.catch(() => {});
|
||||
},
|
||||
|
||||
onCommentInput(e) {
|
||||
this.setData({ commentText: e.detail.value });
|
||||
},
|
||||
|
||||
// 点任意评论/回复:底部输入条切到「回复 xxx」并聚焦
|
||||
onReplyTo(e) {
|
||||
const { id, name } = e.currentTarget.dataset;
|
||||
if (!id) return;
|
||||
this.setData({ replyTo: { id, name }, cmFocus: true });
|
||||
},
|
||||
onCancelReply() {
|
||||
this.setData({ replyTo: {} });
|
||||
},
|
||||
|
||||
// 键盘高度变化:微信为「自定义输入条跟随键盘」提供的事件。只改输入条的 bottom(inline),
|
||||
// 评论列表完全不动。注意:聚焦期间除了这个 bottom,绝不 setData 碰输入框本身
|
||||
// (不设 cmFocus:false、不改它的布局),否则原生 textarea 会被抖失焦、键盘弹一下就收。
|
||||
onKbChange(e) {
|
||||
this.setData({ kbHeight: (e.detail && e.detail.height) || 0 });
|
||||
},
|
||||
onCommentBlur() {
|
||||
// 失焦:收起键盘时把输入条放回底部;cmFocus 复位好让下次回复能重新拉键盘
|
||||
this.setData({ cmFocus: false, kbHeight: 0 });
|
||||
},
|
||||
|
||||
// 配图:评论只允许 1 张
|
||||
onPickCommentImages() {
|
||||
if (this.data.commentImages.length >= 1) {
|
||||
return wx.showToast({ title: '评论只能配 1 张图', icon: 'none' });
|
||||
}
|
||||
upload
|
||||
.chooseAndUploadImages(1)
|
||||
.then((files) => this.setData({ commentImages: (files || []).slice(0, 1) }))
|
||||
.catch((e) => {
|
||||
if (e && e.canceled) return;
|
||||
wx.showToast({ title: (e && e.message) || '上传失败', icon: 'none' });
|
||||
});
|
||||
},
|
||||
onRemoveCommentImage(e) {
|
||||
const list = this.data.commentImages.slice();
|
||||
list.splice(e.currentTarget.dataset.index, 1);
|
||||
this.setData({ commentImages: list });
|
||||
},
|
||||
onPreviewCommentImage(e) {
|
||||
const { urls, cur } = e.currentTarget.dataset;
|
||||
if (urls && urls.length) wx.previewImage({ urls, current: cur });
|
||||
},
|
||||
|
||||
async onSendComment() {
|
||||
if (this.data.sendingComment) return; // 防连点
|
||||
const text = (this.data.commentText || '').trim();
|
||||
if (!text) return wx.showToast({ title: '写点什么再发', icon: 'none' });
|
||||
if (!this.data.postId) return;
|
||||
this.setData({ sendingComment: true });
|
||||
wx.showLoading({ title: '审核中…', mask: true });
|
||||
try {
|
||||
const res = await api.createComment(
|
||||
this.data.postId,
|
||||
text,
|
||||
this.data.commentImages.map((i) => i.url),
|
||||
this.data.replyTo.id || '',
|
||||
);
|
||||
wx.hideLoading();
|
||||
this.setData({ commentText: '', commentImages: [], replyTo: {}, cmFocus: false, sendingComment: false });
|
||||
if (res && res.status === 'published') {
|
||||
this.loadComments();
|
||||
wx.showToast({ title: '评论成功', icon: 'success' });
|
||||
} else {
|
||||
wx.showToast({ title: '已提交,审核通过后展示', icon: 'none' });
|
||||
}
|
||||
} catch (e) {
|
||||
wx.hideLoading();
|
||||
this.setData({ sendingComment: false });
|
||||
wx.showToast({ title: (e && e.message) || '评论失败', icon: 'none' });
|
||||
}
|
||||
},
|
||||
|
||||
// 长按删除自己的评论
|
||||
onDeleteComment(e) {
|
||||
const { id, self } = e.currentTarget.dataset;
|
||||
if (!id || !self) return;
|
||||
wx.showModal({
|
||||
title: '删除评论',
|
||||
content: '确定删除这条评论?',
|
||||
confirmColor: '#D9534F',
|
||||
success: (r) => {
|
||||
if (!r.confirm) return;
|
||||
api
|
||||
.deleteComment(id)
|
||||
.then(() => this.loadComments())
|
||||
.catch((err) => wx.showToast({ title: (err && err.message) || '删除失败', icon: 'none' }));
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
// 一级评论默认只带 3 条回复,点开拉全量
|
||||
onExpandReplies(e) {
|
||||
const { id, index } = e.currentTarget.dataset;
|
||||
api
|
||||
.listReplies(id)
|
||||
.then((list) =>
|
||||
this.setData({
|
||||
[`comments[${index}].replies`]: (list || []).map((r) => ({
|
||||
...r,
|
||||
timeText: fmtAgo(r.created_at),
|
||||
initial: (r.author_name || '?').slice(0, 1),
|
||||
})),
|
||||
}),
|
||||
)
|
||||
.catch((err) => wx.showToast({ title: (err && err.message) || '加载失败', icon: 'none' }));
|
||||
},
|
||||
});
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"nav-bar": "/components/nav-bar/nav-bar",
|
||||
"pt-icon": "/components/pt-icon/index"
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
<nav-bar title="评论" show-back="{{true}}"></nav-bar>
|
||||
|
||||
<scroll-view class="cm-scroll" scroll-y="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}">
|
||||
<view class="cm-count-head">共 {{total}} 条评论</view>
|
||||
|
||||
<view wx:for="{{comments}}" wx:key="id" class="cm"
|
||||
bindtap="onReplyTo" data-id="{{item.id}}" data-name="{{item.author_name}}">
|
||||
<view class="cm-av">{{item.initial}}</view>
|
||||
<view class="cm-body">
|
||||
<view class="cm-name">{{item.author_name}}<text wx:if="{{item.is_self}}" class="mine-tag">我</text></view>
|
||||
<view class="cm-text">{{item.content}}</view>
|
||||
<view wx:if="{{item.imgs.length}}" class="cm-imgs">
|
||||
<image wx:for="{{item.imgs}}" wx:for-item="u" wx:key="*this" class="cm-img"
|
||||
src="{{u}}" mode="aspectFill" catchtap="onPreviewCommentImage"
|
||||
data-urls="{{item.imgs}}" data-cur="{{u}}"></image>
|
||||
</view>
|
||||
<view class="cm-meta">
|
||||
<text>{{item.timeText}}</text>
|
||||
<text class="cm-reply-btn">回复</text>
|
||||
<text wx:if="{{item.is_self}}" class="cm-del" catchtap="onDeleteComment"
|
||||
data-id="{{item.id}}" data-self="{{true}}">删除</text>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{item.replies.length}}" class="cm-replies">
|
||||
<view wx:for="{{item.replies}}" wx:for-item="r" wx:key="id" class="cm-reply"
|
||||
catchtap="onReplyTo" data-id="{{r.id}}" data-name="{{r.author_name}}">
|
||||
<view class="cm-av cm-av-sm">{{r.initial}}</view>
|
||||
<view class="cm-body">
|
||||
<view class="cm-name">
|
||||
{{r.author_name}}<text wx:if="{{r.is_self}}" class="mine-tag">我</text>
|
||||
<text wx:if="{{r.reply_to_name}}" class="cm-at"> 回复 {{r.reply_to_name}}</text>
|
||||
</view>
|
||||
<view class="cm-text">{{r.content}}</view>
|
||||
<view class="cm-meta">
|
||||
<text>{{r.timeText}}</text>
|
||||
<text class="cm-reply-btn">回复</text>
|
||||
<text wx:if="{{r.is_self}}" class="cm-del" catchtap="onDeleteComment"
|
||||
data-id="{{r.id}}" data-self="{{true}}">删除</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{item.reply_n > item.replies.length}}" class="cm-more"
|
||||
catchtap="onExpandReplies" data-id="{{item.id}}" data-index="{{index}}">
|
||||
— 展开全部 {{item.reply_n}} 条回复
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{!comments.length}}" class="cmp-empty">
|
||||
<view class="cmp-empty-ic"><pt-icon name="comment" size="{{72}}"></pt-icon></view>
|
||||
<view class="cmp-empty-t">还没有评论</view>
|
||||
<view class="cmp-empty-p">来抢个沙发,说点什么吧~</view>
|
||||
</view>
|
||||
|
||||
</scroll-view>
|
||||
|
||||
<!-- 底部输入条:固定定位,靠 bindkeyboardheightchange 拿到键盘高度后把自己的 bottom 抬到
|
||||
键盘上方。评论列表完全不动(adjust-position=false,页面不滚)。这是微信为「自定义输入条
|
||||
跟随键盘」专门提供的事件,移动的是 bottom 值、不 reflow 输入框内部,所以不会抖失焦。 -->
|
||||
<view class="cm-bar" style="bottom:{{kbHeight}}px">
|
||||
<view wx:if="{{replyTo.name}}" class="cm-replying">
|
||||
回复 {{replyTo.name}}
|
||||
<view class="cm-cancel" catchtap="onCancelReply"><pt-icon name="close" size="{{24}}"></pt-icon></view>
|
||||
</view>
|
||||
<view wx:if="{{commentImages.length}}" class="img-picker">
|
||||
<view wx:for="{{commentImages}}" wx:key="id" class="img-thumb">
|
||||
<image src="{{item.url}}" mode="aspectFill"></image>
|
||||
<view class="img-del" catchtap="onRemoveCommentImage" data-index="{{index}}"><pt-icon name="close" size="{{24}}"></pt-icon></view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="cm-bar-row">
|
||||
<textarea class="cm-ta" placeholder="{{replyTo.name ? '回复 @' + replyTo.name + '…' : '说点什么…'}}"
|
||||
placeholder-class="placeholder" value="{{commentText}}" bindinput="onCommentInput"
|
||||
focus="{{cmFocus}}" bindblur="onCommentBlur" bindkeyboardheightchange="onKbChange"
|
||||
maxlength="500" auto-height="{{true}}" show-confirm-bar="{{false}}"
|
||||
adjust-position="{{false}}" cursor-spacing="16"></textarea>
|
||||
<view class="cm-pic {{commentImages.length ? 'disabled' : ''}}" catchtap="onPickCommentImages"><pt-icon name="photo" size="{{44}}"></pt-icon></view>
|
||||
<view class="cm-send {{commentText && !sendingComment ? 'on' : ''}}" catchtap="onSendComment">{{sendingComment ? '审核中…' : '发送'}}</view>
|
||||
</view>
|
||||
<view class="cm-tip">评论通过安全审核后才会公开显示,配图最多 1 张</view>
|
||||
</view>
|
||||
@@ -1,88 +0,0 @@
|
||||
/* flex 列 + 整页 overflow:hidden:页面本身不滚(adjust-position=false 时列表纹丝不动),
|
||||
列表在内层 scroll-view 里滚,底部输入条 fixed 覆在最下面 */
|
||||
page{display:flex;flex-direction:column;height:100vh;overflow:hidden;background:var(--bg)}
|
||||
|
||||
/* 底部留白 = 输入条高度,最后几条评论不被固定输入条盖住 */
|
||||
.cm-scroll{flex:1;min-height:0;padding:0 var(--sp-5) 200rpx}
|
||||
.cm-count-head{
|
||||
padding:var(--sp-3) 0;font-size:var(--fs-md);font-weight:var(--fw-b);
|
||||
color:var(--text);border-bottom:1rpx solid var(--line);
|
||||
}
|
||||
|
||||
/* 空态 */
|
||||
.cmp-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:160rpx 0;color:var(--muted)}
|
||||
.cmp-empty-ic{
|
||||
width:140rpx;height:140rpx;border-radius:50%;margin-bottom:var(--sp-4);
|
||||
display:flex;align-items:center;justify-content:center;
|
||||
background:var(--primary-soft);color:var(--primary);
|
||||
}
|
||||
.cmp-empty-t{font-size:var(--fs-lg);font-weight:var(--fw-b);color:var(--text-2)}
|
||||
.cmp-empty-p{margin-top:var(--sp-1);font-size:var(--fs-sm);color:var(--muted2)}
|
||||
|
||||
/* 评论行 */
|
||||
.cm{display:flex;gap:var(--sp-3);padding:var(--sp-3) 0}
|
||||
.cm-av{
|
||||
width:64rpx;height:64rpx;border-radius:50%;flex:none;
|
||||
display:flex;align-items:center;justify-content:center;
|
||||
background:var(--primary-soft);color:var(--primary-ink);
|
||||
font-size:var(--fs-md);font-weight:var(--fw-b);
|
||||
}
|
||||
.cm-av-sm{width:48rpx;height:48rpx;font-size:var(--fs-sm)}
|
||||
.cm-body{flex:1;min-width:0}
|
||||
.cm-name{font-size:var(--fs-sm);color:var(--muted)}
|
||||
.cm-at{color:var(--muted2)}
|
||||
.cm-text{margin-top:6rpx;font-size:var(--fs-md);line-height:1.55;word-break:break-word}
|
||||
.cm-imgs{display:flex;flex-wrap:wrap;gap:var(--sp-1);margin-top:var(--sp-2)}
|
||||
.cm-img{width:150rpx;height:150rpx;border-radius:var(--r-sm)}
|
||||
.cm-meta{display:flex;align-items:center;gap:var(--sp-4);margin-top:var(--sp-2);font-size:var(--fs-cap);color:var(--muted2)}
|
||||
.cm-reply-btn{color:var(--muted)}
|
||||
.cm-del{color:var(--red-ink)}
|
||||
.cm-replies{margin-top:var(--sp-2)}
|
||||
.cm-reply{display:flex;gap:var(--sp-2);padding:var(--sp-2) 0}
|
||||
.cm-more{margin-top:4rpx;font-size:var(--fs-cap);color:var(--muted)}
|
||||
.mine-tag{
|
||||
margin-left:var(--sp-1);font-size:var(--fs-cap);font-weight:var(--fw-b);
|
||||
color:var(--primary-ink);background:var(--primary-soft);padding:2rpx var(--sp-1);border-radius:var(--r-full);
|
||||
}
|
||||
|
||||
/* 底部输入条:固定在底部,键盘弹起时 inline 的 bottom 会被抬到键盘上方(列表不动) */
|
||||
.cm-bar{
|
||||
position:fixed;left:0;right:0;bottom:0;z-index:50;
|
||||
background:#fff;border-top:1rpx solid var(--line);
|
||||
padding:var(--sp-3) var(--sp-5) calc(16rpx + env(safe-area-inset-bottom));
|
||||
transition:bottom .15s ease;
|
||||
}
|
||||
.cm-replying{
|
||||
display:inline-flex;align-items:center;gap:var(--sp-2);margin-bottom:var(--sp-2);
|
||||
padding:4rpx var(--sp-3);border-radius:var(--r-full);
|
||||
background:var(--primary-soft);color:var(--primary-ink);font-size:var(--fs-cap);
|
||||
}
|
||||
.cm-cancel{display:flex;align-items:center}
|
||||
.cm-bar-row{display:flex;align-items:flex-end;gap:var(--sp-3)}
|
||||
/* 起始就是单行高度(显式 height 盖掉全局 textarea 的 88rpx,避免「先高一下再缩成单行」的抖动),
|
||||
auto-height 只在文字换行时把它顶高;超过 max 就内部滚动 */
|
||||
.cm-ta{
|
||||
flex:1;min-width:0;box-sizing:border-box;
|
||||
height:72rpx;min-height:72rpx;max-height:280rpx;
|
||||
padding:16rpx var(--sp-4);background:var(--surface-2);border-radius:var(--r-md);
|
||||
font-size:var(--fs-md);line-height:1.4;
|
||||
}
|
||||
.cm-pic{flex:none;display:flex;align-items:center;color:var(--muted);height:72rpx}
|
||||
.cm-pic.disabled{opacity:.35}
|
||||
.cm-send{
|
||||
flex:none;height:72rpx;padding:0 var(--sp-6);border-radius:var(--r-full);
|
||||
display:flex;align-items:center;justify-content:center;
|
||||
background:var(--line);color:#fff;font-size:var(--fs-md);font-weight:var(--fw-b);transition:.16s ease;
|
||||
}
|
||||
.cm-send.on{background:var(--cta)}
|
||||
.cm-tip{margin-top:var(--sp-2);color:var(--muted2);font-size:var(--fs-cap);line-height:1.5}
|
||||
|
||||
/* 配图预览 */
|
||||
.img-picker{display:flex;flex-wrap:wrap;gap:var(--sp-3);margin-bottom:var(--sp-2)}
|
||||
.img-thumb{position:relative;width:160rpx;height:160rpx;border-radius:var(--r-sm);overflow:hidden}
|
||||
.img-thumb image{width:100%;height:100%}
|
||||
.img-del{
|
||||
position:absolute;top:0;right:0;width:44rpx;height:44rpx;
|
||||
display:flex;align-items:center;justify-content:center;
|
||||
background:rgba(0,0,0,.55);color:#fff;border-radius:0 var(--r-sm) 0 var(--r-sm);
|
||||
}
|
||||
@@ -1,204 +0,0 @@
|
||||
const store = require('../../utils/store.js');
|
||||
const api = require('../../utils/api.js');
|
||||
const { toastErr } = require('../../utils/ui.js');
|
||||
const { syncTabBar } = require('../../utils/tabbar.js');
|
||||
|
||||
// 相对时间。社区里关心的是「多久以前发的」,精确到秒没意义
|
||||
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);
|
||||
const sameYear = d.getFullYear() === new Date().getFullYear();
|
||||
return (sameYear ? '' : d.getFullYear() + '-') + p(d.getMonth() + 1) + '-' + p(d.getDate());
|
||||
}
|
||||
|
||||
const TAG_CLASS = { 求助: 'warn', 经验: 'blue', 精选: 'purple', 避坑: 'red', 晒宠: '' };
|
||||
|
||||
function mapPost(p) {
|
||||
const tags = p.tags || [];
|
||||
const tag = tags[0] || '';
|
||||
return {
|
||||
id: p.id,
|
||||
author_name: p.author_name,
|
||||
author_emoji: p.author_emoji || '🐾',
|
||||
content: p.content,
|
||||
images: p.images || [],
|
||||
like_count: p.like_count,
|
||||
comment_count: p.comment_count,
|
||||
liked: false,
|
||||
tag,
|
||||
tagClass: TAG_CLASS[tag] || '',
|
||||
is_ai: !!p.is_ai,
|
||||
user_id: p.user_id,
|
||||
followed: !!p.followed,
|
||||
is_self: !!p.is_self,
|
||||
timeText: fmtAgo(p.created_at),
|
||||
};
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
pet: {},
|
||||
// 评论功能暂时下线:入口隐藏,comments 页面与 openComments 等代码全部保留,
|
||||
// 需要恢复时把这里改回 true 即可
|
||||
commentsEnabled: false,
|
||||
feedTabs: ['推荐', '关注', '新手求助', '晒宠', '经验'],
|
||||
feedIdx: 0,
|
||||
posts: [],
|
||||
sheetShow: false,
|
||||
sheetType: '',
|
||||
sheetPostId: '',
|
||||
loaded: false,
|
||||
loadErr: '',
|
||||
intoView: '',
|
||||
},
|
||||
onLoad() {
|
||||
this._unsub = store.subscribe((pet) => this.setData({ pet }));
|
||||
},
|
||||
onUnload() {
|
||||
if (this._unsub) this._unsub();
|
||||
},
|
||||
onShow() {
|
||||
syncTabBar(this);
|
||||
store
|
||||
.ready()
|
||||
.then(() => {
|
||||
this.setData({ pet: store.getPet() });
|
||||
this.loadPosts();
|
||||
})
|
||||
.catch((e) => wx.showToast({ title: e.message || '加载失败', icon: 'none' }));
|
||||
},
|
||||
loadPosts() {
|
||||
const tab = this.data.feedTabs[this.data.feedIdx];
|
||||
this.setData({ loadErr: '' });
|
||||
api
|
||||
.listPosts(tab, 1)
|
||||
.then((page) => this.setData({ posts: (page.list || []).map(mapPost), loaded: true }))
|
||||
.catch((e) => {
|
||||
// 不能让「加载失败」显示成「还没有帖子」,那是在骗用户
|
||||
this.setData({ loadErr: e.message || '加载失败', loaded: true });
|
||||
toastErr(e);
|
||||
});
|
||||
},
|
||||
// 来自 seg-tabs 的 change 事件
|
||||
switchFeedTab(e) {
|
||||
// 切分类必须回到顶部:不然从「推荐」滚到一半切到「关注」,
|
||||
// 看到的是新列表的中间,会以为内容错乱了
|
||||
this.setData({ feedIdx: Number(e.detail.index), intoView: 'feed-top' });
|
||||
this.loadPosts();
|
||||
},
|
||||
// 滚动时清掉锚点,否则下次再设同一个值不会触发
|
||||
onFeedScroll() {
|
||||
if (this.data.intoView) this.setData({ intoView: '' });
|
||||
},
|
||||
likePost(e) {
|
||||
const i = e.currentTarget.dataset.index;
|
||||
const post = this.data.posts[i];
|
||||
api
|
||||
.likePost(post.id)
|
||||
.then((res) => {
|
||||
this.setData({ [`posts[${i}].like_count`]: res.like_count, [`posts[${i}].liked`]: true });
|
||||
})
|
||||
.catch((e) => toastErr(e, '点赞失败'));
|
||||
},
|
||||
openComments(e) {
|
||||
const id = e.currentTarget.dataset.id;
|
||||
if (!id) return;
|
||||
// 评论改成独立二级页面。原来套在 fixed 弹层里,输入框被键盘遮挡且无法可靠避让;
|
||||
// 普通页面里的 fixed 输入条用 transform 平移就能稳稳浮在键盘上方
|
||||
wx.navigateTo({
|
||||
url: `/pages/comments/comments?postId=${id}`,
|
||||
events: {
|
||||
// 评论页把「已发布评论数」回传,卡片上的数字实时更新
|
||||
commentChanged: (d) => {
|
||||
if (!d || !d.postId) return;
|
||||
const idx = this.data.posts.findIndex((p) => p.id === d.postId);
|
||||
if (idx >= 0) this.setData({ [`posts[${idx}].comment_count`]: d.count });
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
openSheet(e) {
|
||||
this.setData({ sheetType: e.currentTarget.dataset.type, sheetPostId: '', sheetShow: true });
|
||||
},
|
||||
closeSheet() {
|
||||
this.setData({ sheetShow: false });
|
||||
},
|
||||
onPosted() {
|
||||
this.setData({ sheetShow: false });
|
||||
this.loadPosts();
|
||||
},
|
||||
onCommented() {
|
||||
this.loadPosts();
|
||||
},
|
||||
// 点头像或昵称进 TA 的主页。关注做了却没有主页,关注完就石沉大海
|
||||
goUser(e) {
|
||||
const id = e.currentTarget.dataset.id;
|
||||
if (id) wx.navigateTo({ url: `/pages/user/user?id=${id}` });
|
||||
},
|
||||
goLearn() {
|
||||
wx.navigateTo({ url: '/pages/learn/learn' });
|
||||
},
|
||||
// 社区的悬浮键本来就该是发帖,不是记录(原来它跳 AI 聊天页)
|
||||
onCreatePost() {
|
||||
this.setData({ sheetType: 'createPost', sheetShow: true });
|
||||
},
|
||||
// 点缩略图放大预览。只取 http 图(机器人帖的 emoji 占位不参与)
|
||||
onPreviewImage(e) {
|
||||
const { urls, cur } = e.currentTarget.dataset;
|
||||
const list = (urls || []).filter((u) => typeof u === 'string' && u.indexOf('http') === 0);
|
||||
if (!list.length) return;
|
||||
wx.previewImage({ current: cur, urls: list });
|
||||
},
|
||||
// 长按自己的帖子可删除
|
||||
onLongPressPost(e) {
|
||||
const p = this.data.posts[e.currentTarget.dataset.index];
|
||||
if (!p || !p.is_self) return;
|
||||
wx.showModal({
|
||||
title: '删除帖子',
|
||||
content: '确定删除这条帖子?删除后其他人将看不到。',
|
||||
confirmColor: '#D9534F',
|
||||
success: (res) => {
|
||||
if (!res.confirm) return;
|
||||
api.deletePost(p.id)
|
||||
.then(() => { wx.showToast({ title: '已删除', icon: 'success' }); this.loadPosts(); })
|
||||
.catch((err) => wx.showToast({ title: err.message || '删除失败', icon: 'none' }));
|
||||
},
|
||||
});
|
||||
},
|
||||
// 关注 / 取关帖子作者
|
||||
toggleFollow(e) {
|
||||
const i = e.currentTarget.dataset.index;
|
||||
const p = this.data.posts[i];
|
||||
if (!p || !p.user_id || p.is_self) return;
|
||||
const fn = p.followed ? api.unfollowUser : api.followUser;
|
||||
fn(p.user_id)
|
||||
.then(() => {
|
||||
// 同一作者的所有帖子一起更新状态
|
||||
const posts = this.data.posts.map((x) =>
|
||||
x.user_id === p.user_id ? { ...x, followed: !p.followed } : x,
|
||||
);
|
||||
this.setData({ posts });
|
||||
wx.showToast({ title: p.followed ? '已取消关注' : '已关注', icon: 'none' });
|
||||
if (this.data.feedTabs[this.data.feedIdx] === '关注') this.loadPosts();
|
||||
})
|
||||
.catch((err) => wx.showToast({ title: err.message || '操作失败', icon: 'none' }));
|
||||
},
|
||||
onShareAppMessage(e) {
|
||||
// 从帖子上的分享按钮转发:带上该帖内容做标题
|
||||
if (e && e.from === 'button') {
|
||||
const c = (e.target.dataset.content || '').slice(0, 40);
|
||||
return { title: c ? '宠友圈:' + c : '来宠友圈看看大家的毛孩子', path: '/pages/community/community' };
|
||||
}
|
||||
return { title: '宠友圈 · 和铲屎官们交流养宠经验', path: '/pages/community/community' };
|
||||
},
|
||||
onShareTimeline() {
|
||||
return { title: '宠友圈 · 和铲屎官们交流养宠经验' };
|
||||
},
|
||||
});
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"nav-bar": "/components/nav-bar/nav-bar",
|
||||
"bottom-sheet": "/components/bottom-sheet/bottom-sheet",
|
||||
"fab": "/components/fab/fab",
|
||||
"pt-icon": "/components/pt-icon/index",
|
||||
"seg-tabs": "/components/seg-tabs/index"
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
<wxs module="im">
|
||||
module.exports.isUrl = function (s) { return s && s.indexOf('http') === 0; }
|
||||
</wxs>
|
||||
<nav-bar title="宠友圈"></nav-bar>
|
||||
|
||||
<!-- 发帖统一走右下角悬浮按钮,顶部不再放发布按钮 -->
|
||||
<view class="top-bar feed-bar">
|
||||
<seg-tabs items="{{feedTabs}}" current="{{feedIdx}}" bind:change="switchFeedTab"></seg-tabs>
|
||||
</view>
|
||||
|
||||
<scroll-view class="page-scroll" scroll-y="{{true}}" scroll-into-view="{{intoView}}" bindscroll="onFeedScroll" enhanced="{{true}}" show-scrollbar="{{false}}">
|
||||
<view class="page-body">
|
||||
<view id="feed-top"></view>
|
||||
<view wx:for="{{posts}}" wx:key="id" class="post-card" bindlongpress="onLongPressPost" data-index="{{index}}">
|
||||
<view class="post-head">
|
||||
<view class="post-avatar" catchtap="goUser" data-id="{{item.user_id}}">{{item.author_emoji}}</view>
|
||||
<view class="post-user" catchtap="goUser" data-id="{{item.user_id}}">
|
||||
<view class="pu-b">{{item.author_name}}<text wx:if="{{item.is_ai}}" class="ai-tag">AI</text></view>
|
||||
<view class="pu-s">{{item.timeText}}</view>
|
||||
</view>
|
||||
<view wx:if="{{!item.is_self && item.user_id}}" class="follow-btn {{item.followed ? 'on' : ''}}"
|
||||
catchtap="toggleFollow" data-index="{{index}}">{{item.followed ? '已关注' : '+ 关注'}}</view>
|
||||
<view wx:if="{{item.tag}}" class="tag {{item.tagClass}}">{{item.tag}}</view>
|
||||
</view>
|
||||
<view class="post-content">{{item.content}}</view>
|
||||
<view wx:if="{{item.images.length}}" class="photo-grid">
|
||||
<block wx:for="{{item.images}}" wx:for-item="img" wx:key="*this">
|
||||
<image wx:if="{{im.isUrl(img)}}" class="photo-tile" src="{{img}}" mode="aspectFill"
|
||||
catchtap="onPreviewImage" data-urls="{{item.images}}" data-cur="{{img}}"></image>
|
||||
<view wx:else class="photo-tile">{{img}}</view>
|
||||
</block>
|
||||
</view>
|
||||
<view class="post-actions">
|
||||
<view class="pa-btn {{item.liked ? 'liked' : ''}}" data-index="{{index}}" bindtap="likePost">
|
||||
<pt-icon name="{{item.liked ? 'like-on' : 'like'}}" size="{{32}}"></pt-icon>
|
||||
<text class="pa-n">{{item.like_count || '点赞'}}</text>
|
||||
</view>
|
||||
<!-- 评论功能暂时关闭(commentsEnabled=false),入口隐藏;页面和代码都保留,
|
||||
后面把 commentsEnabled 改回 true 即可恢复 -->
|
||||
<view wx:if="{{commentsEnabled}}" class="pa-btn" data-id="{{item.id}}" bindtap="openComments">
|
||||
<pt-icon name="comment" size="{{32}}"></pt-icon>
|
||||
<text class="pa-n">{{item.comment_count || '评论'}}</text>
|
||||
</view>
|
||||
<button class="pa-btn pa-share" open-type="share" data-content="{{item.content}}">
|
||||
<pt-icon name="share" size="{{32}}"></pt-icon>
|
||||
<text class="pa-n">分享</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{loadErr}}" class="empty lg">
|
||||
{{loadErr}}
|
||||
<view class="retry-btn" bindtap="loadPosts">点击重试</view>
|
||||
</view>
|
||||
<view wx:elif="{{loaded && posts.length === 0}}" class="empty lg">
|
||||
{{feedTabs[feedIdx] === '关注' ? '还没有关注的人,去「推荐」里关注几个宠友吧 🐾' : '还没有帖子,来发第一条吧 🐾'}}
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<fab icon="edit" bind:tap="onCreatePost"></fab>
|
||||
<bottom-sheet show="{{sheetShow}}" type="{{sheetType}}" post-id="{{sheetPostId}}"
|
||||
bind:close="closeSheet" bind:posted="onPosted" bind:commented="onCommented"></bottom-sheet>
|
||||
@@ -1,19 +0,0 @@
|
||||
.compose-card{margin-bottom:var(--sp-4)}
|
||||
|
||||
|
||||
/* 关注按钮 */
|
||||
|
||||
.retry-btn{
|
||||
margin-top:var(--sp-3);display:inline-block;padding:var(--sp-2) var(--sp-6);border-radius:var(--r-full);
|
||||
background:var(--primary-soft);color:var(--primary-dark);font-weight:var(--fw-b);font-size:var(--fs-sm);
|
||||
}
|
||||
|
||||
/* 分类标签吸顶,发布按钮收进同一条:原来那个大黑按钮独占 124rpx,
|
||||
而它是低频操作,不该在每屏都占着首屏 */
|
||||
.feed-bar{display:flex;align-items:flex-start;gap:var(--sp-3)}
|
||||
.feed-bar .st{flex:1;min-width:0}
|
||||
.feed-post{
|
||||
flex:none;display:flex;align-items:center;gap:4rpx;
|
||||
height:var(--h-sm);padding:0 var(--sp-3);border-radius:var(--r-full);
|
||||
background:var(--cta);color:#fff;font-size:var(--fs-sm);font-weight:var(--fw-b);
|
||||
}
|
||||
@@ -34,25 +34,9 @@ Page({
|
||||
.then((card) => this.setData({ card }))
|
||||
.catch(() => {});
|
||||
},
|
||||
// 看自己的公开主页,和别人看到的是同一个页面、同一套渲染
|
||||
previewPublic() {
|
||||
const uid = this.data.user && this.data.user.id;
|
||||
if (uid) wx.navigateTo({ url: `/pages/user/user?id=${uid}` });
|
||||
},
|
||||
// 我的帖子:进自己的主页,能看到待审核/未通过的帖子及状态
|
||||
goMyPosts() {
|
||||
const uid = this.data.user && this.data.user.id;
|
||||
if (!uid) return wx.showToast({ title: '请先登录', icon: 'none' });
|
||||
wx.navigateTo({ url: '/pages/user/user?id=' + uid });
|
||||
},
|
||||
goSettings() {
|
||||
wx.navigateTo({ url: '/pages/settings/settings' });
|
||||
},
|
||||
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.detail.kind}` });
|
||||
},
|
||||
// 宠物档案:当前这只的编辑页
|
||||
goPetForm() {
|
||||
const id = store.currentPetId();
|
||||
|
||||
@@ -2,18 +2,13 @@
|
||||
|
||||
<scroll-view class="page-scroll" scroll-y="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}">
|
||||
<view class="page-body tab-nofab">
|
||||
<!-- 和「宠友主页」同一个组件。自己看到的就是别人看到的,装扮才有意义 -->
|
||||
<profile-head card="{{card}}" hide-wall="{{true}}" bind:relations="goRelations"
|
||||
<profile-head card="{{card}}" hide-wall="{{true}}" hide-social="{{true}}"
|
||||
bind:decorate="goDecorate" bind:pet="onPickPet"></profile-head>
|
||||
|
||||
<!-- 装扮 + 预览,一行两列 -->
|
||||
<view class="me-actions">
|
||||
<view class="btn btn-ghost me-act" bindtap="goDecorate">
|
||||
<pt-icon name="edit" size="{{28}}"></pt-icon>装扮主页
|
||||
</view>
|
||||
<view class="btn btn-ghost me-act" bindtap="previewPublic">
|
||||
<pt-icon name="user" size="{{28}}"></pt-icon>别人眼里的我
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 我的毛孩子 -->
|
||||
@@ -37,13 +32,6 @@
|
||||
|
||||
<!-- 档案/计划/多宠都从首页和宠物卡进,这里留「设置」-->
|
||||
<view class="profile-list">
|
||||
<!-- 社区下线期间隐藏「我的帖子」入口(goMyPosts 代码保留,恢复社区时把这块解开即可)
|
||||
<view class="profile-row" bindtap="goMyPosts">
|
||||
<view class="pr-ic"><pt-icon name="community" size="{{34}}"></pt-icon></view>
|
||||
<text class="pr-label">我的帖子</text><text class="pr-val">看审核状态</text>
|
||||
<view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view>
|
||||
</view>
|
||||
-->
|
||||
<view class="profile-row" bindtap="goSettings">
|
||||
<view class="pr-ic"><pt-icon name="settings" size="{{34}}"></pt-icon></view>
|
||||
<text class="pr-label">设置</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view>
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
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, '操作失败');
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"nav-bar": "/components/nav-bar/nav-bar",
|
||||
"pt-icon": "/components/pt-icon/index"
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<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.initial}}</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>
|
||||
@@ -1,12 +0,0 @@
|
||||
.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)}
|
||||
@@ -55,12 +55,6 @@ Page({
|
||||
wx.navigateTo({ url: '/pages/agreement/agreement?type=privacy' });
|
||||
}
|
||||
},
|
||||
// 自己的关注/粉丝。之前只有帖子上的「+关注」按钮,关注完没有任何地方能看
|
||||
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}` });
|
||||
},
|
||||
goRecord() {
|
||||
wx.navigateTo({ url: '/pages/record/record' });
|
||||
},
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
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}` };
|
||||
},
|
||||
});
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"nav-bar": "/components/nav-bar/nav-bar",
|
||||
"pt-icon": "/components/pt-icon/index",
|
||||
"profile-head": "/components/profile-head/index"
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<wxs module="im">
|
||||
module.exports.isUrl = function (s) { return s && s.indexOf('http') === 0; }
|
||||
</wxs>
|
||||
<nav-bar title="{{card ? card.nickname : '宠友主页'}}" 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:if="{{loading}}" class="empty lg">加载中…</view>
|
||||
|
||||
<block wx:elif="{{card}}">
|
||||
<!-- 别人主页:关注/粉丝数字只展示、不可点开,避免从列表进主页后又开对方列表无限套娃 -->
|
||||
<profile-head card="{{card}}" relations-clickable="{{false}}" bind:follow="toggleFollow"
|
||||
bind:relations="goRelations" bind:decorate="goDecorate"
|
||||
bind:pet="goPet"></profile-head>
|
||||
|
||||
<view wx:for="{{posts}}" wx:key="id" class="post-card">
|
||||
<view class="post-head">
|
||||
<view class="post-avatar">{{item.author_emoji}}</view>
|
||||
<view class="post-user">
|
||||
<view class="pu-b">{{item.author_name}}</view>
|
||||
<view class="pu-s">{{item.timeText}}</view>
|
||||
</view>
|
||||
<view wx:if="{{item.statusText}}" class="post-status st-{{item.status}}">{{item.statusText}}</view>
|
||||
<view wx:if="{{item.tag}}" class="tag {{item.tagClass}}">{{item.tag}}</view>
|
||||
</view>
|
||||
<view wx:if="{{item.status === 'pending'}}" class="status-note">内容审核中,通过后其他人才能看到</view>
|
||||
<view wx:elif="{{item.status === 'rejected'}}" class="status-note st-note-red">未通过内容安全审核,仅你可见</view>
|
||||
<view class="post-content">{{item.content}}</view>
|
||||
<view wx:if="{{item.images.length}}" class="photo-grid">
|
||||
<block wx:for="{{item.images}}" wx:for-item="img" wx:key="*this">
|
||||
<image wx:if="{{im.isUrl(img)}}" class="photo-tile" src="{{img}}" mode="aspectFill"
|
||||
bindtap="previewImage" data-urls="{{item.images}}" data-cur="{{img}}"></image>
|
||||
<view wx:else class="photo-tile">{{img}}</view>
|
||||
</block>
|
||||
</view>
|
||||
<view class="post-actions">
|
||||
<view class="pa-btn"><pt-icon name="like" size="{{32}}"></pt-icon><text class="pa-n">{{item.like_count || 0}}</text></view>
|
||||
<view class="pa-btn"><pt-icon name="comment" size="{{32}}"></pt-icon><text class="pa-n">{{item.comment_count || 0}}</text></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{!posts.length}}" class="empty lg">TA 还没有发过帖子</view>
|
||||
</block>
|
||||
</view>
|
||||
</scroll-view>
|
||||
@@ -1,15 +0,0 @@
|
||||
/* 头部整块(头像/昵称/签名/计数/养宠数据/宠物墙)已抽成 components/profile-head,
|
||||
帖子卡走 app.wxss 的 .post-card。这里没有页面独有样式了。 */
|
||||
|
||||
/* 审核状态标(只在看自己主页出现) */
|
||||
.post-status{
|
||||
padding:2rpx var(--sp-2);border-radius:var(--r-full);
|
||||
font-size:var(--fs-cap);font-weight:var(--fw-b);margin-right:var(--sp-2);
|
||||
}
|
||||
.post-status.st-pending{background:#FDECC8;color:#B26A00}
|
||||
.post-status.st-rejected{background:var(--red-soft);color:var(--red-ink)}
|
||||
.status-note{
|
||||
margin:0 0 var(--sp-2);padding:var(--sp-2) var(--sp-3);border-radius:var(--r-sm);
|
||||
background:var(--surface-2);color:var(--muted);font-size:var(--fs-cap);line-height:1.5;
|
||||
}
|
||||
.status-note.st-note-red{background:var(--red-soft);color:var(--red-ink)}
|
||||
Reference in New Issue
Block a user