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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { ReactComponent as FileIcon } from '@/assets/svg/file-management.svg';
  2. import { ReactComponent as GraphIcon } from '@/assets/svg/graph.svg';
  3. import { ReactComponent as KnowledgeBaseIcon } from '@/assets/svg/knowledge-base.svg';
  4. import { useTranslate } from '@/hooks/common-hooks';
  5. import { useFetchAppConf } from '@/hooks/logic-hooks';
  6. import { useNavigateWithFromState } from '@/hooks/route-hook';
  7. import { MessageOutlined, SearchOutlined } from '@ant-design/icons';
  8. import { Flex, Layout, Radio, Space, theme } from 'antd';
  9. import { MouseEventHandler, useCallback, useMemo } from 'react';
  10. import { useLocation } from 'umi';
  11. import Toolbar from '../right-toolbar';
  12. import { useTheme } from '@/components/theme-provider';
  13. import styles from './index.less';
  14. const { Header } = Layout;
  15. const RagHeader = () => {
  16. const {
  17. token: { colorBgContainer },
  18. } = theme.useToken();
  19. const navigate = useNavigateWithFromState();
  20. const { pathname } = useLocation();
  21. const { t } = useTranslate('header');
  22. const appConf = useFetchAppConf();
  23. const { theme: themeRag } = useTheme();
  24. const tagsData = useMemo(
  25. () => [
  26. { path: '/knowledge', name: t('knowledgeBase'), icon: KnowledgeBaseIcon },
  27. { path: '/chat', name: t('chat'), icon: MessageOutlined },
  28. { path: '/search', name: t('search'), icon: SearchOutlined },
  29. { path: '/agent-list', name: t('flow'), icon: GraphIcon },
  30. { path: '/file', name: t('fileManager'), icon: FileIcon },
  31. ],
  32. [t],
  33. );
  34. const currentPath = useMemo(() => {
  35. return (
  36. tagsData.find((x) => pathname.startsWith(x.path))?.name || 'knowledge'
  37. );
  38. }, [pathname, tagsData]);
  39. const handleChange = useCallback(
  40. (path: string): MouseEventHandler =>
  41. (e) => {
  42. e.preventDefault();
  43. navigate(path);
  44. },
  45. [navigate],
  46. );
  47. const handleLogoClick = useCallback(() => {
  48. navigate('/');
  49. }, [navigate]);
  50. return (
  51. <Header
  52. style={{
  53. padding: '0 16px',
  54. background: colorBgContainer,
  55. display: 'flex',
  56. justifyContent: 'space-between',
  57. alignItems: 'center',
  58. height: '72px',
  59. }}
  60. >
  61. <a href={window.location.origin}>
  62. <Space
  63. size={12}
  64. onClick={handleLogoClick}
  65. className={styles.logoWrapper}
  66. >
  67. <img src="/logo.svg" alt="" className={styles.appIcon} />
  68. <span className={styles.appName}>{appConf.appName}</span>
  69. </Space>
  70. </a>
  71. <Space size={[0, 8]} wrap>
  72. <Radio.Group
  73. defaultValue="a"
  74. buttonStyle="solid"
  75. className={
  76. themeRag === 'dark' ? styles.radioGroupDark : styles.radioGroup
  77. }
  78. value={currentPath}
  79. >
  80. {tagsData.map((item, index) => (
  81. <Radio.Button
  82. className={`${themeRag === 'dark' ? 'dark' : 'light'} ${index === 0 ? 'first' : ''} ${index === tagsData.length - 1 ? 'last' : ''}`}
  83. value={item.name}
  84. key={item.name}
  85. >
  86. <a href={item.path}>
  87. <Flex
  88. align="center"
  89. gap={8}
  90. onClick={handleChange(item.path)}
  91. className="cursor-pointer"
  92. >
  93. <item.icon
  94. className={styles.radioButtonIcon}
  95. stroke={item.name === currentPath ? 'black' : 'white'}
  96. ></item.icon>
  97. {item.name}
  98. </Flex>
  99. </a>
  100. </Radio.Button>
  101. ))}
  102. </Radio.Group>
  103. </Space>
  104. <Toolbar></Toolbar>
  105. </Header>
  106. );
  107. };
  108. export default RagHeader;