You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import { ReactComponent as MoreIcon } from '@/assets/svg/more.svg';
  2. import { KnowledgeRouteKey } from '@/constants/knowledge';
  3. import { useShowDeleteConfirm } from '@/hooks/commonHooks';
  4. import { IKnowledge } from '@/interfaces/database/knowledge';
  5. import { formatDate } from '@/utils/date';
  6. import {
  7. CalendarOutlined,
  8. DeleteOutlined,
  9. FileTextOutlined,
  10. UserOutlined,
  11. } from '@ant-design/icons';
  12. import { Avatar, Card, Dropdown, MenuProps, Space } from 'antd';
  13. import { useTranslation } from 'react-i18next';
  14. import { useDispatch, useNavigate } from 'umi';
  15. import styles from './index.less';
  16. interface IProps {
  17. item: IKnowledge;
  18. }
  19. const KnowledgeCard = ({ item }: IProps) => {
  20. const navigate = useNavigate();
  21. const dispatch = useDispatch();
  22. const showDeleteConfirm = useShowDeleteConfirm();
  23. const { t } = useTranslation();
  24. const removeKnowledge = () => {
  25. return dispatch({
  26. type: 'knowledgeModel/rmKb',
  27. payload: {
  28. kb_id: item.id,
  29. },
  30. });
  31. };
  32. const handleDelete = () => {
  33. showDeleteConfirm({ onOk: removeKnowledge });
  34. };
  35. const items: MenuProps['items'] = [
  36. {
  37. key: '1',
  38. label: (
  39. <Space>
  40. {t('common.delete')}
  41. <DeleteOutlined />
  42. </Space>
  43. ),
  44. },
  45. ];
  46. const handleDropdownMenuClick: MenuProps['onClick'] = ({ domEvent, key }) => {
  47. domEvent.preventDefault();
  48. domEvent.stopPropagation();
  49. if (key === '1') {
  50. handleDelete();
  51. }
  52. };
  53. const handleCardClick = () => {
  54. navigate(`/knowledge/${KnowledgeRouteKey.Dataset}?id=${item.id}`, {
  55. state: { from: 'list' },
  56. });
  57. };
  58. return (
  59. <Card className={styles.card} onClick={handleCardClick}>
  60. <div className={styles.container}>
  61. <div className={styles.content}>
  62. <Avatar size={34} icon={<UserOutlined />} src={item.avatar} />
  63. <Dropdown
  64. menu={{
  65. items,
  66. onClick: handleDropdownMenuClick,
  67. }}
  68. >
  69. <span className={styles.delete}>
  70. <MoreIcon />
  71. </span>
  72. </Dropdown>
  73. </div>
  74. <div className={styles.titleWrapper}>
  75. <span className={styles.title}>{item.name}</span>
  76. <p>{item.description}</p>
  77. </div>
  78. <div className={styles.footer}>
  79. <div className={styles.footerTop}>
  80. <div className={styles.bottomLeft}>
  81. <FileTextOutlined className={styles.leftIcon} />
  82. <span className={styles.rightText}>
  83. <Space>
  84. {item.doc_num}
  85. {t('knowledgeList.doc')}
  86. </Space>
  87. </span>
  88. </div>
  89. </div>
  90. <div className={styles.bottom}>
  91. <div className={styles.bottomLeft}>
  92. <CalendarOutlined className={styles.leftIcon} />
  93. <span className={styles.rightText}>
  94. {formatDate(item.update_time)}
  95. </span>
  96. </div>
  97. {/* <Avatar.Group size={25}>
  98. <Avatar src="https://api.dicebear.com/7.x/miniavs/svg?seed=1" />
  99. <a href="https://ant.design">
  100. <Avatar style={{ backgroundColor: '#f56a00' }}>K</Avatar>
  101. </a>
  102. <Tooltip title="Ant User" placement="top">
  103. <Avatar
  104. style={{ backgroundColor: '#87d068' }}
  105. icon={<UserOutlined />}
  106. />
  107. </Tooltip>
  108. <Avatar
  109. style={{ backgroundColor: '#1677ff' }}
  110. icon={<AntDesignOutlined />}
  111. />
  112. </Avatar.Group> */}
  113. </div>
  114. </div>
  115. </div>
  116. </Card>
  117. );
  118. };
  119. export default KnowledgeCard;