blob: f038b9019f30db833e2acaa7e51922b88095cdf4 [file] [log] [blame]
Krishyadbfadaa2025-06-09 20:33:15 +08001import React from 'react';
2
3const TorrentDetailDialog = ({
4 showTorrentDialog,
5 torrentDetail,
6 closeTorrentDialog
7}) => {
8 const formatSize = (bytes) => {
9 if (bytes === 0) return '0 B';
10
11 const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
12 const i = Math.floor(Math.log(bytes) / Math.log(1024));
13
14 return parseFloat((bytes / Math.pow(1024, i)).toFixed(2)) + ' ' + sizes[i];
15 };
16
17 const formatDateTime = (dateTime) => {
18 if (!dateTime) return '未知';
19 return new Date(dateTime).toLocaleString();
20 };
21
22 return (
23 showTorrentDialog && torrentDetail && (
24 <div className="torrent-detail-overlay">
25 <div className="torrent-detail-dialog">
26 <h3 className="torrent-detail-title">种子详情 - {torrentDetail.title}</h3>
27 <button
28 className="close-btn"
29 onClick={closeTorrentDialog}
30 >
31 &times;
32 </button>
33
34 {/* 封面图片 */}
35 {torrentDetail.coverImage && (
36 <div className="torrent-cover-container">
37 <img
38 src={torrentDetail.coverImage}
39 alt={`${torrentDetail.name}封面`}
40 className="torrent-cover"
41 />
42 </div>
43 )}
44
45 <div className="torrent-detail-content">
46 <div className="torrent-detail-item">
47 <span className="torrent-detail-label">种子ID:</span>
48 <span className="torrent-detail-value">{torrentDetail.id}</span>
49 </div>
50 <div className="torrent-detail-item">
51 <span className="torrent-detail-label">种子名称:</span>
52 <span className="torrent-detail-value">{torrentDetail.title}</span>
53 </div>
54 <div className="torrent-detail-item">
55 <span className="torrent-detail-label">分类:</span>
56 <span className="torrent-detail-value">{torrentDetail.category || '未分类'}</span>
57 </div>
58 <div className="torrent-detail-item">
59 <span className="torrent-detail-label">大小:</span>
60 <span className="torrent-detail-value">{formatSize(torrentDetail.size)}</span>
61 </div>
62 <div className="torrent-detail-item">
63 <span className="torrent-detail-label">上传者:</span>
64 <span className="torrent-detail-value">{torrentDetail.username || '匿名'}</span>
65 </div>
66 <div className="torrent-detail-item">
67 <span className="torrent-detail-label">上传时间:</span>
68 <span className="torrent-detail-value">{formatDateTime(torrentDetail.createTime)}</span>
69 </div>
70 <div className="torrent-detail-item">
71 <span className="torrent-detail-label">做种人数:</span>
72 <span className="torrent-detail-value">{torrentDetail.seeders || 0}</span>
73 </div>
74 <div className="torrent-detail-item">
75 <span className="torrent-detail-label">下载人数:</span>
76 <span className="torrent-detail-value">{torrentDetail.leechers || 0}</span>
77 </div>
78 <div className="torrent-detail-item">
79 <span className="torrent-detail-label">完成次数:</span>
80 <span className="torrent-detail-value">{torrentDetail.completed || 0}</span>
81 </div>
82
83 {/* 种子状态 */}
84 <div className="torrent-detail-item">
85 <span className="torrent-detail-label">状态:</span>
86 <span className="torrent-detail-value">
87 {torrentDetail.seeders > 10 ? (
88 <span className="status-badge hot">热门</span>
89 ) : torrentDetail.seeders === 0 ? (
90 <span className="status-badge cold">冷门</span>
91 ) : (
92 <span className="status-badge normal">普通</span>
93 )}
94 </span>
95 </div>
96
97 {/* 种子描述 */}
98 {torrentDetail.description && (
99 <div className="torrent-detail-item">
100 <span className="torrent-detail-label">描述:</span>
101 <div className="torrent-detail-value description">{torrentDetail.description}</div>
102 </div>
103 )}
104
105 {/* 下载链接 */}
106 {torrentDetail.downloadUrl && (
107 <div className="torrent-detail-item">
108 <span className="torrent-detail-label">下载:</span>
109 <a
110 href={torrentDetail.downloadUrl}
111 target="_blank"
112 rel="noopener noreferrer"
113 className="download-link"
114 >
115 <i className="fa fa-download"></i> 下载种子
116 </a>
117 </div>
118 )}
119 </div>
120
121 <div className="dialog-buttons">
122 <button onClick={closeTorrentDialog}>关闭</button>
123 </div>
124 </div>
125 </div>
126 )
127 );
128};
129
130export default TorrentDetailDialog;