配置Vite代理、API请求封装、JWT认证上下文、登录页面、路由鉴权

This commit is contained in:
yml2213
2026-07-14 11:30:33 +08:00
parent a0ced7bdde
commit 6d437b4e82
8 changed files with 264 additions and 17 deletions
+17 -16
View File
@@ -1,9 +1,11 @@
import { lazy, Suspense } from 'react'
import { Navigate, createBrowserRouter } from 'react-router-dom'
import { Spin } from 'antd'
import RequireAuth from '@/components/RequireAuth'
const AgentLayout = lazy(() => import('@/components/layout/AgentLayout'))
const AdminLayout = lazy(() => import('@/components/layout/AdminLayout'))
const Login = lazy(() => import('@/pages/Login'))
const Dashboard = lazy(() => import('@/pages/agent/Dashboard'))
const ChatHistory = lazy(() => import('@/pages/agent/ChatHistory'))
const Customers = lazy(() => import('@/pages/agent/Customers'))
@@ -27,28 +29,27 @@ function Lazy({ children }: { children: React.ReactNode }) {
}
export const router = createBrowserRouter([
{
path: '/widget/preview',
element: <Lazy><WidgetPreview /></Lazy>,
},
{
path: '/admin',
element: <Lazy><AdminLayout /></Lazy>,
children: [
{ index: true, element: <Navigate to="/admin/dashboard" replace /> },
{ path: 'dashboard', element: <Lazy><AdminDashboard /></Lazy> },
{ path: 'tenants', element: <Lazy><Tenants /></Lazy> },
{ path: 'plans', element: <Lazy><Plans /></Lazy> },
{ path: 'ops', element: <Lazy><Ops /></Lazy> },
],
},
{ path: '/login', element: <Lazy><Login /></Lazy> },
{ path: '/widget/preview', element: <Lazy><WidgetPreview /></Lazy> },
{
path: '/',
element: <Lazy><AgentLayout /></Lazy>,
element: <RequireAuth />,
children: [
{
path: 'admin',
element: <Lazy><AdminLayout /></Lazy>,
children: [
{ index: true, element: <Navigate to="/admin/dashboard" replace /> },
{ path: 'dashboard', element: <Lazy><AdminDashboard /></Lazy> },
{ path: 'tenants', element: <Lazy><Tenants /></Lazy> },
{ path: 'plans', element: <Lazy><Plans /></Lazy> },
{ path: 'ops', element: <Lazy><Ops /></Lazy> },
],
},
{ index: true, element: <Navigate to="/agent/dashboard" replace /> },
{
path: 'agent',
element: <Lazy><AgentLayout /></Lazy>,
children: [
{ index: true, element: <Navigate to="/agent/dashboard" replace /> },
{ path: 'dashboard', element: <Lazy><Dashboard /></Lazy> },