2025-11-27 02:56:24 +08:00
|
|
|
import { useEffect } from 'react'
|
2025-11-21 04:32:08 +08:00
|
|
|
import { BrowserRouter, Routes, Route } from 'react-router-dom'
|
|
|
|
|
import { ConfigProvider } from 'antd'
|
|
|
|
|
import zhCN from 'antd/locale/zh_CN'
|
|
|
|
|
import Layout from './components/Layout'
|
|
|
|
|
import AccountList from './pages/AccountList'
|
|
|
|
|
import AccountImport from './pages/AccountImport'
|
|
|
|
|
import AccountDetail from './pages/AccountDetail'
|
2025-11-26 22:26:50 +08:00
|
|
|
import AccountEdit from './pages/AccountEdit'
|
2025-11-21 04:32:08 +08:00
|
|
|
import LeaderList from './pages/LeaderList'
|
|
|
|
|
import LeaderAdd from './pages/LeaderAdd'
|
|
|
|
|
import ConfigPage from './pages/ConfigPage'
|
2025-11-27 01:13:52 +08:00
|
|
|
import PositionList from './pages/PositionList'
|
2025-11-21 04:32:08 +08:00
|
|
|
import Statistics from './pages/Statistics'
|
2025-11-27 02:56:24 +08:00
|
|
|
import { wsManager } from './services/websocket'
|
2025-11-21 04:32:08 +08:00
|
|
|
|
|
|
|
|
function App() {
|
2025-11-27 02:56:24 +08:00
|
|
|
// 应用启动时立即建立全局 WebSocket 连接
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
// 立即建立连接(如果还未连接)
|
|
|
|
|
if (!wsManager.isConnected()) {
|
|
|
|
|
wsManager.connect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 注意:应用不会卸载,所以不需要在 cleanup 中断开连接
|
|
|
|
|
// WebSocket 连接会在整个应用生命周期中保持,并自动重连
|
|
|
|
|
}, [])
|
|
|
|
|
|
2025-11-21 04:32:08 +08:00
|
|
|
return (
|
|
|
|
|
<ConfigProvider locale={zhCN}>
|
|
|
|
|
<BrowserRouter>
|
|
|
|
|
<Layout>
|
|
|
|
|
<Routes>
|
|
|
|
|
<Route path="/" element={<AccountList />} />
|
|
|
|
|
<Route path="/accounts" element={<AccountList />} />
|
|
|
|
|
<Route path="/accounts/import" element={<AccountImport />} />
|
|
|
|
|
<Route path="/accounts/detail" element={<AccountDetail />} />
|
2025-11-26 22:26:50 +08:00
|
|
|
<Route path="/accounts/edit" element={<AccountEdit />} />
|
2025-11-21 04:32:08 +08:00
|
|
|
<Route path="/leaders" element={<LeaderList />} />
|
|
|
|
|
<Route path="/leaders/add" element={<LeaderAdd />} />
|
|
|
|
|
<Route path="/config" element={<ConfigPage />} />
|
2025-11-27 01:13:52 +08:00
|
|
|
<Route path="/positions" element={<PositionList />} />
|
2025-11-21 04:32:08 +08:00
|
|
|
<Route path="/statistics" element={<Statistics />} />
|
|
|
|
|
</Routes>
|
|
|
|
|
</Layout>
|
|
|
|
|
</BrowserRouter>
|
|
|
|
|
</ConfigProvider>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default App
|
|
|
|
|
|