ReferencesContent.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import MarkDownContext from '@/new-components/common/MarkdownContext';
  2. import { LinkOutlined } from '@ant-design/icons';
  3. import type { TabsProps } from 'antd';
  4. import { Divider, Drawer, Tabs, Typography } from 'antd';
  5. import { useRouter } from 'next/router';
  6. import React, { useMemo, useState } from 'react';
  7. const ReferencesContentView: React.FC<{ references: any }> = ({ references }) => {
  8. const router = useRouter();
  9. const [open, setOpen] = useState<boolean>(false);
  10. // 是否移动端页面
  11. const isMobile = useMemo(() => {
  12. return router.pathname.includes('/mobile');
  13. }, [router]);
  14. const items: TabsProps['items'] = useMemo(() => {
  15. return references?.knowledge?.map((reference: any) => {
  16. return {
  17. label: (
  18. <div style={{ maxWidth: '120px' }}>
  19. <Typography.Text
  20. ellipsis={{
  21. tooltip: reference.name,
  22. }}
  23. >
  24. {decodeURIComponent(reference.name).split('_')[0]}
  25. </Typography.Text>
  26. </div>
  27. ),
  28. key: reference.name,
  29. children: (
  30. <div className='h-full overflow-y-auto'>
  31. {reference?.chunks?.map((chunk: any) => <MarkDownContext key={chunk.id}>{chunk.content}</MarkDownContext>)}
  32. </div>
  33. ),
  34. };
  35. });
  36. }, [references]);
  37. return (
  38. <div>
  39. <Divider className='mb-1 mt-0' dashed />
  40. <div className='flex text-sm gap-2 text-blue-400' onClick={() => setOpen(true)}>
  41. <LinkOutlined />
  42. <span className='text-sm'>查看回复引用</span>
  43. </div>
  44. <Drawer
  45. open={open}
  46. title='回复引用'
  47. placement={isMobile ? 'bottom' : 'right'}
  48. onClose={() => setOpen(false)}
  49. destroyOnClose={true}
  50. className='p-0'
  51. {...(!isMobile && { width: '30%' })}
  52. >
  53. <Tabs items={items} size='small' />
  54. </Drawer>
  55. </div>
  56. );
  57. };
  58. const ReferencesContent: React.FC<{ references: any }> = ({ references }) => {
  59. try {
  60. const data = JSON.parse(references);
  61. return <ReferencesContentView references={data} />;
  62. } catch {
  63. return null;
  64. }
  65. };
  66. export default ReferencesContent;