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
-9
@@ -10,16 +10,12 @@
|
||||
"pages/petform/petform",
|
||||
"pages/idcard/idcard",
|
||||
"pages/report/report",
|
||||
"pages/community/community",
|
||||
"pages/comments/comments",
|
||||
"pages/learn/learn",
|
||||
"pages/article/article",
|
||||
"pages/mine/mine",
|
||||
"pages/decorate/decorate",
|
||||
"pages/settings/settings",
|
||||
"pages/agreement/agreement",
|
||||
"pages/user/user",
|
||||
"pages/relations/relations"
|
||||
"pages/agreement/agreement"
|
||||
],
|
||||
"window": {
|
||||
"navigationStyle": "custom",
|
||||
@@ -40,10 +36,6 @@
|
||||
"pagePath": "pages/report/report",
|
||||
"text": "报告"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/community/community",
|
||||
"text": "社区"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/mine/mine",
|
||||
"text": "我的"
|
||||
|
||||
@@ -17,22 +17,6 @@ function daysLater(n) {
|
||||
|
||||
// "2026-07-30" → "2026-07-30T12:00:00+08:00"
|
||||
//
|
||||
// 相对时间。社区里关心的是「多久以前发的」,精确到秒没意义
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
// 提醒类型(与后端 model.Reminder* 常量对应)
|
||||
const REMINDER_TYPES = [
|
||||
{ key: 'vaccine', label: '疫苗' },
|
||||
@@ -43,9 +27,6 @@ const REMINDER_TYPES = [
|
||||
const REMINDER_LABELS = REMINDER_TYPES.map((t) => t.label);
|
||||
|
||||
|
||||
// 标签和社区顶部筛选保持一致(晒宠 / 新手求助 / 经验)
|
||||
const PTAG = ['晒宠', '新手求助', '经验'];
|
||||
|
||||
Component({
|
||||
options: { addGlobalClass: true },
|
||||
properties: {
|
||||
@@ -58,11 +39,6 @@ Component({
|
||||
innerType: '',
|
||||
pet: {},
|
||||
segSel: {},
|
||||
optSel: {},
|
||||
// 通用简易记录(洗护/清洁那 15 种共用)
|
||||
postContent: '',
|
||||
pfFocus: false, // 发帖内容框聚焦标记(点整块 field 聚焦用)
|
||||
postImages: [],
|
||||
remForm: { id: '', typeIdx: 0, title: '', date: '', freq: '' },
|
||||
remTypeLabels: REMINDER_LABELS,
|
||||
myPets: [],
|
||||
@@ -70,21 +46,12 @@ Component({
|
||||
fbContent: '',
|
||||
fbContact: '',
|
||||
fbDone: false,
|
||||
commentText: '',
|
||||
comments: [],
|
||||
reminders: [],
|
||||
poster: null,
|
||||
reportDetail: null,
|
||||
proInfo: null,
|
||||
saving: false,
|
||||
posterSaving: false,
|
||||
commentImages: [],
|
||||
replyTo: {},
|
||||
cmFocus: false,
|
||||
composing: false, // 评论输入面板是否展开(收起时只是一条细条)
|
||||
sendingComment: false, // 发送+审核在途,防连点
|
||||
kbHeight: 0,
|
||||
total: 0,
|
||||
},
|
||||
observers: {
|
||||
show: function (show) {
|
||||
@@ -107,22 +74,12 @@ Component({
|
||||
const patch = { innerType: type, pet };
|
||||
if (fresh) {
|
||||
patch.segSel = {};
|
||||
patch.optSel = {};
|
||||
patch.postContent = '';
|
||||
patch.postImages = [];
|
||||
patch.medDose = '';
|
||||
patch.remForm = { id: '', typeIdx: 0, title: '', date: '', freq: '' };
|
||||
patch.exportText = '';
|
||||
patch.fbContent = '';
|
||||
patch.fbContact = '';
|
||||
patch.fbDone = false;
|
||||
patch.commentText = '';
|
||||
patch.commentImages = [];
|
||||
patch.replyTo = {};
|
||||
patch.cmFocus = false;
|
||||
patch.composing = false;
|
||||
patch.sendingComment = false;
|
||||
patch.kbHeight = 0;
|
||||
patch.saving = false;
|
||||
}
|
||||
this.setData(patch);
|
||||
@@ -138,8 +95,6 @@ Component({
|
||||
this.loadMyPets();
|
||||
} else if (type === 'exportData') {
|
||||
this.buildExport();
|
||||
} else if (type === 'comments' && this.data.postId) {
|
||||
this.loadComments();
|
||||
} else if (type === 'reminders' && id) {
|
||||
this.loadReminders();
|
||||
} else if (type === 'poster' && id) {
|
||||
@@ -357,54 +312,6 @@ Component({
|
||||
const segSel = Object.assign({}, this.data.segSel, { [group]: Number(index) });
|
||||
this.setData({ segSel });
|
||||
},
|
||||
onOpt(e) {
|
||||
const { group, index } = e.currentTarget.dataset;
|
||||
const optSel = Object.assign({}, this.data.optSel, { [group]: Number(index) });
|
||||
this.setData({ optSel });
|
||||
},
|
||||
onPostInput(e) { this.setData({ postContent: e.detail.value }); },
|
||||
// 点内容 field 任意处都聚焦(原生 textarea 在 scroll-view 里命中区域会偏)
|
||||
onPostFieldTap() { this.setData({ pfFocus: true }); },
|
||||
onPostBlur() { this.setData({ pfFocus: false }); },
|
||||
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),
|
||||
// 没有头像字段,用昵称首字做个色块,比一律显示同一个 emoji 强
|
||||
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),
|
||||
})),
|
||||
})),
|
||||
}),
|
||||
)
|
||||
.catch(() => {});
|
||||
},
|
||||
// 长按删除自己的评论
|
||||
onDeleteComment(e) {
|
||||
const { id, self } = e.currentTarget.dataset;
|
||||
if (!id || !self) return;
|
||||
const c = { id };
|
||||
wx.showModal({
|
||||
title: '删除评论',
|
||||
content: '确定删除这条评论?',
|
||||
confirmColor: '#D9534F',
|
||||
success: (res) => {
|
||||
if (!res.confirm) return;
|
||||
api.deleteComment(c.id)
|
||||
.then(() => { this.loadComments(); this.triggerEvent('commented'); })
|
||||
.catch((err) => wx.showToast({ title: err.message || '删除失败', icon: 'none' }));
|
||||
},
|
||||
});
|
||||
},
|
||||
// ---- 多宠物管理 ----
|
||||
loadMyPets() {
|
||||
const cur = store.currentPetId();
|
||||
@@ -559,33 +466,11 @@ Component({
|
||||
if (!id) return;
|
||||
api.getTasks(id).then((tasks) => this.setData({ manageTasks: tasks || [] })).catch(() => {});
|
||||
},
|
||||
onPickPostImages() {
|
||||
const left = 2 - this.data.postImages.length;
|
||||
if (left <= 0) return wx.showToast({ title: '最多 2 张', icon: 'none' });
|
||||
upload
|
||||
.chooseAndUploadImages(left)
|
||||
.then((list) => this.setData({ postImages: this.data.postImages.concat(list) }))
|
||||
.catch((e) => {
|
||||
if (e && e.canceled) return;
|
||||
wx.showToast({ title: (e && e.message) || '上传失败', icon: 'none' });
|
||||
});
|
||||
},
|
||||
onRemovePostImage(e) {
|
||||
const i = e.currentTarget.dataset.index;
|
||||
const arr = this.data.postImages.slice();
|
||||
arr.splice(i, 1);
|
||||
this.setData({ postImages: arr });
|
||||
},
|
||||
onCommentInput(e) { this.setData({ commentText: e.detail.value }); },
|
||||
|
||||
segIdx(group) {
|
||||
const v = this.data.segSel[group];
|
||||
return v === undefined ? 0 : v;
|
||||
},
|
||||
optIdx(group) {
|
||||
const v = this.data.optSel[group];
|
||||
return v === undefined ? 0 : v;
|
||||
},
|
||||
// 记录表单整体搬去 pages/addrecord 之后,这里只剩「生成就医前摘要」
|
||||
// 会往 health_records 写一条 note —— 它是个动作留痕,不是用户填的表单
|
||||
buildRecord() {
|
||||
@@ -622,139 +507,6 @@ Component({
|
||||
onSave() {
|
||||
this.createAndClose(this.buildRecord());
|
||||
},
|
||||
async onCreatePost() {
|
||||
const content = (this.data.postContent || '').trim();
|
||||
if (!content) return wx.showToast({ title: '写点什么吧', icon: 'none' });
|
||||
const tag = PTAG[this.data.optSel.ptag === undefined ? 0 : this.data.optSel.ptag];
|
||||
if (this.data.saving) return;
|
||||
this.setData({ saving: true });
|
||||
try {
|
||||
// 去掉发布身份,统一用发布者昵称(后端按 user 取昵称)
|
||||
const post = await api.createPost({
|
||||
identity: 'user',
|
||||
content,
|
||||
tags: [tag],
|
||||
image_file_ids: this.data.postImages.map((i) => i.id),
|
||||
});
|
||||
this.triggerEvent('posted');
|
||||
this.close();
|
||||
// 内容安全审核:没直接过审的,明确告诉用户在审核,别以为发失败/是 bug
|
||||
if (post && post.status && post.status !== 'published') {
|
||||
wx.showModal({
|
||||
title: '发布成功,审核中',
|
||||
content: '内容需要通过安全审核后才会出现在社区。可在「我的 → 我的帖子」查看审核状态。',
|
||||
showCancel: false,
|
||||
confirmText: '知道了',
|
||||
});
|
||||
} else {
|
||||
wx.showToast({ title: '已发布', icon: 'success' });
|
||||
}
|
||||
} catch (e) {
|
||||
wx.showToast({ title: e.message || '发布失败', icon: 'none' });
|
||||
this.setData({ saving: false });
|
||||
}
|
||||
},
|
||||
|
||||
// 评论
|
||||
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.close();
|
||||
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: {},
|
||||
composing: false, cmFocus: false, kbHeight: 0, sendingComment: false,
|
||||
});
|
||||
// 过审即时展示;否则挂在人工/异步图片审核,通过后才出现
|
||||
if (res && res.status === 'published') {
|
||||
this.loadComments();
|
||||
this.triggerEvent('commented');
|
||||
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' });
|
||||
}
|
||||
},
|
||||
|
||||
// 评论配图:只允许 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' });
|
||||
});
|
||||
},
|
||||
// 回复某条评论:输入区顶部显示「回复 xxx」,发送时带上 parent_id
|
||||
// 小红书那套:点任意一条评论/回复,直接把输入框激活并填上「回复 @xxx」,
|
||||
// 不用再去底部找输入框、也不用单独点一个「回复」按钮
|
||||
onReplyTo(e) {
|
||||
const { id, name } = e.currentTarget.dataset;
|
||||
if (!id) return;
|
||||
// 输入框常驻、属性不变,直接置 focus 拉键盘即可;只填「回复对象」这一个横幅
|
||||
this.setData({ replyTo: { id, name }, cmFocus: true });
|
||||
},
|
||||
onCommentFocus() {
|
||||
// 只复位一次性 focus 开关。键盘高度交给 onKbChange,用 transform 平移弹层来避让
|
||||
this.setData({ cmFocus: false });
|
||||
},
|
||||
// 键盘高度变化(真机可靠来源)。把高度写进 data,
|
||||
// wxml 里只用它算 transform 平移量 —— 纯合成层操作,不 reflow、不抖焦点
|
||||
onKbChange(e) {
|
||||
this.setData({ kbHeight: (e.detail && e.detail.height) || 0 });
|
||||
},
|
||||
onCommentBlur() {
|
||||
// 失焦不主动清 kbHeight:键盘真正收起时 onKbChange 会回调 0,避免和收键盘动画抢
|
||||
this.setData({ cmFocus: false });
|
||||
},
|
||||
onCancelReply() {
|
||||
this.setData({ replyTo: {} });
|
||||
},
|
||||
// 一级评论默认只带 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' }));
|
||||
},
|
||||
onPreviewCommentImage(e) {
|
||||
const { urls, cur } = e.currentTarget.dataset;
|
||||
if (urls && urls.length) wx.previewImage({ urls, current: cur });
|
||||
},
|
||||
onRemoveCommentImage(e) {
|
||||
const list = this.data.commentImages.slice();
|
||||
list.splice(e.currentTarget.dataset.index, 1);
|
||||
this.setData({ commentImages: list });
|
||||
},
|
||||
|
||||
},
|
||||
});
|
||||
|
||||
@@ -7,102 +7,10 @@ module.exports.sel = function (map, key, index, def) {
|
||||
</wxs>
|
||||
|
||||
<view class="overlay {{show ? 'show' : ''}}" bindtap="onMaskTap">
|
||||
<!-- 键盘避让:只用 transform 平移整张弹层(合成层操作,不触发 reflow,
|
||||
所以不会把聚焦中的 textarea 抖失焦 → 不再「弹一下就收」的死循环)。
|
||||
show/hide 的滑入滑出也并进这一个 transform,避免和 CSS 里的 transform 打架。 -->
|
||||
<view class="sheet {{innerType === 'comments' ? 'sheet-cmp' : ''}}" catchtap="noop"
|
||||
style="transform:translateY({{show ? (innerType === 'comments' && kbHeight ? ('-' + kbHeight + 'px') : '0px') : '106%'}})">
|
||||
<view class="sheet" catchtap="noop">
|
||||
<view class="sheetbar"></view>
|
||||
|
||||
<!-- 评论:头 + 滚动列表 + 常驻输入栏。输入栏不能放进滚动区,
|
||||
否则列表一滚它就跟着走,点评论回复时还得再找回来 -->
|
||||
<block wx:if="{{innerType === 'comments'}}">
|
||||
<view class="cmp-head">共 {{total}} 条评论</view>
|
||||
|
||||
<scroll-view class="cmp-list" scroll-y="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}">
|
||||
<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>
|
||||
|
||||
<!-- 常驻评论条:textarea 的 class / auto-height / 尺寸全程不变,回复时只置 focus。
|
||||
之前真机「闪 + 不聚焦」是因为聚焦同帧还改了 textarea 自身属性(mini→full、
|
||||
auto-height 切换),被微信当成 reflow 把焦点抖掉了。现在什么都不切。 -->
|
||||
<view class="cmp-dock">
|
||||
<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>
|
||||
<textarea class="cm-ta" placeholder="{{replyTo.name ? '回复 @' + replyTo.name + '…' : '说点什么…'}}"
|
||||
placeholder-class="placeholder" value="{{commentText}}" bindinput="onCommentInput"
|
||||
focus="{{cmFocus}}" bindfocus="onCommentFocus" bindblur="onCommentBlur"
|
||||
bindkeyboardheightchange="onKbChange"
|
||||
maxlength="500" auto-height="{{true}}" show-confirm-bar="{{false}}"
|
||||
adjust-position="{{false}}" cursor-spacing="16"></textarea>
|
||||
<view wx:if="{{commentImages.length}}" class="img-picker" style="margin-top:12rpx">
|
||||
<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-toolbar">
|
||||
<view class="cm-pic {{commentImages.length ? 'disabled' : ''}}" catchtap="onPickCommentImages"><pt-icon name="photo" size="{{44}}"></pt-icon></view>
|
||||
<text class="cm-count">{{commentText.length}}/500</text>
|
||||
<view class="cm-send {{commentText && !sendingComment ? 'on' : ''}}" catchtap="onSendComment">{{sendingComment ? '审核中…' : '发送'}}</view>
|
||||
</view>
|
||||
<view class="cm-tip">评论通过安全审核后才会公开显示,配图最多 1 张</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
|
||||
<scroll-view wx:if="{{innerType !== 'comments'}}" class="sheet-scroll" scroll-y="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}">
|
||||
<scroll-view class="sheet-scroll" scroll-y="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}">
|
||||
<!-- 那 9 种记录表单(体重/排便/饮食/异常/给药/记账/疫苗/驱虫/照片)已经整体
|
||||
搬到 pages/addrecord —— 字段由后端 record_types.fields 驱动,一个页面吃掉
|
||||
全部 24 种,不再每种一个 wx:elif。弹层现在只管「不是记一笔」的那些事:
|
||||
@@ -204,32 +112,6 @@ module.exports.sel = function (map, key, index, def) {
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<!-- 添加宠物 -->
|
||||
<!-- 添加/编辑宠物已经整体搬到 pages/petform:三步向导(名字+头像 → 猫狗+品种
|
||||
→ 其他资料),品种从后端 breeds 表来、按首字母索引。弹层塞不下这些 -->
|
||||
<block wx:elif="{{innerType === 'createPost'}}">
|
||||
<view class="sheet-h3">发布图文</view>
|
||||
<view class="sheet-p">用你的昵称分享养宠日常。</view>
|
||||
<!-- 点整块 field 都能聚焦:原生 textarea 在 scroll-view 里命中区域会偏 -->
|
||||
<view class="field" bindtap="onPostFieldTap"><label>内容</label>
|
||||
<textarea class="textarea" focus="{{pfFocus}}" placeholder="分享养宠日常、求助问题、经验笔记..." placeholder-class="placeholder" value="{{postContent}}" bindinput="onPostInput" bindblur="onPostBlur"></textarea></view>
|
||||
<view class="mini-options">
|
||||
<view class="option {{u.sel(optSel,'ptag',0,0)?'selected':''}}" data-group="ptag" data-index="0" bindtap="onOpt">晒宠</view>
|
||||
<view class="option {{u.sel(optSel,'ptag',1,0)?'selected':''}}" data-group="ptag" data-index="1" bindtap="onOpt">新手求助</view>
|
||||
<view class="option {{u.sel(optSel,'ptag',2,0)?'selected':''}}" data-group="ptag" data-index="2" bindtap="onOpt">经验</view>
|
||||
</view>
|
||||
<view class="field"><label>图片(可选,最多 2 张)</label>
|
||||
<view class="img-picker">
|
||||
<view wx:for="{{postImages}}" wx:key="id" class="img-thumb">
|
||||
<image src="{{item.url}}" mode="aspectFill"></image>
|
||||
<view class="img-del" catchtap="onRemovePostImage" data-index="{{index}}"><pt-icon name="close" size="{{24}}"></pt-icon></view>
|
||||
</view>
|
||||
<view wx:if="{{postImages.length < 2}}" class="img-add" bindtap="onPickPostImages"><pt-icon name="plus" size="{{48}}"></pt-icon></view>
|
||||
</view>
|
||||
</view>
|
||||
<button class="btn btn-primary btn-block" bindtap="onCreatePost">发布到宠友圈</button>
|
||||
</block>
|
||||
|
||||
<!-- 任务管理那一支删了:它管的是 DailyTask,而「今日任务」已经并进计划节点,
|
||||
增删改都在计划页做。留着会出现「这里加的任务」和「计划页加的节点」进不同的表 -->
|
||||
<block wx:elif="{{innerType === 'managePets'}}">
|
||||
|
||||
@@ -8,9 +8,7 @@ Component({
|
||||
// 装扮页的实时预览:只看效果,不要底部那排按钮
|
||||
preview: { type: Boolean, value: false },
|
||||
hideWall: { type: Boolean, value: false }, // 「我的」页藏掉社交宠物墙,避免和「我的毛孩子」卡重复
|
||||
// 关注/粉丝数字是否可点开列表。别人主页设 false:从关注/粉丝列表点进对方主页后,
|
||||
// 不再允许打开对方的关注/粉丝,否则会无限套娃
|
||||
relationsClickable: { type: Boolean, value: true },
|
||||
hideSocial: { type: Boolean, value: false }, // 兼容旧调用,社区下线后无实际作用
|
||||
},
|
||||
data: { initial: '', theme: 'warm' },
|
||||
observers: {
|
||||
@@ -24,16 +22,9 @@ Component({
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
onFollow() {
|
||||
this.triggerEvent('follow');
|
||||
},
|
||||
onDecorate() {
|
||||
this.triggerEvent('decorate');
|
||||
},
|
||||
onRelations(e) {
|
||||
if (!this.data.relationsClickable) return; // 别人主页:只看数字,不给点开列表
|
||||
this.triggerEvent('relations', { kind: e.currentTarget.dataset.kind });
|
||||
},
|
||||
onPet(e) {
|
||||
this.triggerEvent('pet', { id: e.currentTarget.dataset.id });
|
||||
},
|
||||
|
||||
@@ -15,13 +15,6 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 社交数:小一行,数字+标签内联 -->
|
||||
<view class="pf-social">
|
||||
<view class="pf-stat"><text class="pf-n">{{card.post_count || 0}}</text><text class="pf-l">帖子</text></view>
|
||||
<view class="pf-stat" data-kind="following" bindtap="onRelations"><text class="pf-n">{{card.following_count || 0}}</text><text class="pf-l">关注</text></view>
|
||||
<view class="pf-stat" data-kind="followers" bindtap="onRelations"><text class="pf-n">{{card.follower_count || 0}}</text><text class="pf-l">粉丝</text></view>
|
||||
</view>
|
||||
|
||||
<!-- 养宠数据:这个 App 独有,做成高亮带,比帖子数更能说明是个认真的铲屎官 -->
|
||||
<view wx:if="{{card.stats}}" class="pf-keep">
|
||||
<view class="pf-keep-i"><text class="pf-kn">{{card.stats.days || 0}}</text><text class="pf-kl">养宠天数</text></view>
|
||||
@@ -42,9 +35,5 @@
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 别人主页的关注键(装扮按钮已挪到「我的」页) -->
|
||||
<view wx:if="{{!preview && !card.is_self}}" class="btn {{card.followed ? 'btn-ghost' : 'btn-dark'}} btn-block pf-follow" bindtap="onFollow">
|
||||
<pt-icon wx:if="{{!card.followed}}" name="plus" size="{{28}}"></pt-icon>{{card.followed ? '已关注' : '关注 TA'}}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -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)}
|
||||
+1
-20
@@ -125,27 +125,8 @@ const api = {
|
||||
healthSummary: (id) => request({ url: `/api/pets/${id}/health-summary` }),
|
||||
getPoster: (id) => request({ url: `/api/pets/${id}/poster` }),
|
||||
|
||||
// 社区
|
||||
listPosts: (tab, page) =>
|
||||
request({ url: `/api/posts?tab=${encodeURIComponent(tab || '')}&page=${page || 1}&page_size=10` }),
|
||||
createPost: (body) => request({ url: '/api/posts', method: 'POST', data: body }),
|
||||
likePost: (id) => request({ url: `/api/posts/${id}/like`, method: 'POST' }),
|
||||
// 个人主页卡片(「我的」页头部用;社区/关注已下线)
|
||||
userCard: (userId) => request({ url: `/api/users/${userId}/profile` }),
|
||||
userPosts: (userId, page) => request({ url: `/api/users/${userId}/posts?page=${page || 1}&page_size=10` }),
|
||||
relations: (userId, kind, page) =>
|
||||
request({ url: `/api/users/${userId}/relations?kind=${kind}&page=${page || 1}&page_size=20` }),
|
||||
followUser: (userId) => request({ url: `/api/users/${userId}/follow`, method: 'POST' }),
|
||||
unfollowUser: (userId) => request({ url: `/api/users/${userId}/follow`, method: 'DELETE' }),
|
||||
deletePost: (id) => request({ url: `/api/posts/${id}`, method: 'DELETE' }),
|
||||
deleteComment: (id) => request({ url: `/api/comments/${id}`, method: 'DELETE' }),
|
||||
listComments: (id) => request({ url: `/api/posts/${id}/comments` }),
|
||||
createComment: (id, content, images, parentId) =>
|
||||
request({
|
||||
url: `/api/posts/${id}/comments`,
|
||||
method: 'POST',
|
||||
data: { content, images: images || [], parent_id: parentId || '' },
|
||||
}),
|
||||
listReplies: (commentId) => request({ url: `/api/comments/${commentId}/replies` }),
|
||||
|
||||
// 文章
|
||||
listArticles: () => request({ url: '/api/articles' }),
|
||||
|
||||
Reference in New Issue
Block a user