119 lines
3.8 KiB
TypeScript
119 lines
3.8 KiB
TypeScript
import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom'
|
|
import { ConfigProvider, App as AntdApp } from 'antd'
|
|
import zhCN from 'antd/locale/zh_CN'
|
|
import { AuthProvider, useAuth } from './store/auth'
|
|
import MainLayout from './layouts/MainLayout'
|
|
import Login from './pages/Login'
|
|
import Dashboard from './pages/Dashboard'
|
|
import OpenApiDocs from './pages/OpenApiDocs'
|
|
import ApiDebugger from './pages/ApiDebugger'
|
|
import Delivery from './pages/Delivery'
|
|
import MerchantCenter from './pages/MerchantCenter'
|
|
import MerchantRecharge from './pages/MerchantRecharge'
|
|
import AlertSettings from './pages/AlertSettings'
|
|
import PlatformMerchants from './pages/PlatformMerchants'
|
|
import type { ReactNode } from 'react'
|
|
function PrivateRoute({ children }: { children: ReactNode }) {
|
|
const { token } = useAuth()
|
|
if (!token) return <Navigate to="/login" replace />
|
|
return <>{children}</>
|
|
}
|
|
|
|
function AdminRoute({ children }: { children: ReactNode }) {
|
|
const { isAdmin } = useAuth()
|
|
if (!isAdmin) return <Navigate to="/" replace />
|
|
return <>{children}</>
|
|
}
|
|
|
|
function AppRoutes() {
|
|
return (
|
|
<Routes>
|
|
<Route path="/login" element={<Login />} />
|
|
<Route path="/delivery/:channel/:orderNo" element={<Delivery />} />
|
|
<Route
|
|
path="/"
|
|
element={
|
|
<PrivateRoute>
|
|
<MainLayout />
|
|
</PrivateRoute>
|
|
}
|
|
>
|
|
<Route index element={<Dashboard />} />
|
|
<Route path="merchant-center" element={<MerchantCenter />} />
|
|
<Route path="merchant-products" element={<MerchantCenter fixedTab="products" title="商品列表" />} />
|
|
<Route path="merchant-orders" element={<MerchantCenter fixedTab="orders" title="发货订单" />} />
|
|
<Route path="merchant-wallet" element={<MerchantCenter fixedTab="wallet" title="积分明细" />} />
|
|
<Route path="merchant-recharge" element={<MerchantRecharge />} />
|
|
<Route path="merchant-alert-settings" element={<AlertSettings />} />
|
|
<Route path="merchant-members" element={<MerchantCenter fixedTab="members" title="成员" />} />
|
|
<Route path="merchant-callbacks" element={<MerchantCenter fixedTab="callbacks" title="回调" />} />
|
|
<Route path="merchant-api-keys" element={<MerchantCenter fixedTab="api" title="API 密钥" />} />
|
|
<Route
|
|
path="platform-merchants"
|
|
element={
|
|
<AdminRoute>
|
|
<PlatformMerchants />
|
|
</AdminRoute>
|
|
}
|
|
/>
|
|
<Route path="open-api" element={<OpenApiDocs />} />
|
|
<Route
|
|
path="api-debug"
|
|
element={
|
|
<AdminRoute>
|
|
<ApiDebugger />
|
|
</AdminRoute>
|
|
}
|
|
/>
|
|
</Route>
|
|
<Route path="*" element={<Navigate to="/" replace />} />
|
|
</Routes>
|
|
)
|
|
}
|
|
|
|
export default function App() {
|
|
return (
|
|
<ConfigProvider
|
|
locale={zhCN}
|
|
theme={{
|
|
token: {
|
|
colorPrimary: '#2563eb',
|
|
colorInfo: '#2563eb',
|
|
colorSuccess: '#16a34a',
|
|
colorWarning: '#d97706',
|
|
colorError: '#dc2626',
|
|
borderRadius: 8,
|
|
fontFamily: `-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif`,
|
|
},
|
|
components: {
|
|
Card: {
|
|
paddingLG: 20,
|
|
borderRadiusLG: 10,
|
|
},
|
|
Table: {
|
|
headerBg: '#f8fafc',
|
|
headerColor: '#475569',
|
|
headerSplitColor: 'transparent',
|
|
rowHoverBg: '#f1f5f9',
|
|
},
|
|
Button: {
|
|
fontWeight: 600,
|
|
borderRadius: 6,
|
|
},
|
|
Tag: {
|
|
borderRadiusSM: 4,
|
|
},
|
|
},
|
|
}}
|
|
>
|
|
<AntdApp>
|
|
<AuthProvider>
|
|
<BrowserRouter>
|
|
<AppRoutes />
|
|
</BrowserRouter>
|
|
</AuthProvider>
|
|
</AntdApp>
|
|
</ConfigProvider>
|
|
)
|
|
}
|