index.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. const Setting = () => {
  11. const { t } = useTranslation();
  12. const navigate = useNavigate();
  13. const location = useLocation();
  14. const [tabActiveKey, setTabActiveKey] = useState('1');
  15. let panes = [
  16. {
  17. tab: t('个人设置'),
  18. content: <PersonalSetting />,
  19. itemKey: 'personal',
  20. },
  21. ];
  22. if (isRoot()) {
  23. panes.push({
  24. tab: t('运营设置'),
  25. content: <OperationSetting />,
  26. itemKey: 'operation',
  27. });
  28. panes.push({
  29. tab: t('系统设置'),
  30. content: <SystemSetting />,
  31. itemKey: 'system',
  32. });
  33. panes.push({
  34. tab: t('其他设置'),
  35. content: <OtherSetting />,
  36. itemKey: 'other',
  37. });
  38. }
  39. const onChangeTab = (key) => {
  40. setTabActiveKey(key);
  41. navigate(`?tab=${key}`);
  42. };
  43. useEffect(() => {
  44. const searchParams = new URLSearchParams(window.location.search);
  45. const tab = searchParams.get('tab');
  46. if (tab) {
  47. setTabActiveKey(tab);
  48. } else {
  49. onChangeTab('personal');
  50. }
  51. }, [location.search]);
  52. return (
  53. <div>
  54. <Layout>
  55. <Layout.Content>
  56. <Tabs
  57. type='line'
  58. activeKey={tabActiveKey}
  59. onChange={(key) => onChangeTab(key)}
  60. >
  61. {panes.map((pane) => (
  62. <TabPane itemKey={pane.itemKey} tab={pane.tab} key={pane.itemKey}>
  63. {tabActiveKey === pane.itemKey && pane.content}
  64. </TabPane>
  65. ))}
  66. </Tabs>
  67. </Layout.Content>
  68. </Layout>
  69. </div>
  70. );
  71. };
  72. export default Setting;