完成打开导入OPC变量对话框自动连接服务器

This commit is contained in:
2025-07-09 21:35:51 +08:00
parent 5915a6c87b
commit b1e79a63df
6 changed files with 81 additions and 56 deletions

View File

@@ -37,6 +37,8 @@ public partial class OpcUaImportDialogViewModel : ObservableObject
{
OpcUaNodes = new ObservableCollection<OpcUaNode>();
SelectedNodeVariables = new ObservableCollection<VariableData>();
// Automatically connect when the ViewModel is created
_ = Connect().ConfigureAwait(false);
}
[RelayCommand]

View File

@@ -232,7 +232,13 @@ partial class VariableTableViewModel : ViewModelBase
{
try
{
var importedVariables = await _dialogService.ShowOpcUaImportDialog();
string opcUaEndpointUrl = VariableTable?.Device?.OpcUaEndpointUrl;
if (string.IsNullOrEmpty(opcUaEndpointUrl))
{
NotificationHelper.ShowError("OPC UA Endpoint URL 未设置。请在设备详情中配置。");
return;
}
var importedVariables = await _dialogService.ShowOpcUaImportDialog(opcUaEndpointUrl);
if (importedVariables == null || !importedVariables.Any())
{
return; // 用户取消或没有选择任何变量