File size: 3,620 Bytes
e85fa50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4fc8eae
 
 
 
 
 
e85fa50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import React from 'react';
import { useNavigate } from 'react-router-dom';
import { PromptGroup } from '../../types';
import Card, { CardHeader, CardContent, CardFooter } from '../common/Card';
import CategoryBadge from '../Category/CategoryBadge';
import { useApp } from '../../contexts/AppContext';

interface PromptGroupCardProps {
  promptGroup: PromptGroup;
  className?: string;
}

const PromptGroupCard: React.FC<PromptGroupCardProps> = ({

  promptGroup,

  className = ''

}) => {
  const navigate = useNavigate();
  const { categories } = useApp();
  
  // 查找分类对象 - 支持两种可能的数据结构
  const categoryId = typeof promptGroup.category === 'object' 
    ? promptGroup.category._id 
    : promptGroup.category;
    
  const category = categories.find(c => c._id === categoryId);
  
  const handleClick = () => {
    navigate(`/prompt-group/${promptGroup._id}`);
  };
  
  const formatDate = (date: string | Date) => {
    const dateObj = typeof date === 'string' ? new Date(date) : date;
    return dateObj.toLocaleDateString('zh-CN', {
      year: 'numeric',
      month: 'long',
      day: 'numeric'
    });
  };

  return (
    <Card 

      className={`${className}`} 

      hoverable 

      onClick={handleClick}

    >

      <CardHeader 

        title={promptGroup.name}

        subtitle={formatDate(promptGroup.updatedAt)}

        action={category && <CategoryBadge category={category} />}

      />

      <CardContent>

        <p className="text-gray-600 line-clamp-2">{promptGroup.description || '无描述'}</p>

        <div className="mt-3 flex items-center text-sm text-gray-500">

          <div className="flex items-center mr-4">

            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="mr-1">

              <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>

              <polyline points="14 2 14 8 20 8"></polyline>

              <line x1="16" y1="13" x2="8" y2="13"></line>

              <line x1="16" y1="17" x2="8" y2="17"></line>

              <polyline points="10 9 9 9 8 9"></polyline>

            </svg>

            {promptGroup.prompts.length} 个提示词

          </div>

          <div className="flex items-center">

            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="mr-1">

              <path d="M22 12h-4l-3 9L9 3l-3 9H2"></path>

            </svg>

            {promptGroup.workflows.length} 个工作流

          </div>

        </div>

      </CardContent>

      <CardFooter className="flex justify-between items-center">

        <div className="text-xs text-gray-500">

          创建于 {formatDate(promptGroup.createdAt)}

        </div>

        <button 

          className="text-blue-500 flex items-center"

          onClick={(e) => {

            e.stopPropagation();

            navigate(`/prompt-group/${promptGroup._id}`);

          }}

        >

          查看详情

          <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="ml-1">

            <polyline points="9 18 15 12 9 6"></polyline>

          </svg>

        </button>

      </CardFooter>

    </Card>
  );
};

export default PromptGroupCard;