Complete Phase 2 identity & authentication module: - Organization CRUD with tree structure (parent_id + materialized path) - Department CRUD nested under organizations with tree support - Position CRUD nested under departments - User management page with table, create/edit modal, role assignment - Organization architecture page with 3-panel tree layout - Frontend API layer for orgs/depts/positions - Sidebar navigation updated with organization menu item - Fix parse_ttl edge case for strings ending in 'd' (e.g. "invalid")
59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
import { useEffect } from 'react';
|
||
import { HashRouter, Routes, Route, Navigate } from 'react-router-dom';
|
||
import { ConfigProvider, theme as antdTheme } from 'antd';
|
||
import zhCN from 'antd/locale/zh_CN';
|
||
import MainLayout from './layouts/MainLayout';
|
||
import Login from './pages/Login';
|
||
import Home from './pages/Home';
|
||
import Roles from './pages/Roles';
|
||
import Users from './pages/Users';
|
||
import Organizations from './pages/Organizations';
|
||
import { useAuthStore } from './stores/auth';
|
||
import { useAppStore } from './stores/app';
|
||
|
||
function PrivateRoute({ children }: { children: React.ReactNode }) {
|
||
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
||
return isAuthenticated ? <>{children}</> : <Navigate to="/login" replace />;
|
||
}
|
||
|
||
export default function App() {
|
||
const loadFromStorage = useAuthStore((s) => s.loadFromStorage);
|
||
const theme = useAppStore((s) => s.theme);
|
||
|
||
// Restore auth state from localStorage on app load
|
||
useEffect(() => {
|
||
loadFromStorage();
|
||
}, [loadFromStorage]);
|
||
|
||
return (
|
||
<ConfigProvider
|
||
locale={zhCN}
|
||
theme={{
|
||
algorithm: theme === 'dark' ? antdTheme.darkAlgorithm : antdTheme.defaultAlgorithm,
|
||
}}
|
||
>
|
||
<HashRouter>
|
||
<Routes>
|
||
<Route path="/login" element={<Login />} />
|
||
<Route
|
||
path="/"
|
||
element={
|
||
<PrivateRoute>
|
||
<MainLayout>
|
||
<Routes>
|
||
<Route path="/" element={<Home />} />
|
||
<Route path="/users" element={<Users />} />
|
||
<Route path="/roles" element={<Roles />} />
|
||
<Route path="/organizations" element={<Organizations />} />
|
||
<Route path="/settings" element={<div>系统设置(开发中)</div>} />
|
||
</Routes>
|
||
</MainLayout>
|
||
</PrivateRoute>
|
||
}
|
||
/>
|
||
</Routes>
|
||
</HashRouter>
|
||
</ConfigProvider>
|
||
);
|
||
}
|