74 lines
1.9 KiB
JavaScript
Raw Normal View History

import React, { useEffect, useState } from 'react';
import { Layout, TabPane, Tabs } from '@douyinfe/semi-ui';
import { useNavigate, useLocation } from 'react-router-dom';
2023-04-22 20:39:27 +08:00
import SystemSetting from '../../components/SystemSetting';
2024-03-23 21:24:39 +08:00
import { isRoot } from '../../helpers';
2023-04-22 20:39:27 +08:00
import OtherSetting from '../../components/OtherSetting';
import PersonalSetting from '../../components/PersonalSetting';
import OperationSetting from '../../components/OperationSetting';
2023-04-22 20:39:27 +08:00
const Setting = () => {
const navigate = useNavigate();
const location = useLocation();
const [tabActiveKey, setTabActiveKey] = useState('1');
2024-03-23 21:24:39 +08:00
let panes = [
{
tab: '个人设置',
content: <PersonalSetting />,
itemKey: 'personal',
2024-03-23 21:24:39 +08:00
},
];
2023-04-22 20:39:27 +08:00
2024-03-23 21:24:39 +08:00
if (isRoot()) {
panes.push({
tab: '运营设置',
content: <OperationSetting />,
itemKey: 'operation',
2024-03-23 21:24:39 +08:00
});
panes.push({
tab: '系统设置',
content: <SystemSetting />,
itemKey: 'system',
2024-03-23 21:24:39 +08:00
});
panes.push({
tab: '其他设置',
content: <OtherSetting />,
itemKey: 'other',
2024-03-23 21:24:39 +08:00
});
}
const onChangeTab = (key) => {
setTabActiveKey(key);
navigate(`?tab=${key}`);
};
useEffect(() => {
const searchParams = new URLSearchParams(window.location.search);
const tab = searchParams.get('tab');
if (tab) {
setTabActiveKey(tab);
} else {
onChangeTab('personal');
}
}, [location.search]);
2024-03-23 21:24:39 +08:00
return (
<div>
<Layout>
<Layout.Content>
<Tabs
type='line'
activeKey={tabActiveKey}
onChange={(key) => onChangeTab(key)}
>
2024-03-23 21:24:39 +08:00
{panes.map((pane) => (
<TabPane itemKey={pane.itemKey} tab={pane.tab} key={pane.itemKey}>
{tabActiveKey === pane.itemKey && pane.content}
2024-03-23 21:24:39 +08:00
</TabPane>
))}
</Tabs>
</Layout.Content>
</Layout>
</div>
);
2023-04-22 20:39:27 +08:00
};
export default Setting;