App.tsx
5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { useEffect } from 'react';
import { BrowserRouter, Routes, Route, Navigate, useNavigate, useLocation } from 'react-router-dom';
import { ConfigProvider, Layout, Menu, Dropdown, Space, Spin } from 'antd';
import zhCN from 'antd/locale/zh_CN';
import { AppstoreOutlined, KeyOutlined, SettingOutlined, FileTextOutlined, ThunderboltOutlined, CompassOutlined, SafetyCertificateOutlined, BarChartOutlined, UserOutlined, LogoutOutlined } from '@ant-design/icons';
import type { MenuProps } from 'antd';
import ProviderList from './pages/Providers/ProviderList';
import AccountList from './pages/Accounts/AccountList';
import StrategyList from './pages/Strategies/StrategyList';
import PromptList from './pages/Prompts/PromptList';
import CallMonitor from './pages/Calls/CallMonitor';
import ModelPlaza from './pages/DebugConsole/ModelPlaza';
import WordBankList from './pages/WordBank/WordBankList';
import StatisticsDashboard from './pages/Statistics/StatisticsDashboard';
import LoginPage from './pages/Login/LoginPage';
import { useAuthStore } from './stores/authStore';
import './design-tokens.css';
const { Sider, Content } = Layout;
const menuItems = [
{ key: '/debug', icon: <CompassOutlined />, label: '模型广场' },
{ key: '/providers', icon: <AppstoreOutlined />, label: '供应商管理' },
{ key: '/accounts', icon: <KeyOutlined />, label: '账号配置' },
{ key: '/strategies', icon: <SettingOutlined />, label: '调用策略' },
{ key: '/prompts', icon: <FileTextOutlined />, label: '提示词模板' },
{ key: '/calls', icon: <ThunderboltOutlined />, label: '模型调用' },
{ key: '/word-bank', icon: <SafetyCertificateOutlined />, label: '敏感词库' },
{ key: '/statistics', icon: <BarChartOutlined />, label: '调用统计' },
];
function AppLayout() {
const navigate = useNavigate();
const location = useLocation();
const user = useAuthStore((s) => s.user);
const logout = useAuthStore((s) => s.logout);
const handleLogout = () => {
logout();
navigate('/login', { replace: true });
};
const userMenuItems: MenuProps['items'] = [
{
key: 'logout',
icon: <LogoutOutlined />,
label: '退出登录',
onClick: handleLogout,
},
];
return (
<Layout className="app-layout">
<Sider width={220} className="app-sider">
<div className="sider-header">
<div className="sider-logo">L</div>
<span className="sider-title">LLM 调度平台</span>
</div>
<Menu
mode="inline"
selectedKeys={[location.pathname]}
items={menuItems}
onClick={({ key }) => navigate(key)}
className="sider-menu"
/>
<div className="sider-footer">
<Dropdown menu={{ items: userMenuItems }} placement="topRight" trigger={['click']}>
<Space className="sider-user" style={{ cursor: 'pointer' }}>
<div className="sider-avatar">
{user?.display_name?.[0] || user?.username?.[0] || 'U'}
</div>
<span className="sider-username">
{user?.display_name || user?.username || '用户'}
</span>
</Space>
</Dropdown>
</div>
</Sider>
<Content className="app-content">
<div className="app-content-wrap">
<Routes>
<Route path="/providers" element={<ProviderList />} />
<Route path="/accounts" element={<AccountList />} />
<Route path="/strategies" element={<StrategyList />} />
<Route path="/prompts" element={<PromptList />} />
<Route path="/calls" element={<CallMonitor />} />
<Route path="/debug" element={<ModelPlaza />} />
<Route path="/word-bank" element={<WordBankList />} />
<Route path="/statistics" element={<StatisticsDashboard />} />
<Route path="*" element={<Navigate to="/providers" replace />} />
</Routes>
</div>
</Content>
</Layout>
);
}
function AuthGuard({ children }: { children: React.ReactNode }) {
const token = useAuthStore((s) => s.token);
const initialized = useAuthStore((s) => s.initialized);
const location = useLocation();
if (!initialized) {
return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}>
<Spin size="large" />
</div>
);
}
if (!token) {
return <Navigate to="/login" state={{ from: location }} replace />;
}
return <>{children}</>;
}
export default function App() {
const checkAuth = useAuthStore((s) => s.checkAuth);
useEffect(() => {
checkAuth();
}, [checkAuth]);
return (
<ConfigProvider
locale={zhCN}
theme={{
token: {
colorPrimary: '#6366f1',
borderRadius: 6,
fontFamily: "'Inter', -apple-system, BlinkMacSystemFont, sans-serif",
},
}}
>
<BrowserRouter>
<Routes>
<Route path="/login" element={<LoginPage />} />
<Route
path="/*"
element={
<AuthGuard>
<AppLayout />
</AuthGuard>
}
/>
</Routes>
</BrowserRouter>
</ConfigProvider>
);
}