blob: 1d3ac22347e3189a2dcea62cfd2550eab187d164 [file] [log] [blame]
22301014356527a2025-06-09 17:46:56 +08001import React from 'react';
2import { Card, Typography, Space } from 'antd';
3import { EyeOutlined, UserOutlined } from '@ant-design/icons';
4import type { WorkCardProps } from './types';
5import { useNavigate } from 'react-router';
6
7const { Text, Title } = Typography;
8const { Meta } = Card;
9
10const WorkCard: React.FC<WorkCardProps> = ({ artwork }) => {
11 const handleImageError = (e: React.SyntheticEvent<HTMLImageElement, Event>) => {
12 const target = e.target as HTMLImageElement;
13 target.src = 'https://via.placeholder.com/300x200?text=No+Image';
14 };
15 const nav = useNavigate()
16 const handleClick = () => {
17 nav(`/work/${artwork.id}`)
18 }
19
20 const formatViews = (views: number): string => {
21 return views.toLocaleString();
22 };
23
24 return (
25 <Card
26 hoverable
27 style={{ marginBottom: 16 }}
28 cover={
29 <img
30 alt={artwork.title}
31 src={artwork.cover}
32 style={{
33 height: 200,
34 objectFit: 'cover',
35 borderRadius: '8px 8px 0 0'
36 }}
37 onError={handleImageError}
38 />
39 }
40 actions={[
41 <Space key="views">
42 <EyeOutlined />
43 <Text type="secondary">{formatViews(artwork.views)}</Text>
44 </Space>,
45 <Space key="author">
46 <UserOutlined />
47 <Text type="secondary">{artwork.author}</Text>
48 </Space>,
49 ]}
50 onClick={handleClick}
51 >
52 <Meta
53 title={
54 <div style={{ marginBottom: 8 }}>
55 <Title level={4} style={{ margin: 0, fontSize: 16 }}>
56 {artwork.title}
57 </Title>
58 </div>
59 }
60 description={
61 <Space direction="vertical" size="small" style={{ width: '100%' }}>
62 <Text type="secondary" style={{ fontSize: 12 }}>
63 分类: {artwork.category.name}
64 </Text>
65 {artwork.category.children.length > 0 && (
66 <Space wrap size={[4, 4]}>
67 {artwork.category.children.map((child, index) => (
68 <Text
69 key={index}
70 code
71 style={{
72 fontSize: 11,
73 padding: '2px 6px',
74 backgroundColor: '#f5f5f5',
75 borderRadius: 4
76 }}
77 >
78 {child}
79 </Text>
80 ))}
81 </Space>
82 )}
83 </Space>
84 }
85 />
86 </Card>
87 );
88};
89
90export default WorkCard;