|
|
@@ -24,6 +24,7 @@ import { theme } from 'antd';
|
|
|
import { getAntdLocale, setDayjsLocale } from './utils/localeHelper';
|
|
|
import { setupGlobalErrorHandlers } from './utils/errorHandler';
|
|
|
import ServerConfigModal from './features/serverConfig/components/ServerConfigModal';
|
|
|
+import { ServerConfig } from './features/serverConfig/types';
|
|
|
console.log = logger.log;
|
|
|
console.warn = logger.warn;
|
|
|
console.error = logger.error;
|
|
|
@@ -60,6 +61,8 @@ function AppContent({ children }: { children: ReactNode }): JSX.Element {
|
|
|
const [isI18nReady, setIsI18nReady] = useState(false);
|
|
|
const [showConfigModal, setShowConfigModal] = useState(false);
|
|
|
const [connectionChecked, setConnectionChecked] = useState(false);
|
|
|
+ const [connectionCheckMessage, setConnectionCheckMessage] = useState('');
|
|
|
+ const [currentServerConfig, setCurrentServerConfig] = useState<ServerConfig | null>(null);
|
|
|
const themeWithAlgorithm = {
|
|
|
...currentTheme,
|
|
|
algorithm:
|
|
|
@@ -87,10 +90,13 @@ function AppContent({ children }: { children: ReactNode }): JSX.Element {
|
|
|
}
|
|
|
|
|
|
// Electron/Cordova 环境:检查服务器连接
|
|
|
- dispatch(checkServerConnection())
|
|
|
+ setConnectionCheckMessage('正在检测服务器连接...');
|
|
|
+ dispatch(checkServerConnection({ onProgress: handleConnectionProgress }))
|
|
|
.unwrap()
|
|
|
.then(async (result) => {
|
|
|
setConnectionChecked(true);
|
|
|
+ setConnectionCheckMessage('');
|
|
|
+ setCurrentServerConfig(result.config);
|
|
|
|
|
|
if (result.needsConfig) {
|
|
|
// 需要配置,显示对话框
|
|
|
@@ -105,6 +111,8 @@ function AppContent({ children }: { children: ReactNode }): JSX.Element {
|
|
|
.catch((error) => {
|
|
|
console.error('连接检查失败:', error);
|
|
|
setConnectionChecked(true);
|
|
|
+ setConnectionCheckMessage('');
|
|
|
+ setCurrentServerConfig(null);
|
|
|
setShowConfigModal(true);
|
|
|
});
|
|
|
|
|
|
@@ -140,14 +148,20 @@ function AppContent({ children }: { children: ReactNode }): JSX.Element {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ // 进度更新函数
|
|
|
+ const handleConnectionProgress = (progress: { current: number; total: number }) => {
|
|
|
+ setConnectionCheckMessage(`正在检测服务器连接... (${progress.current}/${progress.total})`);
|
|
|
+ };
|
|
|
+
|
|
|
// 配置保存后的处理
|
|
|
const handleConfigSaved = () => {
|
|
|
setShowConfigModal(false);
|
|
|
// 重新检查连接并初始化应用
|
|
|
- dispatch(checkServerConnection())
|
|
|
+ dispatch(checkServerConnection({ onProgress: handleConnectionProgress }))
|
|
|
.unwrap()
|
|
|
.then((result) => {
|
|
|
if (!result.needsConfig) {
|
|
|
+ setConnectionCheckMessage('');//通了,隐藏服务器连接检测覆盖层
|
|
|
initializeApp();
|
|
|
}
|
|
|
})
|
|
|
@@ -177,7 +191,7 @@ function AppContent({ children }: { children: ReactNode }): JSX.Element {
|
|
|
}`}
|
|
|
</style>
|
|
|
|
|
|
- {/* 加载状态覆盖层 */}
|
|
|
+ {/* 多语言加载状态覆盖层 */}
|
|
|
{(loading || (!isI18nReady && !connectionChecked)) && (
|
|
|
<div
|
|
|
style={{
|
|
|
@@ -198,11 +212,33 @@ function AppContent({ children }: { children: ReactNode }): JSX.Element {
|
|
|
</div>
|
|
|
)}
|
|
|
|
|
|
+ {/* 服务器连接检测覆盖层 */}
|
|
|
+ {connectionCheckMessage && (
|
|
|
+ <div
|
|
|
+ style={{
|
|
|
+ position: 'fixed',
|
|
|
+ top: 0,
|
|
|
+ left: 0,
|
|
|
+ right: 0,
|
|
|
+ bottom: 0,
|
|
|
+ zIndex: 10000, // 比多语言加载覆盖层更高
|
|
|
+ display: 'flex',
|
|
|
+ justifyContent: 'center',
|
|
|
+ alignItems: 'center',
|
|
|
+ backgroundColor: currentTheme.token.colorBgLayout,
|
|
|
+ color: currentTheme.token.colorText,
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <div>{connectionCheckMessage}</div>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+
|
|
|
{/* 服务器配置对话框 */}
|
|
|
<ServerConfigModal
|
|
|
open={showConfigModal}
|
|
|
onSave={handleConfigSaved}
|
|
|
onCancel={() => setShowConfigModal(false)}
|
|
|
+ initialConfig={currentServerConfig}
|
|
|
/>
|
|
|
|
|
|
{/* 错误状态覆盖层 */}
|