blob: 947ecc310fd8f54681217366470c0d06905b7a8d [file] [log] [blame]
meisiyu1d4aade2025-06-02 20:10:36 +08001import React from 'react';
2import { Card, Tag, Button, Avatar, Badge } from 'antd';
3import { EyeOutlined, CommentOutlined, UserOutlined, ClockCircleOutlined, HeartOutlined, CrownOutlined } from '@ant-design/icons';
4import { history } from 'umi';
5import styles from './PostCard.module.css';
6import { Post } from '../PostCenter/types';
7
8interface PostCardProps {
9 post: Post;
10}
11
12const PostCard: React.FC<PostCardProps> = ({ post }) => {
13 const {
14 id,
15 title,
16 author,
17 publishTime,
18 tags,
19 views,
20 comments,
21 favorites,
22 likes,
23 coverImage,
24 summary,
25 promotionPlanId,
26 isPromoted
27 } = post;
28
29 const goToDetail = () => {
30 history.push(`/post-detail/${id}`);
31 };
32
33 return (
34 <div className={styles.postCardWrapper}>
35 <Card
36 hoverable
37 cover={
38 <div className={styles.coverContainer}>
39 {isPromoted && (
40 <div className={styles.promotionBadge}>
41 <CrownOutlined />
42 <span>推广</span>
43 </div>
44 )}
45 <img
46 alt={title}
47 src={coverImage}
48 className={styles.coverImage}
49 onError={(e) => {
50 e.currentTarget.src = '/images/404.png';
51 }}
52 />
53 </div>
54 }
55 className={styles.postCard}
56 bodyStyle={{ padding: '16px', height: '240px', display: 'flex', flexDirection: 'column' }}
57 >
58 <div className={styles.cardContent}>
59 <h3 className={styles.postTitle} title={title}>{title}</h3>
60
61 <div className={styles.postMeta}>
62 <Avatar size="small" style={{ marginRight: 6 }} icon={<UserOutlined />}>
63 {author && author[0]}
64 </Avatar>
65 <span className={styles.authorName}>{author}</span>
66 <ClockCircleOutlined style={{ marginLeft: 12, marginRight: 4 }} />
67 <span className={styles.publishTime}>{publishTime}</span>
68 </div>
69
70 <div className={styles.tagsContainer}>
71 {(Array.isArray(tags) ? tags : []).slice(0, 3).map(tag => (
72 <Tag color="blue" key={tag} className={styles.tag}>{tag}</Tag>
73 ))}
74 {tags && tags.length > 3 && (
75 <Tag color="default" className={styles.tag}>+{tags.length - 3}</Tag>
76 )}
77 </div>
78
79 <div className={styles.postSummary} title={summary}>{summary}</div>
80
81 <div className={styles.postFooter}>
82 <div className={styles.stats}>
83 <span className={styles.statItem}>
84 <EyeOutlined /> {views || 0}
85 </span>
86 <span className={styles.statItem}>
87 <CommentOutlined /> {comments || 0}
88 </span>
89 <span className={styles.statItem}>
90 <HeartOutlined /> {favorites || 0}
91 </span>
92 </div>
93 <Button
94 type="link"
95 className={styles.readMoreBtn}
96 onClick={goToDetail}
97 >
98 查看更多 »
99 </Button>
100 </div>
101 </div>
102 </Card>
103 </div>
104 );
105};
106
107export default PostCard;