初步增加 web 界面
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
|
||||
import { ConfigProvider } from 'antd';
|
||||
import zhCN from 'antd/locale/zh_CN';
|
||||
import LoginPage from './pages/LoginPage';
|
||||
import MainLayout from './layouts/MainLayout';
|
||||
import DashboardPage from './pages/DashboardPage';
|
||||
import AccountsPage from './pages/AccountsPage';
|
||||
import LoginTasksPage from './pages/LoginTasksPage';
|
||||
import ProxyPage from './pages/ProxyPage';
|
||||
import UsersPage from './pages/UsersPage';
|
||||
import { getToken } from './store/auth';
|
||||
|
||||
function App() {
|
||||
// 用 state 驱动重渲染,登录/登出时调 refreshAuth()
|
||||
const [authVersion, setAuthVersion] = useState(0);
|
||||
const refreshAuth = useCallback(() => setAuthVersion((v) => v + 1), []);
|
||||
const isLoggedIn = !!getToken();
|
||||
|
||||
return (
|
||||
<ConfigProvider locale={zhCN}>
|
||||
<BrowserRouter>
|
||||
<Routes>
|
||||
<Route path="/login" element={<LoginPage onLogin={refreshAuth} />} />
|
||||
<Route
|
||||
path="/"
|
||||
element={isLoggedIn ? <MainLayout key={authVersion} onLogout={refreshAuth} /> : <Navigate to="/login" replace />}
|
||||
>
|
||||
<Route index element={<DashboardPage />} />
|
||||
<Route path="accounts" element={<AccountsPage />} />
|
||||
<Route path="login-tasks" element={<LoginTasksPage />} />
|
||||
<Route path="proxy" element={<ProxyPage />} />
|
||||
<Route path="users" element={<UsersPage />} />
|
||||
</Route>
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
</ConfigProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
Reference in New Issue
Block a user