@@ -11,39 +11,96 @@ import theme from "./theme";
1111import { errorConfigStore } from "@/utils/errorConfigStore.ts" ;
1212import "@/i18n" ;
1313
14+ async function checkHomePageRedirect ( ) : Promise < string | null > {
15+ try {
16+ const response = await fetch ( '/api/sys-param/sys.home.page.url' , {
17+ cache : 'no-store'
18+ } ) ;
19+
20+ if ( response . ok ) {
21+ const result = await response . json ( ) ;
22+ return result . data ?. paramValue ?. trim ( ) || null ;
23+ }
24+ } catch ( error ) {
25+ console . error ( 'Failed to fetch home page URL:' , error ) ;
26+ }
27+
28+ return null ;
29+ }
30+
31+ function showLoadingUI ( ) {
32+ const container = document . getElementById ( "root" ) ;
33+ if ( ! container ) return ;
34+
35+ container . innerHTML = `
36+ <div style="
37+ min-height: 100vh;
38+ background: linear-gradient(to bottom right, #eff6ff, #e0e7ff);
39+ display: flex;
40+ align-items: center;
41+ justify-content: center;
42+ ">
43+ <div style="text-align: center;">
44+ <div style="
45+ width: 40px;
46+ height: 40px;
47+ border: 3px solid #e5e7eb;
48+ border-top-color: #3b82f6;
49+ border-radius: 50%;
50+ animation: spin 1s linear infinite;
51+ "></div>
52+ <style>
53+ @keyframes spin {
54+ to { transform: rotate(360deg); }
55+ }
56+ </style>
57+ </div>
58+ </div>
59+ ` ;
60+ }
61+
1462async function bootstrap ( ) {
1563 const container = document . getElementById ( "root" ) ;
1664 if ( ! container ) return ;
1765
18- const root = createRoot ( container ) ;
66+ showLoadingUI ( ) ;
1967
2068 try {
21- // 2. 【关键步骤】在渲染前,等待配置文件加载完成
22- // 这一步会发起 fetch 请求去拿 /config/error-code.json
23- await errorConfigStore . loadConfig ( ) ;
69+ const [ , homePageUrl ] = await Promise . all ( [
70+ errorConfigStore . loadConfig ( ) ,
71+ checkHomePageRedirect ( )
72+ ] ) ;
73+
74+ if ( homePageUrl ) {
75+ const currentPath = window . location . pathname ;
76+ const targetPath = new URL ( homePageUrl , window . location . origin ) . pathname ;
77+
78+ if ( currentPath === '/' && currentPath !== targetPath ) {
79+ window . location . href = homePageUrl ;
80+ return ;
81+ }
82+ }
2483
2584 } catch ( e ) {
26- // 容错处理:即使配置文件加载失败(比如404),也不应该导致整个 App 白屏崩溃
27- // 此时 App 会使用代码里的默认兜底文案
28- console . error ( 'Error config load failed, using default messages.' , e ) ;
29- } finally {
30- // 3. 无论配置加载成功与否,最后都执行渲染
31- root . render (
32- < StrictMode >
33- < Provider store = { store } >
34- < ConfigProvider theme = { theme } >
35- < AntdApp >
36- < Suspense fallback = { < Spin /> } >
37- < TopLoadingBar />
38- < RouterProvider router = { router } />
39- </ Suspense >
40- </ AntdApp >
41- </ ConfigProvider >
42- </ Provider >
43- </ StrictMode >
44- ) ;
85+ console . error ( 'Config load failed:' , e ) ;
4586 }
87+
88+ const root = createRoot ( container ) ;
89+
90+ root . render (
91+ < StrictMode >
92+ < Provider store = { store } >
93+ < ConfigProvider theme = { theme } >
94+ < AntdApp >
95+ < Suspense fallback = { < Spin /> } >
96+ < TopLoadingBar />
97+ < RouterProvider router = { router } />
98+ </ Suspense >
99+ </ AntdApp >
100+ </ ConfigProvider >
101+ </ Provider >
102+ </ StrictMode >
103+ ) ;
46104}
47105
48- // 4. 执行启动
49106bootstrap ( ) ;
0 commit comments