feat(settings): add settings pages and layout with routing
This commit is contained in:
16
src/App.tsx
16
src/App.tsx
@@ -8,6 +8,18 @@ import AuthGuard from './components/AuthGuard';
|
|||||||
|
|
||||||
import './locales';
|
import './locales';
|
||||||
import './utils/request'
|
import './utils/request'
|
||||||
|
import UserDataProvider from './components/Provider/UserDataProvider';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 授权应用,包含路由守卫和用户数据提供器
|
||||||
|
*/
|
||||||
|
function AuthorizationApp() {
|
||||||
|
return (
|
||||||
|
<AuthGuard>
|
||||||
|
<AppRoutes />
|
||||||
|
</AuthGuard>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 封装MaterialUIApp,将主题、基础样式和路由包裹起来
|
* 封装MaterialUIApp,将主题、基础样式和路由包裹起来
|
||||||
@@ -19,9 +31,7 @@ function MaterialUIApp() {
|
|||||||
<SnackbarProvider>
|
<SnackbarProvider>
|
||||||
<DialogProvider>
|
<DialogProvider>
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<AuthGuard>
|
<AuthorizationApp />
|
||||||
<AppRoutes />
|
|
||||||
</AuthGuard>
|
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
</DialogProvider>
|
</DialogProvider>
|
||||||
</SnackbarProvider>
|
</SnackbarProvider>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { useLocation, useNavigate } from 'react-router-dom';
|
import { useLocation, useNavigate } from 'react-router-dom';
|
||||||
import { CircularProgress, Box } from '@mui/material';
|
import { CircularProgress, Box } from '@mui/material';
|
||||||
|
import UserDataProvider from './Provider/UserDataProvider';
|
||||||
|
|
||||||
interface AuthGuardProps {
|
interface AuthGuardProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@@ -46,7 +47,11 @@ const AuthGuard: React.FC<AuthGuardProps> = ({ children }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 已认证,渲染子组件
|
// 已认证,渲染子组件
|
||||||
return <>{children}</>;
|
return (
|
||||||
|
<UserDataProvider>
|
||||||
|
{children}
|
||||||
|
</UserDataProvider>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AuthGuard;
|
export default AuthGuard;
|
||||||
@@ -16,11 +16,13 @@ import LogoutIcon from '@mui/icons-material/Logout';
|
|||||||
import PersonIcon from '@mui/icons-material/Person';
|
import PersonIcon from '@mui/icons-material/Person';
|
||||||
import LanguageSwitcher from '../LanguageSwitcher';
|
import LanguageSwitcher from '../LanguageSwitcher';
|
||||||
import { useAuth } from '@/hooks/login-hooks';
|
import { useAuth } from '@/hooks/login-hooks';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
const Header = () => {
|
const Header = () => {
|
||||||
const { userInfo, logout } = useAuth();
|
const { userInfo, logout } = useAuth();
|
||||||
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
||||||
const open = Boolean(anchorEl);
|
const open = Boolean(anchorEl);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const handleAvatarClick = (event: React.MouseEvent<HTMLElement>) => {
|
const handleAvatarClick = (event: React.MouseEvent<HTMLElement>) => {
|
||||||
setAnchorEl(event.currentTarget);
|
setAnchorEl(event.currentTarget);
|
||||||
@@ -30,6 +32,11 @@ const Header = () => {
|
|||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleProfileClick = () => {
|
||||||
|
navigate('/setting/profile');
|
||||||
|
setAnchorEl(null);
|
||||||
|
};
|
||||||
|
|
||||||
const handleLogout = () => {
|
const handleLogout = () => {
|
||||||
logout();
|
logout();
|
||||||
handleClose();
|
handleClose();
|
||||||
@@ -179,7 +186,7 @@ const Header = () => {
|
|||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
{/* 菜单项 */}
|
{/* 菜单项 */}
|
||||||
<MenuItem onClick={handleClose} sx={{ py: 1 }}>
|
<MenuItem onClick={handleProfileClick} sx={{ py: 1 }}>
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
<PersonIcon fontSize="small" />
|
<PersonIcon fontSize="small" />
|
||||||
</ListItemIcon>
|
</ListItemIcon>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { Box, styled } from '@mui/material';
|
|||||||
import { Outlet } from 'react-router-dom';
|
import { Outlet } from 'react-router-dom';
|
||||||
import Header from './Header';
|
import Header from './Header';
|
||||||
import Sidebar from './Sidebar';
|
import Sidebar from './Sidebar';
|
||||||
import UserDataProvider from '../Provider/UserDataProvider';
|
|
||||||
|
|
||||||
const LayoutContainer = styled(Box)({
|
const LayoutContainer = styled(Box)({
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
@@ -25,7 +24,6 @@ const ContentArea = styled(Box)({
|
|||||||
|
|
||||||
const MainLayout = () => {
|
const MainLayout = () => {
|
||||||
return (
|
return (
|
||||||
<UserDataProvider>
|
|
||||||
<LayoutContainer>
|
<LayoutContainer>
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
<MainContent>
|
<MainContent>
|
||||||
@@ -35,7 +33,6 @@ const MainLayout = () => {
|
|||||||
</ContentArea>
|
</ContentArea>
|
||||||
</MainContent>
|
</MainContent>
|
||||||
</LayoutContainer>
|
</LayoutContainer>
|
||||||
</UserDataProvider>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
17
src/components/Layout/SettingLayout.tsx
Normal file
17
src/components/Layout/SettingLayout.tsx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { Box, styled } from "@mui/material";
|
||||||
|
import { Outlet } from "react-router-dom";
|
||||||
|
|
||||||
|
const LayoutContainer = styled(Box)({
|
||||||
|
display: 'flex',
|
||||||
|
height: '100vh',
|
||||||
|
});
|
||||||
|
|
||||||
|
function SettingLayout() {
|
||||||
|
return (
|
||||||
|
<LayoutContainer>
|
||||||
|
<Outlet />
|
||||||
|
</LayoutContainer>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SettingLayout;
|
||||||
5
src/pages/setting/index.tsx
Normal file
5
src/pages/setting/index.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export { default as ModelsSetting } from './models';
|
||||||
|
export { default as SystemSetting } from './system';
|
||||||
|
export { default as TeamsSetting } from './teams';
|
||||||
|
export { default as ProfileSetting } from './profile';
|
||||||
|
export { default as MCPSetting } from './mcp';
|
||||||
8
src/pages/setting/mcp.tsx
Normal file
8
src/pages/setting/mcp.tsx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
function MCPSetting() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>MCP Setting</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
export default MCPSetting;
|
||||||
9
src/pages/setting/models.tsx
Normal file
9
src/pages/setting/models.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
function ModelsSetting() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Model Setting</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ModelsSetting;
|
||||||
9
src/pages/setting/profile.tsx
Normal file
9
src/pages/setting/profile.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
function ProfileSetting() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Profile Setting</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ProfileSetting;
|
||||||
9
src/pages/setting/system.tsx
Normal file
9
src/pages/setting/system.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
function SystemSetting() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>System Setting</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SystemSetting;
|
||||||
9
src/pages/setting/teams.tsx
Normal file
9
src/pages/setting/teams.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
function TeamsSetting() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Teams Setting</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TeamsSetting;
|
||||||
@@ -1,15 +1,28 @@
|
|||||||
import { Routes, Route, Navigate } from 'react-router-dom';
|
import { Routes, Route, Navigate } from 'react-router-dom';
|
||||||
import MainLayout from '../components/Layout/MainLayout';
|
import MainLayout from '../components/Layout/MainLayout';
|
||||||
|
import SettingLayout from '../components/Layout/SettingLayout';
|
||||||
import Login from '../pages/login/Login';
|
import Login from '../pages/login/Login';
|
||||||
import Home from '../pages/Home';
|
|
||||||
import PipelineConfig from '../pages/PipelineConfig';
|
import PipelineConfig from '../pages/PipelineConfig';
|
||||||
import Dashboard from '../pages/Dashboard';
|
import Dashboard from '../pages/Dashboard';
|
||||||
import ModelsResources from '../pages/ModelsResources';
|
import ModelsResources from '../pages/ModelsResources';
|
||||||
import { KnowledgeBaseList, KnowledgeBaseCreate, KnowledgeBaseDetail, KnowledgeBaseSetting, KnowledgeBaseTesting } from '../pages/knowledge';
|
import {
|
||||||
|
KnowledgeBaseList,
|
||||||
|
KnowledgeBaseCreate,
|
||||||
|
KnowledgeBaseDetail,
|
||||||
|
KnowledgeBaseSetting,
|
||||||
|
KnowledgeBaseTesting
|
||||||
|
} from '../pages/knowledge';
|
||||||
|
import {
|
||||||
|
ModelsSetting,
|
||||||
|
SystemSetting,
|
||||||
|
TeamsSetting,
|
||||||
|
ProfileSetting,
|
||||||
|
MCPSetting,
|
||||||
|
} from '../pages/setting';
|
||||||
import MCP from '../pages/MCP';
|
import MCP from '../pages/MCP';
|
||||||
import FormFieldTest from '../pages/FormFieldTest';
|
import FormFieldTest from '../pages/FormFieldTest';
|
||||||
import ChunkParsedResult from '@/pages/chunk/parsed-result';
|
import ChunkParsedResult from '../pages/chunk/parsed-result';
|
||||||
import DocumentPreview from '@/pages/chunk/document-preview';
|
import DocumentPreview from '../pages/chunk/document-preview';
|
||||||
|
|
||||||
const AppRoutes = () => {
|
const AppRoutes = () => {
|
||||||
return (
|
return (
|
||||||
@@ -42,6 +55,15 @@ const AppRoutes = () => {
|
|||||||
{/* 文档预览页面路由 */}
|
{/* 文档预览页面路由 */}
|
||||||
<Route path="document-preview/:kb_id/:doc_id" element={<DocumentPreview />} />
|
<Route path="document-preview/:kb_id/:doc_id" element={<DocumentPreview />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
{/* setting 相关路由 */}
|
||||||
|
<Route path="setting" element={<SettingLayout />}>
|
||||||
|
<Route index element={<ModelsSetting />} />
|
||||||
|
<Route path="models" element={<ModelsSetting />} />
|
||||||
|
<Route path="system" element={<SystemSetting />} />
|
||||||
|
<Route path="teams" element={<TeamsSetting />} />
|
||||||
|
<Route path="profile" element={<ProfileSetting />} />
|
||||||
|
<Route path="mcp" element={<MCPSetting />} />
|
||||||
|
</Route>
|
||||||
|
|
||||||
{/* 处理未匹配的路由 */}
|
{/* 处理未匹配的路由 */}
|
||||||
<Route path="*" element={<Navigate to="/" replace />} />
|
<Route path="*" element={<Navigate to="/" replace />} />
|
||||||
|
|||||||
Reference in New Issue
Block a user