Files

473 lines
10 KiB
Plaintext

<template>
<view class="card-panel">
<!-- 用户信息 -->
<view class="card-panel-header">
<view class="user-info" @click="onUserClick">
<image class="avatar" :src="moment.userAvatar" mode="aspectFill"></image>
<view class="user-details">
<view class="user-name-row">
<text class="user-name">{{ moment.userName }}</text>
<text v-if="moment.userVip" class="vip-badge">V</text>
<text v-if="moment.hot" class="hot-badge">🔥</text>
</view>
<view class="meta-info">
<text class="location">{{ moment.location }}</text>
<text class="time">{{ formatTime(moment.time) }}</text>
</view>
</view>
</view>
<view class="more-btn" @click="onMoreClick">
<uni-icons type="more" size="20" color="#999"></uni-icons>
</view>
</view>
<!-- 动态内容 -->
<view class="card-panel-body" @click="onContentClick">
<text class="content-text">{{ moment.content }}</text>
<!-- 图片内容 -->
<view v-if="moment.type === 'image' && moment.images.length > 0" class="image-content">
<view v-if="moment.images.length == 1" class="single-image" @click="previewImage(0)">
<image class="image-item" :src="moment.images[0]" mode="aspectFill"></image>
</view>
<view v-else-if="moment.images.length < 3" class="multi-images-row">
<view v-for="(img, index) in moment.images" :key="index" class="image-item-small"
@click="previewImage(index)">
<image class="image" :src="img" mode="aspectFill"></image>
</view>
</view>
<view v-else class="multi-images-grid">
<view v-for="(img, index) in moment.images.slice(0, 4)" :key="index" class="grid-image"
:class="{ 'last-image': index == 3 && moment.images.length > 4 }" @click="previewImage(index)">
<image class="image" :src="img" mode="aspectFill"></image>
<view v-if="index == 3 && moment.images.length > 4" class="image-count">
+{{ moment.images.length - 4 }}
</view>
</view>
</view>
</view>
<!-- 视频内容 -->
<view v-else-if="moment.type === 'video'" class="video-content" @click="playVideo">
<image v-if="moment.images.length > 0" class="video-cover" :src="moment.images[0] " mode="aspectFill">
</image>
<view class="video-play-btn">
<uni-icons type="play" size="40" color="#fff"></uni-icons>
</view>
<view class="video-duration">03:25</view>
</view>
<!-- 标签 -->
<view v-if="moment.tags != null" class="moment-tags">
<view v-for="(tag, index) in moment.tags" :key="index" class="tag-item">
<text class="tag-text">#{{ tag }}</text>
</view>
</view>
</view>
<!-- 互动操作栏 -->
<view class="card-panel-footer">
<view class="action-item" @click="onLikeClick">
<uni-icons :type="moment.isLiked ? 'heart-filled' : 'heart'" size="20"
:color="moment.isLiked ? '#FF2D55' : '#666'"></uni-icons>
<text class="action-text" :style="{ color: moment.isLiked ? '#FF2D55' : '#666' }">
{{ formatNumber(moment.likes) }}
</text>
</view>
<view class="action-item" @click="onCommentClick">
<uni-icons type="chat" size="20" color="#666"></uni-icons>
<text class="action-text">{{ formatNumber(moment.comments) }}</text>
</view>
<view class="action-item" @click="onShareClick">
<uni-icons type="redo" size="20" color="#666"></uni-icons>
<text class="action-text">{{ formatNumber(moment.shares) }}</text>
</view>
<view class="action-item distance" v-if="moment.distance !=0 && moment.distance < 50">
<uni-icons type="location" size="16" color="#999"></uni-icons>
<text class="distance-text">{{ formatDistance(moment.distance) }}</text>
</view>
</view>
</view>
</template>
<script setup lang="uts">
import { IMoment } from '@/types/dynamicType.uts'
const props = defineProps<{
moment : IMoment
}>()
const emit = defineEmits<{
like : [id: number]
comment : [id: number]
share : [id: number]
more : [id: number]
}>()
// 格式化时间
const formatTime = (timestamp : number) : string => {
const now = Date.now()
const diff = now - timestamp
if (diff < 60000) { // 1分钟内
return '刚刚'
} else if (diff < 3600000) { // 1小时内
return Math.floor(diff / 60000) + '分钟前'
} else if (diff < 86400000) { // 1天内
return Math.floor(diff / 3600000) + '小时前'
} else if (diff < 604800000) { // 1周内
return Math.floor(diff / 86400000) + '天前'
} else {
const date = new Date(timestamp)
return `${date.getMonth() + 1}月${date.getDate()}日`
}
}
// 格式化数字
const formatNumber = (num : number) : string => {
if (num >= 10000) {
return (num / 10000).toFixed(1) + 'w'
} else if (num >= 1000) {
return (num / 1000).toFixed(1) + 'k'
}
return num.toString()
}
// 格式化距离
const formatDistance = (distance : number) : string => {
if (distance < 1) {
return '<1km'
} else if (distance < 10) {
return distance.toFixed(1) + 'km'
} else {
return Math.floor(distance) + 'km'
}
}
// 点击用户
const onUserClick = () => {
console.log('点击用户:', props.moment.userName)
uni.navigateTo({
url: `/pages/user-detail/user-detail?id=${props.moment.userId}`
})
}
// 点击更多
const onMoreClick = () => {
emit('more', props.moment.id)
}
// 点击内容
const onContentClick = () => {
console.log('点击动态内容:', props.moment.id)
let page = `/pages/moment/details?id=${props.moment.id}`;
console.log(page)
uni.navigateTo({
url: page
})
}
// 预览图片
const previewImage = (index : number) => {
console.log('预览图片:', index)
uni.previewImage({
current: index,
urls: props.moment.images
})
}
// 播放视频
const playVideo = () => {
console.log('播放视频')
uni.navigateTo({
url: `/pages/video-player/video-player?url=${encodeURIComponent(props.moment.videoUrl)}`
})
}
// 点赞
const onLikeClick = () => {
emit('like', props.moment.id)
}
// 评论
const onCommentClick = () => {
emit('comment', props.moment.id)
}
// 分享
const onShareClick = () => {
emit('share', props.moment.id)
}
</script>
<style>
/* 用户信息 */
.user-info {
display: flex;
flex-flow: row nowrap;
align-items: center;
flex: 1;
}
.avatar {
width: 80rpx;
height: 80rpx;
border-radius: 50%;
margin-right: 20rpx;
background-color: #f0f0f0;
}
.user-details {
flex: 1;
}
.user-name-row {
display: flex;
flex-flow: row nowrap;
align-items: center;
margin-bottom: 8rpx;
}
.user-name {
font-size: 30rpx;
font-weight: bold;
color: #333;
margin-right: 10rpx;
max-width: 200rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.vip-badge {
background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
color: #fff;
font-size: 20rpx;
padding: 3rpx 10rpx;
border-radius: 20rpx;
margin-right: 10rpx;
}
.hot-badge {
background-color: #f30f025c;
color: #fff;
font-size: 20rpx;
padding: 3rpx 10rpx;
border-radius: 20rpx;
}
.meta-info {
display: flex;
flex-flow: row nowrap;
align-items: center;
flex-wrap: wrap;
}
.location,
.time {
font-size: 24rpx;
color: #999;
margin-right: 20rpx;
}
.more-btn {
width: 60rpx;
height: 60rpx;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
background-color: #f8f8f8;
}
/* 动态内容 */
.moment-content {
margin-bottom: 25rpx;
}
.content-text {
font-size: 30rpx;
color: #333;
line-height: 1.5;
margin-bottom: 20rpx;
display: flex;
overflow: hidden;
}
/* 图片内容 */
.image-content {
margin: 20rpx 0;
}
.single-image {
width: 100%;
height: 400rpx;
border-radius: 20rpx;
overflow: hidden;
}
.image-item {
width: 100%;
height: 100%;
background-color: #f0f0f0;
}
.multi-images-row {
display: flex;
flex-flow: row nowrap;
margin-bottom: 20rpx;
}
.image-item-small {
flex: 1;
height: 375rpx;
border-radius: 20rpx;
overflow: hidden;
padding: 5rpx;
}
.image-item-small .image {
width: 100%;
height: 100%;
background-color: #f0f0f0;
}
.multi-images-grid {
display: flex;
flex-flow: row wrap;
overflow: hidden;
}
.grid-image {
margin: 5rpx;
position: relative;
flex-basis: 210rpx;
height: 230rpx;
box-sizing: border-box;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.grid-image .image {
width: 100%;
height: 100%;
background-color: #f0f0f0;
}
.grid-image.last-image::after {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
}
.image-count {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 40rpx;
color: #fff;
font-weight: bold;
z-index: 1;
}
/* 视频内容 */
.video-content {
position: relative;
height: 400rpx;
border-radius: 20rpx;
overflow: hidden;
margin: 20rpx 0;
}
.video-cover {
width: 100%;
height: 100%;
background-color: #000;
}
.video-play-btn {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100rpx;
height: 100rpx;
background-color: rgba(0, 0, 0, 0.6);
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
}
.video-duration {
position: absolute;
bottom: 20rpx;
right: 20rpx;
padding: 8rpx 20rpx;
background-color: rgba(0, 0, 0, 0.7);
border-radius: 20rpx;
}
/* 标签 */
.moment-tags {
display: flex;
flex-flow: row nowrap;
margin-top: 20rpx;
}
.tag-item {
padding: 8rpx 20rpx;
background-color: #f0f0f0;
border-radius: 20rpx;
}
.tag-text {
font-size: 24rpx;
color: #007AFF;
}
/* 互动操作栏 */
.action-bar {
display: flex;
flex-flow: row nowrap;
align-items: center;
padding-top: 20rpx;
border-top: 1rpx solid #f0f0f0;
}
.action-item {
display: flex;
align-items: center;
margin-right: 40rpx;
padding: 10rpx 0;
}
.action-item .uni-icons {
margin-right: 10rpx;
}
.action-text {
font-size: 24rpx;
color: #666;
}
.action-item.distance {
margin-left: auto;
margin-right: 0;
}
.distance-text {
font-size: 24rpx;
color: #999;
margin-left: 8rpx;
}
</style>