@@ -13,25 +13,24 @@ import { ErrorBoundary } from './providers/ErrorBoundary';
1313import { getToken } from '../shared/api/client' ;
1414import { usersApi } from '../shared/api/users' ;
1515import { setupApi } from '../shared/api/setup' ;
16- import DashboardPage from '../pages/DashboardPage' ;
17- import UserOverviewPage from '../pages/user/UserOverviewPage' ;
18- import UsersPage from '../pages/admin/UsersPage' ;
19- import AccountsPage from '../pages/admin/AccountsPage' ;
20- import GroupsPage from '../pages/admin/GroupsPage' ;
21- import SubscriptionsPage from '../pages/admin/SubscriptionsPage' ;
22- import ProxiesPage from '../pages/admin/ProxiesPage' ;
23- import UsagePage from '../pages/admin/UsagePage' ;
24- import PluginsPage from '../pages/admin/PluginsPage' ;
25- import SettingsPage from '../pages/admin/SettingsPage' ;
26- import ProfilePage from '../pages/user/ProfilePage' ;
27- import UserKeysPage from '../pages/user/UserKeysPage' ;
28- import UserUsagePage from '../pages/user/UserUsagePage' ;
29- // 登录、安装、首页不常用,保持懒加载
3016const SetupPage = lazy ( ( ) => import ( '../pages/SetupPage' ) ) ;
3117const LoginPage = lazy ( ( ) => import ( '../pages/LoginPage' ) ) ;
3218const PluginPage = lazy ( ( ) => import ( '../pages/PluginPage' ) ) ;
3319const PublicHomePage = lazy ( ( ) => import ( '../pages/HomePage' ) ) ;
3420const DocsPage = lazy ( ( ) => import ( '../pages/DocsPage' ) ) ;
21+ const DashboardPage = lazy ( ( ) => import ( '../pages/DashboardPage' ) ) ;
22+ const UserOverviewPage = lazy ( ( ) => import ( '../pages/user/UserOverviewPage' ) ) ;
23+ const UsersPage = lazy ( ( ) => import ( '../pages/admin/UsersPage' ) ) ;
24+ const AccountsPage = lazy ( ( ) => import ( '../pages/admin/AccountsPage' ) ) ;
25+ const GroupsPage = lazy ( ( ) => import ( '../pages/admin/GroupsPage' ) ) ;
26+ const SubscriptionsPage = lazy ( ( ) => import ( '../pages/admin/SubscriptionsPage' ) ) ;
27+ const ProxiesPage = lazy ( ( ) => import ( '../pages/admin/ProxiesPage' ) ) ;
28+ const UsagePage = lazy ( ( ) => import ( '../pages/admin/UsagePage' ) ) ;
29+ const PluginsPage = lazy ( ( ) => import ( '../pages/admin/PluginsPage' ) ) ;
30+ const SettingsPage = lazy ( ( ) => import ( '../pages/admin/SettingsPage' ) ) ;
31+ const ProfilePage = lazy ( ( ) => import ( '../pages/user/ProfilePage' ) ) ;
32+ const UserKeysPage = lazy ( ( ) => import ( '../pages/user/UserKeysPage' ) ) ;
33+ const UserUsagePage = lazy ( ( ) => import ( '../pages/user/UserUsagePage' ) ) ;
3534
3635// 缓存安装状态,避免每次路由跳转都请求
3736let setupChecked = false ;
@@ -153,12 +152,16 @@ const authLayout = createRoute({
153152 ) ,
154153} ) ;
155154
156- // 首页:API Key 登录重定向到使用记录,管理员看仪表盘,普通用户看个人概览
157155function HomePage ( ) {
158156 const { user, isAPIKeySession } = useAuth ( ) ;
159157 if ( ! user ) return null ;
160- if ( isAPIKeySession ) return < UserUsagePage /> ;
161- return user . role === 'admin' ? < DashboardPage /> : < UserOverviewPage /> ;
158+
159+ const Page = isAPIKeySession ? UserUsagePage : user . role === 'admin' ? DashboardPage : UserOverviewPage ;
160+ return (
161+ < Suspense fallback = { null } >
162+ < Page />
163+ </ Suspense >
164+ ) ;
162165}
163166const dashboardRoute = createRoute ( { getParentRoute : ( ) => authLayout , path : '/' , component : HomePage } ) ;
164167
@@ -175,20 +178,26 @@ const adminLayout = createRoute({
175178 component : Outlet ,
176179} ) ;
177180
178- // 管理员路由
179- const adminUsersRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/users' , component : UsersPage } ) ;
180- const adminAccountsRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/accounts' , component : AccountsPage } ) ;
181- const adminGroupsRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/groups' , component : GroupsPage } ) ;
182- const adminSubscriptionsRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/subscriptions' , component : SubscriptionsPage } ) ;
183- const adminProxiesRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/proxies' , component : ProxiesPage } ) ;
184- const adminUsageRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/usage' , component : UsagePage } ) ;
185- const adminPluginsRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/plugins' , component : PluginsPage } ) ;
186- const adminSettingsRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/settings' , component : SettingsPage } ) ;
181+ function renderPage ( Page : React . LazyExoticComponent < React . ComponentType > ) {
182+ return ( ) => (
183+ < Suspense fallback = { null } >
184+ < Page />
185+ </ Suspense >
186+ ) ;
187+ }
188+
189+ const adminUsersRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/users' , component : renderPage ( UsersPage ) } ) ;
190+ const adminAccountsRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/accounts' , component : renderPage ( AccountsPage ) } ) ;
191+ const adminGroupsRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/groups' , component : renderPage ( GroupsPage ) } ) ;
192+ const adminSubscriptionsRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/subscriptions' , component : renderPage ( SubscriptionsPage ) } ) ;
193+ const adminProxiesRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/proxies' , component : renderPage ( ProxiesPage ) } ) ;
194+ const adminUsageRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/usage' , component : renderPage ( UsagePage ) } ) ;
195+ const adminPluginsRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/plugins' , component : renderPage ( PluginsPage ) } ) ;
196+ const adminSettingsRoute = createRoute ( { getParentRoute : ( ) => adminLayout , path : '/admin/settings' , component : renderPage ( SettingsPage ) } ) ;
187197
188- // 用户路由
189- const profileRoute = createRoute ( { getParentRoute : ( ) => authLayout , path : '/profile' , component : ProfilePage } ) ;
190- const userKeysRoute = createRoute ( { getParentRoute : ( ) => authLayout , path : '/keys' , component : UserKeysPage } ) ;
191- const userUsageRoute = createRoute ( { getParentRoute : ( ) => authLayout , path : '/usage' , component : UserUsagePage } ) ;
198+ const profileRoute = createRoute ( { getParentRoute : ( ) => authLayout , path : '/profile' , component : renderPage ( ProfilePage ) } ) ;
199+ const userKeysRoute = createRoute ( { getParentRoute : ( ) => authLayout , path : '/keys' , component : renderPage ( UserKeysPage ) } ) ;
200+ const userUsageRoute = createRoute ( { getParentRoute : ( ) => authLayout , path : '/usage' , component : renderPage ( UserUsagePage ) } ) ;
192201
193202// /chat: 全屏沉浸式 AI 对话页(airgate-playground 插件),独立布局不挂 AppShell。
194203// 仍要求登录 + 安装完成;走 ChatShell 极简顶栏。
0 commit comments