Browse Source

提供完整的动态展示

蛋吧eggbar
徐飞洋 1 month ago
parent
commit
e053af9a1e
  1. 49
      pages/eggbar/eggbar.js
  2. 5
      pages/eggbar/eggbar.wxml
  3. 14
      pages/eggbar/eggbar.wxss

49
pages/eggbar/eggbar.js

@ -157,6 +157,32 @@ Page({
}); });
} }
// 确保topic字段存在
if (post.topic) {
console.log('动态话题:', post.topic);
}
// 为了兼容前端模板,添加user对象
if (!post.user) {
post.user = {
avatar: post.avatar_url || '',
nickname: post.username
};
}
// 为了兼容前端模板,添加image字段(使用images数组的第一个元素)
if (!post.image && post.images && post.images.length > 0) {
post.image = post.images[0];
}
// 为了兼容前端模板,添加like_count和comment_count字段
if (post.likes !== undefined && post.like_count === undefined) {
post.like_count = post.likes;
}
if (post.comments !== undefined && post.comment_count === undefined) {
post.comment_count = post.comments;
}
return post; return post;
}); });
@ -362,6 +388,29 @@ Page({
}); });
}, },
// 预览图片
previewImage(e) {
const images = e.currentTarget.dataset.images;
const currentIndex = parseInt(e.currentTarget.dataset.current);
console.log('预览图片:', {
images,
currentIndex,
current: images[currentIndex]
});
wx.previewImage({
current: images[currentIndex],
urls: images,
success: function(res) {
console.log('预览图片成功:', res);
},
fail: function(err) {
console.error('预览图片失败:', err);
}
});
},
createPost() { createPost() {
wx.navigateTo({ wx.navigateTo({
url: '/pages/eggbar/create-post' url: '/pages/eggbar/create-post'

5
pages/eggbar/eggbar.wxml

@ -38,7 +38,10 @@
<view class="post-content"> <view class="post-content">
<text class="post-text">{{item.content}}</text> <text class="post-text">{{item.content}}</text>
<view class="post-images" wx:if="{{item.images && item.images.length > 0}}"> <view class="post-images" wx:if="{{item.images && item.images.length > 0}}">
<image class="post-image" wx:for="{{item.images}}" wx:for-item="img" wx:key="index" src="{{img}}" mode="aspectFill"></image> <image class="post-image" wx:for="{{item.images}}" wx:for-item="img" wx:key="index" src="{{img}}" mode="aspectFill" bindtap="previewImage" data-images="{{item.images}}" data-current="{{index}}"></image>
</view>
<view class="post-topic" wx:if="{{item.topic}}">
<text class="topic-text">#{{item.topic}}</text>
</view> </view>
</view> </view>
<view class="post-footer"> <view class="post-footer">

14
pages/eggbar/eggbar.wxss

@ -182,6 +182,20 @@ page {
background: #f0f0f0; background: #f0f0f0;
} }
.post-topic {
margin-top: 15rpx;
padding: 8rpx 16rpx;
background: #f0f8ff;
border-radius: 20rpx;
display: inline-block;
}
.topic-text {
font-size: 24rpx;
color: #1890ff;
font-weight: 500;
}
.post-footer { .post-footer {
display: flex; display: flex;
justify-content: space-around; justify-content: space-around;

Loading…
Cancel
Save