|
@@ -55,6 +55,7 @@ function AppContent({ children }: { children: ReactNode }): JSX.Element {
|
|
|
.dispatch(initializeProductState())
|
|
|
.unwrap()
|
|
|
.then((productState) => {
|
|
|
+ console.log(`初始化,拉取到产品信息:${JSON.stringify(productState)}`);
|
|
|
// 从 current_locale 提取语言代码
|
|
|
const languageCode = productState.language;
|
|
|
|
|
@@ -70,58 +71,16 @@ function AppContent({ children }: { children: ReactNode }): JSX.Element {
|
|
|
});
|
|
|
}, [dispatch]);
|
|
|
|
|
|
- // 显示加载状态
|
|
|
- if (loading || !isI18nReady) {
|
|
|
- return (
|
|
|
- <div
|
|
|
- style={{
|
|
|
- display: 'flex',
|
|
|
- justifyContent: 'center',
|
|
|
- alignItems: 'center',
|
|
|
- height: '100vh',
|
|
|
- backgroundColor: currentTheme.token.colorBgLayout,
|
|
|
- color: currentTheme.token.colorText,
|
|
|
- }}
|
|
|
- >
|
|
|
- <div>加载多语言资源中...</div>
|
|
|
- <div style={{ display: 'none' }}>{children}</div>
|
|
|
- </div>
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- // 显示错误状态
|
|
|
- if (error) {
|
|
|
- return (
|
|
|
- <div
|
|
|
- style={{
|
|
|
- display: 'flex',
|
|
|
- justifyContent: 'center',
|
|
|
- alignItems: 'center',
|
|
|
- height: '100vh',
|
|
|
- flexDirection: 'column',
|
|
|
- backgroundColor: currentTheme.token.colorBgLayout,
|
|
|
- color: currentTheme.token.colorText,
|
|
|
- }}
|
|
|
- >
|
|
|
- <div>多语言资源加载失败: {error}</div>
|
|
|
- <button
|
|
|
- onClick={() => window.location.reload()}
|
|
|
- style={{ marginTop: '16px', padding: '8px 16px' }}
|
|
|
- >
|
|
|
- 重新加载
|
|
|
- </button>
|
|
|
- <div style={{ display: 'none' }}>{children}</div>
|
|
|
- </div>
|
|
|
- );
|
|
|
- }
|
|
|
console.log('当前语言:', currentLocale);
|
|
|
console.log('messages', messages);
|
|
|
+
|
|
|
// children 是将要会渲染的页面
|
|
|
+ // IntlProvider 始终存在,使用默认值避免 useIntl 报错
|
|
|
return (
|
|
|
<ConfigProvider theme={currentTheme}>
|
|
|
<IntlProvider
|
|
|
- locale={currentLocale.split('_')[0]} // en_US -> en
|
|
|
- messages={messages as Record<string, string>}
|
|
|
+ locale={currentLocale ? currentLocale.split('_')[0] : 'en'} // en_US -> en,提供默认值
|
|
|
+ messages={(messages as Record<string, string>) || {}} // 提供空对象作为默认值
|
|
|
>
|
|
|
<style>
|
|
|
{/*把theme中的colorPrimary转换成变量--color-primary,变量被tailwindcss使用*/}
|
|
@@ -132,6 +91,57 @@ function AppContent({ children }: { children: ReactNode }): JSX.Element {
|
|
|
--button-bg-hover: ${currentTheme.token.buttonBgHover};
|
|
|
}`}
|
|
|
</style>
|
|
|
+
|
|
|
+ {/* 加载状态覆盖层 */}
|
|
|
+ {(loading || !isI18nReady) && (
|
|
|
+ <div
|
|
|
+ style={{
|
|
|
+ position: 'fixed',
|
|
|
+ top: 0,
|
|
|
+ left: 0,
|
|
|
+ right: 0,
|
|
|
+ bottom: 0,
|
|
|
+ zIndex: 9999,
|
|
|
+ display: 'flex',
|
|
|
+ justifyContent: 'center',
|
|
|
+ alignItems: 'center',
|
|
|
+ backgroundColor: currentTheme.token.colorBgLayout,
|
|
|
+ color: currentTheme.token.colorText,
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <div>加载多语言资源中...</div>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+
|
|
|
+ {/* 错误状态覆盖层 */}
|
|
|
+ {error && (
|
|
|
+ <div
|
|
|
+ style={{
|
|
|
+ position: 'fixed',
|
|
|
+ top: 0,
|
|
|
+ left: 0,
|
|
|
+ right: 0,
|
|
|
+ bottom: 0,
|
|
|
+ zIndex: 9999,
|
|
|
+ display: 'flex',
|
|
|
+ justifyContent: 'center',
|
|
|
+ alignItems: 'center',
|
|
|
+ flexDirection: 'column',
|
|
|
+ backgroundColor: currentTheme.token.colorBgLayout,
|
|
|
+ color: currentTheme.token.colorText,
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <div>多语言资源加载失败: {error}</div>
|
|
|
+ <button
|
|
|
+ onClick={() => window.location.reload()}
|
|
|
+ style={{ marginTop: '16px', padding: '8px 16px' }}
|
|
|
+ >
|
|
|
+ 重新加载
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+
|
|
|
+ {/* children 始终被渲染,满足 Taro 框架要求 */}
|
|
|
<div
|
|
|
style={{
|
|
|
backgroundColor: currentTheme.token.colorBgLayout,
|