fix(fe): 保存到相册的方法根本没写进去 + 重构社区版式
## 保存到相册点了没反应 上次改的时候,插入方法的锚点用的是「// AI 聊天」那段注释,而它在 AI 独立成页时已经被删掉了 —— 替换没匹配上,onSavePoster / drawPoster / saveToAlbum 三个方法一个都没进 js,按钮绑了个不存在的方法。 我的检查器没拦住,是因为「事件绑定是否有实现」那条写在临时的 audit.js 里,日常只跑 check.js。已经把这条并进 check.js —— 加完立刻抓出了本次 新写的 13 处缺样式 class,说明它管用。 ## 社区 帖子操作栏原来是 space-around 排三个宽度不一的项:点赞数从 9 变 10 整行就会跳。改成三等分,图标 32rpx 居中对齐,没有数字时显示「点赞/评论」 而不是一个孤零零的 0,加了按下态。 帖子头部原来副标题固定写死「宠友」两个字,等于没有信息。换成发布时间 (刚刚 / 12 分钟前 / 3 天前)。 评论弹层原来拿 .record-row 当评论用 —— 那是个「左右两端对齐」的行, 昵称在左内容在右,评论一长就被挤扁,完全不是评论该有的样子。重做成 头像 + 昵称/时间 + 内容的正常结构;没有头像字段就用昵称首字做色块, 比一律显示同一个 emoji 强。发送按钮有输入才点亮,支持键盘回车发送。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,21 @@ const store = require('../../utils/store.js');
|
||||
const api = require('../../utils/api.js');
|
||||
const { toastErr } = require('../../utils/ui.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) {
|
||||
@@ -22,6 +37,7 @@ function mapPost(p) {
|
||||
user_id: p.user_id,
|
||||
followed: !!p.followed,
|
||||
is_self: !!p.is_self,
|
||||
timeText: fmtAgo(p.created_at),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,10 @@ module.exports.isUrl = function (s) { return s && s.indexOf('http') === 0; }
|
||||
<view wx:for="{{posts}}" wx:key="id" class="post-card" bindlongpress="onLongPressPost" data-index="{{index}}">
|
||||
<view class="post-head">
|
||||
<view class="post-avatar">{{item.author_emoji}}</view>
|
||||
<view class="post-user"><text class="pu-b">{{item.author_name}}<text wx:if="{{item.is_ai}}" class="ai-tag">AI</text></text><text class="pu-s">宠友</text></view>
|
||||
<view class="post-user">
|
||||
<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>
|
||||
@@ -27,9 +30,18 @@ module.exports.isUrl = function (s) { return s && s.indexOf('http') === 0; }
|
||||
</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="{{30}}"></pt-icon>{{item.like_count}}</view>
|
||||
<view class="pa-btn" data-id="{{item.id}}" bindtap="openComments"><pt-icon name="comment" size="{{30}}"></pt-icon>{{item.comment_count}}</view>
|
||||
<button class="pa-btn pa-share" open-type="share" data-content="{{item.content}}"><pt-icon name="share" size="{{30}}"></pt-icon>分享</button>
|
||||
<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>
|
||||
<view 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>
|
||||
|
||||
|
||||
@@ -21,14 +21,18 @@
|
||||
display:flex;align-items:center;justify-content:center;font-size:56rpx;
|
||||
}
|
||||
|
||||
.post-actions{display:flex;justify-content:space-around;border-top:1rpx solid var(--line);padding-top:var(--sp-3)}
|
||||
/* 三等分。原来是 space-around 排三个宽度不一的项,点赞数一变宽度就跳 */
|
||||
.post-actions{display:flex;border-top:1rpx solid var(--line);padding-top:var(--sp-2)}
|
||||
.pa-btn{
|
||||
display:flex;align-items:center;gap:var(--sp-1);
|
||||
color:var(--muted);font-weight:var(--fw-b);font-size:var(--fs-sm);
|
||||
flex:1;height:72rpx;
|
||||
display:flex;align-items:center;justify-content:center;gap:var(--sp-1);
|
||||
color:var(--muted);font-weight:var(--fw);font-size:var(--fs-sm);
|
||||
}
|
||||
.pa-n{line-height:1}
|
||||
.pa-btn.liked{color:var(--red-ink)}
|
||||
.pa-btn:active{background:var(--surface-2);border-radius:var(--r-sm)}
|
||||
/* 分享用微信原生 open-type=share,得抹掉 button 默认外观 */
|
||||
.pa-share{background:transparent;border:none;padding:0;margin:0;line-height:inherit;height:auto}
|
||||
.pa-share{background:transparent;border:none;padding:0;margin:0;line-height:inherit}
|
||||
.pa-share::after{border:none}
|
||||
|
||||
/* 关注按钮 */
|
||||
|
||||
Reference in New Issue
Block a user