| import React from 'react'; |
| import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'; |
| import { Provider } from 'react-redux'; |
| import { ConfigProvider, message } from 'antd'; |
| import zhCN from 'antd/locale/zh_CN'; |
| import store from './store/store'; |
| import LoginPage from './pages/LoginPage'; |
| import RegisterPage from './pages/RegisterPage'; |
| import TeacherDashboard from './pages/teacher/TeacherDashboard'; |
| import StudentDashboard from './pages/student/StudentDashboard'; |
| import AgentChat from './pages/student/AgentChat'; |
| import ProtectedRoute from './components/common/ProtectedRoute'; |
| import './index.css'; |
|
|
| |
| const theme = { |
| token: { |
| colorPrimary: '#10b981', |
| colorSuccess: '#10b981', |
| colorWarning: '#f97316', |
| colorError: '#f43f5e', |
| colorInfo: '#8b5cf6', |
| borderRadius: 8, |
| fontSize: 14, |
| fontFamily: "'Inter', 'PingFang SC', 'Microsoft YaHei', sans-serif", |
| }, |
| components: { |
| Button: { |
| controlHeight: 40, |
| fontWeight: 500, |
| }, |
| Input: { |
| controlHeight: 40, |
| }, |
| Select: { |
| controlHeight: 40, |
| }, |
| Menu: { |
| itemBorderRadius: 8, |
| subMenuItemBorderRadius: 8, |
| }, |
| Card: { |
| borderRadiusLG: 12, |
| boxShadow: '0 2px 8px rgba(0, 0, 0, 0.04)', |
| }, |
| }, |
| }; |
|
|
| |
| message.config({ |
| top: 80, |
| duration: 3, |
| maxCount: 3, |
| }); |
|
|
| function App() { |
| return ( |
| <Provider store={store}> |
| <ConfigProvider theme={theme} locale={zhCN}> |
| <BrowserRouter> |
| <Routes> |
| <Route path="/login" element={<LoginPage />} /> |
| <Route path="/register" element={<RegisterPage />} /> |
| |
| {/* Agent对话页面 - 不需要登录保护,通过token访问 */} |
| {/* 注意:这个路由必须在 /student/* 之前,否则会被捕获并要求登录 */} |
| <Route path="/student/chat/:agentId" element={<AgentChat />} /> |
| |
| {/* 教师端路由 */} |
| <Route |
| path="/teacher/*" |
| element={ |
| <ProtectedRoute requiredRole="teacher"> |
| <TeacherDashboard /> |
| </ProtectedRoute> |
| } |
| /> |
| |
| {/* 学生端路由 - 排除chat路径 */} |
| <Route |
| path="/student/*" |
| element={ |
| <ProtectedRoute requiredRole="student"> |
| <StudentDashboard /> |
| </ProtectedRoute> |
| } |
| /> |
| |
| {/* 默认重定向到登录 */} |
| <Route path="/" element={<Navigate to="/login" replace />} /> |
| <Route path="*" element={<Navigate to="/login" replace />} /> |
| </Routes> |
| </BrowserRouter> |
| </ConfigProvider> |
| </Provider> |
| ); |
| } |
|
|
| export default App; |