临时提交

This commit is contained in:
2025-07-26 11:51:09 +08:00
parent db419edde3
commit 2ee17c2560
4 changed files with 33 additions and 20 deletions

View File

@@ -55,7 +55,7 @@ public partial class App : System.Windows.Application
protected override async void OnStartup(StartupEventArgs e) protected override async void OnStartup(StartupEventArgs e)
{ {
base.OnStartup(e); base.OnStartup(e);
ShutdownMode = ShutdownMode.OnExplicitShutdown; ShutdownMode = ShutdownMode.OnLastWindowClose;
ThemeHelper.InitializeTheme(); ThemeHelper.InitializeTheme();
await Host.StartAsync(); await Host.StartAsync();
@@ -80,8 +80,8 @@ public partial class App : System.Windows.Application
NotificationHelper.ShowError("加载数据时发生错误,如果是连接字符串不正确,可以在设置界面更改:{exception.Message}", exception); NotificationHelper.ShowError("加载数据时发生错误,如果是连接字符串不正确,可以在设置界面更改:{exception.Message}", exception);
} }
MainWindow = Host.Services.GetRequiredService<SplashWindow>(); var splashWindow = Host.Services.GetRequiredService<SplashWindow>();
MainWindow.Show(); splashWindow.Show();
// 根据配置启动服务 // 根据配置启动服务
// var connectionSettings = DMS.Config.AppSettings.Load(); // var connectionSettings = DMS.Config.AppSettings.Load();

View File

@@ -1,10 +1,13 @@
// 文件: DMS.WPF/Services/NavigationService.cs // 文件: DMS.WPF/Services/NavigationService.cs
using DMS.WPF.ViewModels; using DMS.WPF.ViewModels;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
using DMS.ViewModels; using DMS.ViewModels;
using DMS.WPF.Views;
namespace DMS.WPF.Services; namespace DMS.WPF.Services;
@@ -50,9 +53,14 @@ public class NavigationService : INavigationService
/// </summary> /// </summary>
public Task ShowMainWindowAsync() public Task ShowMainWindowAsync()
{ {
var mainWindow = _serviceProvider.GetRequiredService<MainWindow>(); return App.Current.Dispatcher.InvokeAsync(() =>
mainWindow.Show(); {
return Task.CompletedTask; var mainView = _serviceProvider.GetRequiredService<MainView>();
// 将 MainView 设置为新的主窗口
App.Current.MainWindow = mainView;
mainView.Show();
})
.Task;
} }
private Type GetViewModelTypeByKey(string key) private Type GetViewModelTypeByKey(string key)

View File

@@ -29,7 +29,7 @@ public partial class SplashViewModel : ObservableObject
/// <summary> /// <summary>
/// 开始执行初始化任务。 /// 开始执行初始化任务。
/// </summary> /// </summary>
public async Task InitializeAsync() public async Task<bool> InitializeAsync()
{ {
try try
{ {
@@ -50,12 +50,14 @@ public partial class SplashViewModel : ObservableObject
// 初始化完成,显示主窗口 // 初始化完成,显示主窗口
var navigationService = (INavigationService)_serviceProvider.GetService(typeof(INavigationService)); var navigationService = (INavigationService)_serviceProvider.GetService(typeof(INavigationService));
await navigationService.ShowMainWindowAsync(); await navigationService.ShowMainWindowAsync();
return true;
} }
catch (Exception ex) catch (Exception ex)
{ {
// 处理初始化过程中的异常 // 处理初始化过程中的异常
LoadingMessage = $"初始化失败: {ex.Message}"; LoadingMessage = $"初始化失败: {ex.Message}";
// 在此可以记录日志或显示错误对话框 // 在此可以记录日志或显示错误对话框
return false;
} }
} }
} }

View File

@@ -15,8 +15,11 @@ public partial class SplashWindow : Window
DataContext = viewModel; DataContext = viewModel;
Loaded += async (s, e) => Loaded += async (s, e) =>
{ {
await viewModel.InitializeAsync(); var success = await viewModel.InitializeAsync();
if (success)
{
Close(); Close();
}
}; };
} }
} }