index.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React, { useEffect, useState } from 'react';
  2. import { Layout, TabPane, Tabs } from '@douyinfe/semi-ui';
  3. import { useNavigate, useLocation } from 'react-router-dom';
  4. import { useTranslation } from 'react-i18next';
  5. import SystemSetting from '../../components/settings/SystemSetting.js';
  6. import { isRoot } from '../../helpers';
  7. import OtherSetting from '../../components/settings/OtherSetting';
  8. import PersonalSetting from '../../components/settings/PersonalSetting.js';
  9. import OperationSetting from '../../components/settings/OperationSetting.js';
  10. import RateLimitSetting from '../../components/settings/RateLimitSetting.js';
  11. import ModelSetting from '../../components/settings/ModelSetting.js';
  12. const Setting = () => {
  13. const { t } = useTranslation();
  14. const navigate = useNavigate();
  15. const location = useLocation();
  16. const [tabActiveKey, setTabActiveKey] = useState('1');
  17. let panes = [];
  18. if (isRoot()) {
  19. panes.push({
  20. tab: t('运营设置'),
  21. content: <OperationSetting />,
  22. itemKey: 'operation',
  23. });
  24. panes.push({
  25. tab: t('速率限制设置'),
  26. content: <RateLimitSetting />,
  27. itemKey: 'ratelimit',
  28. });
  29. panes.push({
  30. tab: t('模型相关设置'),
  31. content: <ModelSetting />,
  32. itemKey: 'models',
  33. });
  34. panes.push({
  35. tab: t('系统设置'),
  36. content: <SystemSetting />,
  37. itemKey: 'system',
  38. });
  39. panes.push({
  40. tab: t('其他设置'),
  41. content: <OtherSetting />,
  42. itemKey: 'other',
  43. });
  44. }
  45. const onChangeTab = (key) => {
  46. setTabActiveKey(key);
  47. navigate(`?tab=${key}`);
  48. };
  49. useEffect(() => {
  50. const searchParams = new URLSearchParams(window.location.search);
  51. const tab = searchParams.get('tab');
  52. if (tab) {
  53. setTabActiveKey(tab);
  54. } else {
  55. onChangeTab('operation');
  56. }
  57. }, [location.search]);
  58. return (
  59. <div>
  60. <Layout>
  61. <Layout.Content>
  62. <Tabs
  63. type='line'
  64. activeKey={tabActiveKey}
  65. onChange={(key) => onChangeTab(key)}
  66. >
  67. {panes.map((pane) => (
  68. <TabPane itemKey={pane.itemKey} tab={pane.tab} key={pane.itemKey}>
  69. {tabActiveKey === pane.itemKey && pane.content}
  70. </TabPane>
  71. ))}
  72. </Tabs>
  73. </Layout.Content>
  74. </Layout>
  75. </div>
  76. );
  77. };
  78. export default Setting;