/** * 帖子卡片组件 - 类似小红书风格 * 用于论坛主页的帖子展示 */ import React from 'react'; import { Box, Image, Text, HStack, VStack, Avatar, Badge, IconButton, Flex, useColorModeValue, } from '@chakra-ui/react'; import { motion } from 'framer-motion'; import { Heart, MessageCircle, Eye, TrendingUp } from 'lucide-react'; import { useNavigate } from 'react-router-dom'; import { forumColors } from '@theme/forumTheme'; const MotionBox = motion(Box); const PostCard = ({ post }) => { const navigate = useNavigate(); // 处理卡片点击 const handleCardClick = () => { navigate(`/value-forum/post/${post.id}`); }; // 格式化数字(1000 -> 1k) const formatNumber = (num) => { if (num >= 1000000) return `${(num / 1000000).toFixed(1)}M`; if (num >= 1000) return `${(num / 1000).toFixed(1)}K`; return num; }; // 格式化时间 const formatTime = (dateString) => { const date = new Date(dateString); const now = new Date(); const diff = now - date; const minutes = Math.floor(diff / 60000); const hours = Math.floor(diff / 3600000); const days = Math.floor(diff / 86400000); if (minutes < 1) return '刚刚'; if (minutes < 60) return `${minutes}分钟前`; if (hours < 24) return `${hours}小时前`; if (days < 7) return `${days}天前`; return date.toLocaleDateString('zh-CN', { month: '2-digit', day: '2-digit' }); }; return ( {/* 封面图片区域 */} {post.images && post.images.length > 0 && ( {post.title} {/* 置顶标签 */} {post.is_pinned && ( 置顶 )} )} {/* 内容区域 */} {/* 标题 */} {post.title} {/* 内容预览 */} {post.content && ( {post.content} )} {/* 标签 */} {post.tags && post.tags.length > 0 && ( {post.tags.slice(0, 3).map((tag, index) => ( #{tag} ))} )} {/* 底部信息栏 */} {/* 作者信息 */} {post.author_name} {/* 互动数据 */} {formatNumber(post.likes_count || 0)} {formatNumber(post.comments_count || 0)} {formatNumber(post.views_count || 0)} {/* 时间 */} {formatTime(post.created_at)} ); }; export default PostCard;