| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- /*
- Copyright (C) 2025 QuantumNous
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
- For commercial licensing, please contact support@quantumnous.com
- */
- import React, { useEffect, useState } from 'react';
- import { Layout, TabPane, Tabs } from '@douyinfe/semi-ui';
- import { useNavigate, useLocation } from 'react-router-dom';
- import { useTranslation } from 'react-i18next';
- import {
- Settings,
- Calculator,
- Gauge,
- Shapes,
- Cog,
- MoreHorizontal,
- LayoutDashboard,
- MessageSquare,
- Palette,
- CreditCard
- } from 'lucide-react';
- import SystemSetting from '../../components/settings/SystemSetting.js';
- import { isRoot } from '../../helpers';
- import OtherSetting from '../../components/settings/OtherSetting';
- import OperationSetting from '../../components/settings/OperationSetting.js';
- import RateLimitSetting from '../../components/settings/RateLimitSetting.js';
- import ModelSetting from '../../components/settings/ModelSetting.js';
- import DashboardSetting from '../../components/settings/DashboardSetting.js';
- import RatioSetting from '../../components/settings/RatioSetting.js';
- import ChatsSetting from '../../components/settings/ChatsSetting.js';
- import DrawingSetting from '../../components/settings/DrawingSetting.js';
- import PaymentSetting from '../../components/settings/PaymentSetting.js';
- const Setting = () => {
- const { t } = useTranslation();
- const navigate = useNavigate();
- const location = useLocation();
- const [tabActiveKey, setTabActiveKey] = useState('1');
- let panes = [];
- if (isRoot()) {
- panes.push({
- tab: (
- <span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
- <Settings size={18} />
- {t('运营设置')}
- </span>
- ),
- content: <OperationSetting />,
- itemKey: 'operation',
- });
- panes.push({
- tab: (
- <span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
- <LayoutDashboard size={18} />
- {t('仪表盘设置')}
- </span>
- ),
- content: <DashboardSetting />,
- itemKey: 'dashboard',
- });
- panes.push({
- tab: (
- <span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
- <MessageSquare size={18} />
- {t('聊天设置')}
- </span>
- ),
- content: <ChatsSetting />,
- itemKey: 'chats',
- });
- panes.push({
- tab: (
- <span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
- <Palette size={18} />
- {t('绘图设置')}
- </span>
- ),
- content: <DrawingSetting />,
- itemKey: 'drawing',
- });
- panes.push({
- tab: (
- <span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
- <CreditCard size={18} />
- {t('支付设置')}
- </span>
- ),
- content: <PaymentSetting />,
- itemKey: 'payment',
- });
- panes.push({
- tab: (
- <span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
- <Calculator size={18} />
- {t('倍率设置')}
- </span>
- ),
- content: <RatioSetting />,
- itemKey: 'ratio',
- });
- panes.push({
- tab: (
- <span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
- <Gauge size={18} />
- {t('速率限制设置')}
- </span>
- ),
- content: <RateLimitSetting />,
- itemKey: 'ratelimit',
- });
- panes.push({
- tab: (
- <span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
- <Shapes size={18} />
- {t('模型相关设置')}
- </span>
- ),
- content: <ModelSetting />,
- itemKey: 'models',
- });
- panes.push({
- tab: (
- <span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
- <Cog size={18} />
- {t('系统设置')}
- </span>
- ),
- content: <SystemSetting />,
- itemKey: 'system',
- });
- panes.push({
- tab: (
- <span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
- <MoreHorizontal size={18} />
- {t('其他设置')}
- </span>
- ),
- content: <OtherSetting />,
- itemKey: 'other',
- });
- }
- 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('operation');
- }
- }, [location.search]);
- return (
- <div className="mt-[60px] px-2">
- <Layout>
- <Layout.Content>
- <Tabs
- type='card'
- collapsible
- activeKey={tabActiveKey}
- onChange={(key) => onChangeTab(key)}
- >
- {panes.map((pane) => (
- <TabPane itemKey={pane.itemKey} tab={pane.tab} key={pane.itemKey}>
- {tabActiveKey === pane.itemKey && pane.content}
- </TabPane>
- ))}
- </Tabs>
- </Layout.Content>
- </Layout>
- </div>
- );
- };
- export default Setting;
|