完成连接OpcUa服务器

This commit is contained in:
2025-08-25 21:26:18 +08:00
parent 8290c96b1b
commit f80a1669fb
11 changed files with 86 additions and 155 deletions

View File

@@ -18,6 +18,7 @@ namespace DMS.WPF.Services
{ typeof(ConfirmDialogViewModel), typeof(ConfirmDialog) },
{ typeof(VariableTableDialogViewModel), typeof(VariableTableDialog) },
{ typeof(ImportExcelDialogViewModel), typeof(ImportExcelDialog) },
{ typeof(ImportOpcUaDialogViewModel), typeof(ImportOpcUaDialog) },
{ typeof(VariableDialogViewModel), typeof(VariableDialog) },
// { typeof(MqttDialogViewModel), typeof(MqttDialog) }, // Add other mappings here
// ... other dialogs

View File

@@ -1,68 +0,0 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using DMS.Helper;
using DMS.Message;
using DMS.WPF.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using DMS.Core.Enums;
namespace DMS.Services;
public partial class NavgatorServices : ObservableRecipient, IRecipient<NavgatorMessage>
{
// [ObservableProperty]
private ViewModelBase currentViewModel;
public NavgatorServices()
{
IsActive = true;
}
// partial void OnCurrentViewModelChanging(ViewModelBase viewModel)
// {
// viewModel?.OnLoading();
// }
//
// partial void OnCurrentViewModelChanged(ViewModelBase viewModel)
// {
// OnViewModelChanged?.Invoke();
// viewModel?.OnLoaded();
// }
public ViewModelBase CurrentViewModel
{
get => currentViewModel;
set { currentViewModel = value; }
}
public async void Receive(NavgatorMessage message)
{
try
{
ViewModelBase nextViewModel = message.Value;
//如果OnExit返回False终止跳转
if (currentViewModel != null)
{
var isExit = await currentViewModel.OnExitAsync();
if (!isExit)
{
return;
}
}
nextViewModel?.OnLoading();
CurrentViewModel = message.Value;
OnViewModelChanged?.Invoke();
currentViewModel?.OnLoaded();
}
catch (Exception e)
{
NotificationHelper.ShowError($"切换视图时发生了错误:{e.Message}", e);
}
}
public event Action OnViewModelChanged;
}

View File

@@ -1,14 +1,15 @@
// 文件: DMS.WPF/Services/NavigationService.cs
using DMS.Helper;
using DMS.ViewModels;
using DMS.WPF.ViewModels;
using DMS.WPF.ViewModels.Items;
using DMS.WPF.Views;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using DMS.ViewModels;
using DMS.WPF.ViewModels.Items;
using DMS.WPF.Views;
namespace DMS.WPF.Services;
@@ -39,6 +40,13 @@ public class NavigationService : INavigationService
var mainViewModel = App.Current.Services.GetRequiredService<MainViewModel>();
var viewModel = GetViewModelByKey(menu.TargetViewKey);
if (viewModel == null)
{
NotificationHelper.ShowError($"切换界面失败,没有找到界面:{menu.TargetViewKey}");
return;
}
if (viewModel is INavigatable navigatableViewModel)
{
@@ -70,7 +78,7 @@ public class NavigationService : INavigationService
case "SettingView":
return App.Current.Services.GetRequiredService<SettingViewModel>();
default:
throw new KeyNotFoundException($"未找到与键 '{key}' 关联的视图模型类型。请检查 NavigationService 的映射配置。");
return null;
}
}
}