2024-04-01 13:51:07 +08:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
|
import { Layout, TabPane, Tabs } from '@douyinfe/semi-ui';
|
|
|
|
|
import { useNavigate, useLocation } from 'react-router-dom';
|
2024-12-13 19:03:14 +08:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2025-06-21 02:21:27 +08:00
|
|
|
import {
|
|
|
|
|
Settings,
|
|
|
|
|
Calculator,
|
|
|
|
|
Gauge,
|
|
|
|
|
Shapes,
|
|
|
|
|
Cog,
|
|
|
|
|
MoreHorizontal,
|
2025-06-21 02:36:09 +08:00
|
|
|
LayoutDashboard,
|
2025-06-21 02:50:09 +08:00
|
|
|
MessageSquare,
|
2025-06-21 04:16:01 +08:00
|
|
|
Palette,
|
|
|
|
|
CreditCard
|
2025-06-21 02:21:27 +08:00
|
|
|
} from 'lucide-react';
|
2024-04-01 13:51:07 +08:00
|
|
|
|
2025-06-04 00:42:06 +08:00
|
|
|
import SystemSetting from '../../components/settings/SystemSetting.js';
|
2024-03-23 21:24:39 +08:00
|
|
|
import { isRoot } from '../../helpers';
|
2025-06-04 00:42:06 +08:00
|
|
|
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';
|
✨ feat: major refactor and enhancement of Detail dashboard component & add api url display
- **Code Organization & Architecture:**
- Restructured component with clear sections (Hooks, Constants, Helper Functions, etc.)
- Added comprehensive code organization comments for better maintainability
- Extracted reusable helper functions and constants for better separation of concerns
- **Performance Optimizations:**
- Implemented extensive use of useCallback and useMemo hooks for expensive operations
- Optimized data processing pipeline with dedicated processing functions
- Memoized chart configurations, performance metrics, and grouped stats data
- Cached helper functions like getTrendSpec, handleCopyUrl, and modal handlers
- **UI/UX Enhancements:**
- Added Empty state component with construction illustrations for better UX
- Implemented responsive grid layout with conditional API info section visibility
- Enhanced button styling with consistent rounded design and hover effects
- Added mini trend charts to statistics cards for visual data representation
- Improved form field consistency with reusable createFormField helper
- **Feature Improvements:**
- Added self-use mode detection to conditionally hide/show API information section
- Enhanced chart configurations with centralized CHART_CONFIG constant
- Improved time handling with dedicated helper functions (getTimeInterval, getInitialTimestamp)
- Added comprehensive performance metrics calculation (RPM/TPM trends)
- Implemented advanced data aggregation and processing workflows
- **Code Quality & Maintainability:**
- Extracted complex data processing logic into dedicated functions
- Added proper prop destructuring and state organization
- Implemented consistent naming conventions and helper utilities
- Enhanced error handling and loading states management
- Added comprehensive JSDoc-style comments for better code documentation
- **Technical Debt Reduction:**
- Replaced repetitive form field definitions with reusable components
- Consolidated chart update logic into centralized updateChartSpec function
- Improved data flow with better state management patterns
- Reduced code duplication through strategic use of helper functions
This refactor significantly improves component performance, maintainability, and user experience while maintaining backward compatibility and existing functionality.
2025-06-09 17:44:23 +08:00
|
|
|
import DashboardSetting from '../../components/settings/DashboardSetting.js';
|
2025-06-18 01:29:35 +08:00
|
|
|
import RatioSetting from '../../components/settings/RatioSetting.js';
|
2025-06-21 02:36:09 +08:00
|
|
|
import ChatsSetting from '../../components/settings/ChatsSetting.js';
|
2025-06-21 02:50:09 +08:00
|
|
|
import DrawingSetting from '../../components/settings/DrawingSetting.js';
|
2025-06-21 04:16:01 +08:00
|
|
|
import PaymentSetting from '../../components/settings/PaymentSetting.js';
|
2024-12-13 19:03:14 +08:00
|
|
|
|
2023-04-22 20:39:27 +08:00
|
|
|
const Setting = () => {
|
2024-12-13 19:03:14 +08:00
|
|
|
const { t } = useTranslation();
|
2024-04-01 13:51:07 +08:00
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const location = useLocation();
|
2024-04-01 13:33:57 +08:00
|
|
|
const [tabActiveKey, setTabActiveKey] = useState('1');
|
2025-03-09 18:31:16 +08:00
|
|
|
let panes = [];
|
2023-04-22 20:39:27 +08:00
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
if (isRoot()) {
|
|
|
|
|
panes.push({
|
2025-06-21 02:21:27 +08:00
|
|
|
tab: (
|
|
|
|
|
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
|
|
|
|
<Settings size={18} />
|
|
|
|
|
{t('运营设置')}
|
|
|
|
|
</span>
|
|
|
|
|
),
|
2024-03-23 21:24:39 +08:00
|
|
|
content: <OperationSetting />,
|
2024-04-01 13:51:07 +08:00
|
|
|
itemKey: 'operation',
|
2024-03-23 21:24:39 +08:00
|
|
|
});
|
2025-06-21 21:59:38 +08:00
|
|
|
panes.push({
|
|
|
|
|
tab: (
|
|
|
|
|
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
|
|
|
|
<LayoutDashboard size={18} />
|
|
|
|
|
{t('仪表盘设置')}
|
|
|
|
|
</span>
|
|
|
|
|
),
|
|
|
|
|
content: <DashboardSetting />,
|
|
|
|
|
itemKey: 'dashboard',
|
|
|
|
|
});
|
2025-06-21 02:36:09 +08:00
|
|
|
panes.push({
|
|
|
|
|
tab: (
|
|
|
|
|
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
|
|
|
|
<MessageSquare size={18} />
|
|
|
|
|
{t('聊天设置')}
|
|
|
|
|
</span>
|
|
|
|
|
),
|
|
|
|
|
content: <ChatsSetting />,
|
|
|
|
|
itemKey: 'chats',
|
|
|
|
|
});
|
2025-06-21 02:50:09 +08:00
|
|
|
panes.push({
|
|
|
|
|
tab: (
|
|
|
|
|
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
|
|
|
|
<Palette size={18} />
|
|
|
|
|
{t('绘图设置')}
|
|
|
|
|
</span>
|
|
|
|
|
),
|
|
|
|
|
content: <DrawingSetting />,
|
|
|
|
|
itemKey: 'drawing',
|
|
|
|
|
});
|
2025-06-21 04:16:01 +08:00
|
|
|
panes.push({
|
|
|
|
|
tab: (
|
|
|
|
|
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
|
|
|
|
<CreditCard size={18} />
|
|
|
|
|
{t('支付设置')}
|
|
|
|
|
</span>
|
|
|
|
|
),
|
|
|
|
|
content: <PaymentSetting />,
|
|
|
|
|
itemKey: 'payment',
|
|
|
|
|
});
|
2025-06-18 01:29:35 +08:00
|
|
|
panes.push({
|
2025-06-21 02:21:27 +08:00
|
|
|
tab: (
|
|
|
|
|
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
|
|
|
|
<Calculator size={18} />
|
|
|
|
|
{t('倍率设置')}
|
|
|
|
|
</span>
|
|
|
|
|
),
|
2025-06-18 01:29:35 +08:00
|
|
|
content: <RatioSetting />,
|
|
|
|
|
itemKey: 'ratio',
|
|
|
|
|
});
|
2025-02-24 16:20:55 +08:00
|
|
|
panes.push({
|
2025-06-21 02:21:27 +08:00
|
|
|
tab: (
|
|
|
|
|
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
|
|
|
|
<Gauge size={18} />
|
|
|
|
|
{t('速率限制设置')}
|
|
|
|
|
</span>
|
|
|
|
|
),
|
2025-02-24 16:20:55 +08:00
|
|
|
content: <RateLimitSetting />,
|
|
|
|
|
itemKey: 'ratelimit',
|
|
|
|
|
});
|
2025-02-26 16:54:43 +08:00
|
|
|
panes.push({
|
2025-06-21 02:21:27 +08:00
|
|
|
tab: (
|
|
|
|
|
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
|
|
|
|
<Shapes size={18} />
|
|
|
|
|
{t('模型相关设置')}
|
|
|
|
|
</span>
|
|
|
|
|
),
|
2025-02-26 16:54:43 +08:00
|
|
|
content: <ModelSetting />,
|
|
|
|
|
itemKey: 'models',
|
|
|
|
|
});
|
2024-03-23 21:24:39 +08:00
|
|
|
panes.push({
|
2025-06-21 02:21:27 +08:00
|
|
|
tab: (
|
|
|
|
|
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
|
|
|
|
<Cog size={18} />
|
|
|
|
|
{t('系统设置')}
|
|
|
|
|
</span>
|
|
|
|
|
),
|
2024-03-23 21:24:39 +08:00
|
|
|
content: <SystemSetting />,
|
2024-04-01 13:51:07 +08:00
|
|
|
itemKey: 'system',
|
2024-03-23 21:24:39 +08:00
|
|
|
});
|
2025-06-21 02:21:27 +08:00
|
|
|
panes.push({
|
|
|
|
|
tab: (
|
|
|
|
|
<span style={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
|
|
|
|
|
<MoreHorizontal size={18} />
|
|
|
|
|
{t('其他设置')}
|
|
|
|
|
</span>
|
|
|
|
|
),
|
|
|
|
|
content: <OtherSetting />,
|
|
|
|
|
itemKey: 'other',
|
|
|
|
|
});
|
2024-03-23 21:24:39 +08:00
|
|
|
}
|
2024-04-01 13:51:07 +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 {
|
2025-03-07 17:22:37 +08:00
|
|
|
onChangeTab('operation');
|
2024-04-01 13:51:07 +08:00
|
|
|
}
|
|
|
|
|
}, [location.search]);
|
2024-03-23 21:24:39 +08:00
|
|
|
return (
|
2025-06-25 15:26:51 +08:00
|
|
|
<div className="mt-[64px]">
|
2024-03-23 21:24:39 +08:00
|
|
|
<Layout>
|
|
|
|
|
<Layout.Content>
|
2024-04-01 13:33:57 +08:00
|
|
|
<Tabs
|
2025-06-21 02:21:27 +08:00
|
|
|
type='card'
|
2025-06-21 02:50:09 +08:00
|
|
|
collapsible
|
2024-04-01 13:51:07 +08:00
|
|
|
activeKey={tabActiveKey}
|
|
|
|
|
onChange={(key) => onChangeTab(key)}
|
2024-04-01 13:33:57 +08:00
|
|
|
>
|
2024-03-23 21:24:39 +08:00
|
|
|
{panes.map((pane) => (
|
2024-03-24 18:50:21 +08:00
|
|
|
<TabPane itemKey={pane.itemKey} tab={pane.tab} key={pane.itemKey}>
|
2024-04-01 13:33:57 +08:00
|
|
|
{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;
|