import { useState } from 'react'; import { useNavigate } from '@remix-run/react'; interface Template { id: string; title: string; type: string; description: string; updateTime: string; useCount: number; rating: number; category: string; } interface TemplateCardProps { template: Template; onClick: () => void; } export function TemplateCard({ template, onClick }: TemplateCardProps) { const [isFavorited, setIsFavorited] = useState(false); const navigate = useNavigate(); const handleFavoriteClick = (e: React.MouseEvent) => { e.stopPropagation(); setIsFavorited(!isFavorited); }; const handleActionClick = (e: React.MouseEvent, action: string) => { e.stopPropagation(); switch (action) { case '立即使用': console.log('下载并使用模板:', template.id); // 这里应该触发下载逻辑 break; case '预览': // 导航到模板详情页面 navigate(`/contract-template/detail/${template.id}`); break; default: console.log(`执行操作: ${action}`, template.id); } }; const renderStars = (rating: number) => { const stars = []; const fullStars = Math.floor(rating); const hasHalfStar = rating % 1 !== 0; for (let i = 0; i < 5; i++) { if (i < fullStars) { stars.push(); } else if (i === fullStars && hasHalfStar) { stars.push(); } else { stars.push(); } } return stars; }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onClick(); } }; return (
{template.type}
{renderStars(template.rating)} {template.rating}

{template.title}

{template.description}

更新时间:{template.updateTime} 使用次数:{template.useCount.toLocaleString()}
); }