index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/SystemSetting';
  6. import { isRoot } from '../../helpers';
  7. import OtherSetting from '../../components/OtherSetting';
  8. import PersonalSetting from '../../components/PersonalSetting';
  9. import OperationSetting from '../../components/OperationSetting';
  10. import RateLimitSetting from '../../components/RateLimitSetting.js';
  11. import ModelSetting from '../../components/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. {
  19. tab: t('个人设置'),
  20. content: <PersonalSetting />,
  21. itemKey: 'personal',
  22. },
  23. ];
  24. if (isRoot()) {
  25. panes.push({
  26. tab: t('运营设置'),
  27. content: <OperationSetting />,
  28. itemKey: 'operation',
  29. });
  30. panes.push({
  31. tab: t('速率限制设置'),
  32. content: <RateLimitSetting />,
  33. itemKey: 'ratelimit',
  34. });
  35. panes.push({
  36. tab: t('模型相关设置'),
  37. content: <ModelSetting />,
  38. itemKey: 'models',
  39. });
  40. panes.push({
  41. tab: t('系统设置'),
  42. content: <SystemSetting />,
  43. itemKey: 'system',
  44. });
  45. panes.push({
  46. tab: t('其他设置'),
  47. content: <OtherSetting />,
  48. itemKey: 'other',
  49. });
  50. }
  51. const onChangeTab = (key) => {
  52. setTabActiveKey(key);
  53. navigate(`?tab=${key}`);
  54. };
  55. useEffect(() => {
  56. const searchParams = new URLSearchParams(window.location.search);
  57. const tab = searchParams.get('tab');
  58. if (tab) {
  59. setTabActiveKey(tab);
  60. } else {
  61. onChangeTab('personal');
  62. }
  63. }, [location.search]);
  64. return (
  65. <div>
  66. <Layout>
  67. <Layout.Content>
  68. <Tabs
  69. type='line'
  70. activeKey={tabActiveKey}
  71. onChange={(key) => onChangeTab(key)}
  72. >
  73. {panes.map((pane) => (
  74. <TabPane itemKey={pane.itemKey} tab={pane.tab} key={pane.itemKey}>
  75. {tabActiveKey === pane.itemKey && pane.content}
  76. </TabPane>
  77. ))}
  78. </Tabs>
  79. </Layout.Content>
  80. </Layout>
  81. </div>
  82. );
  83. };
  84. export default Setting;