设置界面优化

This commit is contained in:
hsc
2026-06-09 09:19:35 +08:00
parent bb4fe61ded
commit c01aa6e545
16 changed files with 196 additions and 59 deletions

View File

@@ -678,8 +678,9 @@ namespace ADP.ViewModels
_globalInfo.ContextDic.Remove(targetRegionName); _globalInfo.ContextDic.Remove(targetRegionName);
_globalInfo.StepRunningDic.Remove(targetRegionName); _globalInfo.StepRunningDic.Remove(targetRegionName);
_globalInfo.ScopeDic.Remove(targetRegionName);
var parameters = new NavigationParameters { { "Name", targetRegionName } }; var parameters = new NavigationParameters { { "Name", targetRegionName } };
_regionManager.RequestNavigate(targetRegionName, "ProtocolStartView", parameters); _regionManager.RequestNavigate(targetRegionName, "ProtocolStartView", parameters);
_eventAggregator.GetEvent<ExpandViewEvent>().Publish(""); _eventAggregator.GetEvent<ExpandViewEvent>().Publish("");
} }

View File

@@ -29,7 +29,7 @@ namespace MainModule.ViewModels
public ScopedContext _scopedContext { get; } public ScopedContext _scopedContext { get; }
public StepRunning _stepRunning { get; } public StepRunning _stepRunning { get; }
public GlobalInfo _globalInfo { get; } public GlobalInfo _globalInfo { get; }
public SystemConfig _systemConfig { get; } public SystemConfig _systemConfig { get; set; }
// 5 个子 ViewModel 全部从同一个 scope 解析,自动注入同一个 ScopedContext // 5 个子 ViewModel 全部从同一个 scope 解析,自动注入同一个 ScopedContext
public CommandTreeViewModel CommandTreeVM { get; } public CommandTreeViewModel CommandTreeVM { get; }
@@ -50,7 +50,6 @@ namespace MainModule.ViewModels
// 在该作用域内解析 ScopedContext —— 当前作用域唯一 // 在该作用域内解析 ScopedContext —— 当前作用域唯一
_scopedContext = _scope.Resolve<ScopedContext>(); _scopedContext = _scope.Resolve<ScopedContext>();
_stepRunning = _scope.Resolve<StepRunning>(); _stepRunning = _scope.Resolve<StepRunning>();
_systemConfig=_scope.Resolve<SystemConfig>();
// 关键:从同一个 _scope 解析 5 个子 VMDI 会把同一个 ScopedContext 注入它们 // 关键:从同一个 _scope 解析 5 个子 VMDI 会把同一个 ScopedContext 注入它们
CommandTreeVM = _scope.Resolve<CommandTreeViewModel>(); CommandTreeVM = _scope.Resolve<CommandTreeViewModel>();
StepsManagerVM = _scope.Resolve<StepsManagerViewModel>(); StepsManagerVM = _scope.Resolve<StepsManagerViewModel>();
@@ -108,6 +107,18 @@ namespace MainModule.ViewModels
_globalInfo.ContextDic.Add(TestStatus, _scopedContext); _globalInfo.ContextDic.Add(TestStatus, _scopedContext);
_globalInfo.StepRunningDic.Add(TestStatus, _stepRunning); _globalInfo.StepRunningDic.Add(TestStatus, _stepRunning);
_globalInfo.ScopeDic.Add(TestStatus, _scope); _globalInfo.ScopeDic.Add(TestStatus, _scope);
_systemConfig = _scope.Resolve<SystemConfig>();
if (ConfigService.IsExit(TestStatus))
{
string filePath = System.IO.Path.Combine(_systemConfig.SystemPath, $"{TestStatus}.json");
if (System.IO.File.Exists(filePath))
{
string json = System.IO.File.ReadAllText(filePath);
// 🔥 关键:把 json 数据直接灌入当前实例,对象引用没有任何改变
Newtonsoft.Json.JsonConvert.PopulateObject(json, _systemConfig);
}
}
} }
} }

View File

@@ -79,7 +79,8 @@ namespace MainModule.ViewModels
region.Remove(myView); region.Remove(myView);
} }
}, parameters); }, parameters);
_moduleManager.LoadModule("MonitorModule");
_moduleManager.LoadModule("SettingModule");
return; return;
} }
} }

View File

@@ -4,6 +4,7 @@ using System.Reflection;
namespace MonitorModule namespace MonitorModule
{ {
[Module(OnDemand = true)]
public class MonitorModule: IModule public class MonitorModule: IModule
{ {
public void OnInitialized(IContainerProvider containerProvider) public void OnInitialized(IContainerProvider containerProvider)

View File

@@ -301,7 +301,7 @@ namespace MonitorModule.ViewModels
Plot.Title = $"监控 - {TestStatus}"; Plot.Title = $"监控 - {TestStatus}";
Plot.InvalidatePlot(false); Plot.InvalidatePlot(false);
_scope = _globalInfo.ScopeDic[TestStatus]; _scope = _globalInfo.ScopeDic[TestStatus];
_scopedContext = _globalInfo.ContextDic[TestStatus]; _scopedContext = _scope.Resolve<ScopedContext>();
IsInitiated = true; IsInitiated = true;
} }
} }

View File

@@ -345,7 +345,7 @@ namespace MonitorModule.ViewModels
{ {
TestStatus = navigationContext.Parameters.GetValue<string>("Name"); TestStatus = navigationContext.Parameters.GetValue<string>("Name");
_scope = _globalInfo.ScopeDic[TestStatus]; _scope = _globalInfo.ScopeDic[TestStatus];
_scopedContext = _globalInfo.ContextDic[TestStatus]; _scopedContext = _scope.Resolve<ScopedContext>();
IsInitiated = true; IsInitiated = true;
} }
LoadTables(); LoadTables();

View File

@@ -4,6 +4,7 @@ using System.Reflection;
namespace SettingModule namespace SettingModule
{ {
[Module(OnDemand = true)]
public class SettingModule : IModule public class SettingModule : IModule
{ {
public void OnInitialized(IContainerProvider containerProvider) public void OnInitialized(IContainerProvider containerProvider)

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Windows.Input; using System.Windows.Input;
using Prism.Commands; using Prism.Commands;
@@ -48,7 +49,7 @@ namespace SettingModule.ViewModels
public ObservableCollection<string> ConnectionTypes { get; } = new() public ObservableCollection<string> ConnectionTypes { get; } = new()
{ {
"None", "TCP", "Serial" "None", "Tcp", "Serial"
}; };
#endregion #endregion
@@ -72,7 +73,6 @@ namespace SettingModule.ViewModels
public SettingViewModel(IContainerExtension container) : base(container) public SettingViewModel(IContainerExtension container) : base(container)
{ {
_globalInfo = container.Resolve<GlobalInfo>(); _globalInfo = container.Resolve<GlobalInfo>();
RefreshCommand = new DelegateCommand(OnExpand); RefreshCommand = new DelegateCommand(OnExpand);
SaveCommand = new DelegateCommand(OnSave); SaveCommand = new DelegateCommand(OnSave);
ResetCommand = new DelegateCommand(OnReset); ResetCommand = new DelegateCommand(OnReset);
@@ -107,15 +107,23 @@ namespace SettingModule.ViewModels
_eventAggregator.GetEvent<ExpandViewEvent>().Publish(TestStatus); _eventAggregator.GetEvent<ExpandViewEvent>().Publish(TestStatus);
} }
/// <summary>保存当前选中设备的配置(占位,实际写盘逻辑后续接入)。</summary> /// <summary>保存当前 SystemConfig 到 SystemPath 下,文件名为 {Title}.json。</summary>
private void OnSave() private void OnSave()
{ {
if (SelectedDevice == null) if (_systemConfig == null)
{ {
StatusMessage = "无可保存的设备"; StatusMessage = "无可保存的配置";
return; return;
} }
StatusMessage = $"已保存设备 [{SelectedDevice.DeviceName}] 的配置({DateTime.Now:HH:mm:ss}";
if (string.IsNullOrWhiteSpace(_systemConfig.Title))
{
StatusMessage = "保存失败标题Title不能为空";
return;
}
ConfigService.Save(_systemConfig);
StatusMessage = $"已保存配置 [{_systemConfig.Title}.json] 至 {_systemConfig.SystemPath}{DateTime.Now:HH:mm:ss}";
} }
/// <summary>重置当前选中设备的配置(占位)。</summary> /// <summary>重置当前选中设备的配置(占位)。</summary>
@@ -142,7 +150,7 @@ namespace SettingModule.ViewModels
var dialogName = SelectedDevice.ConnectionType switch var dialogName = SelectedDevice.ConnectionType switch
{ {
"TCP" => "TCPConfig", "Tcp" => "TCPConfig",
"Serial" => "SerialPortConfig", "Serial" => "SerialPortConfig",
_ => string.Empty _ => string.Empty
}; };
@@ -153,7 +161,6 @@ namespace SettingModule.ViewModels
return; return;
} }
// 【关键修改】在此处将选中的设备以及隔离作用域内的 _systemConfig 一并传进弹窗
var p = new DialogParameters var p = new DialogParameters
{ {
{ "Device", SelectedDevice }, { "Device", SelectedDevice },
@@ -180,12 +187,11 @@ namespace SettingModule.ViewModels
_scope = _globalInfo.ScopeDic[TestStatus]; _scope = _globalInfo.ScopeDic[TestStatus];
_scopedContext = _globalInfo.ContextDic[TestStatus]; _scopedContext = _globalInfo.ContextDic[TestStatus];
_systemConfig = _scope.Resolve<SystemConfig>(); _systemConfig = _scope.Resolve<SystemConfig>();
DeviceList = _systemConfig.DeviceList;
if (DeviceList != null && DeviceList.Count > 0) if (DeviceList != null && DeviceList.Count > 0)
{ {
SelectedDevice = DeviceList[0]; SelectedDevice = DeviceList[0];
} }
DeviceList = _systemConfig.DeviceList;
IsInitiated = true; IsInitiated = true;
} }
} }

View File

@@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SettingModule.Views.Dialogs" xmlns:local="clr-namespace:SettingModule.Views.Dialogs"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:helpers="clr-namespace:UIShare.Helpers;assembly=UIShare" xmlns:helpers="clr-namespace:UIShare.Helpers;assembly=UIShare"
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare" xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
mc:Ignorable="d" mc:Ignorable="d"
@@ -14,20 +15,29 @@
Width="440" Width="440"
Height="430"> Height="430">
<prism:Dialog.WindowStyle> <prism:Dialog.WindowStyle>
<Style TargetType="Window"> <Style BasedOn="{StaticResource DialogUserManageStyle}"
<Setter Property="ResizeMode" Value="NoResize"/> TargetType="Window" />
<Setter Property="SizeToContent" Value="WidthAndHeight"/>
</Style>
</prism:Dialog.WindowStyle> </prism:Dialog.WindowStyle>
<UserControl.Resources> <UserControl.Resources>
<converters:StringToVisibilityConverter x:Key="StringToVisibility"/> <converters:StringToVisibilityConverter x:Key="StringToVisibility"/>
</UserControl.Resources> </UserControl.Resources>
<GroupBox Padding="12,8,12,8" <GroupBox Padding="12,8,12,8" materialDesign:HintAssist.Hint=""
Header="{Binding Title}"
helpers:WindowDragHelper.EnableWindowDrag="True"> helpers:WindowDragHelper.EnableWindowDrag="True">
<GroupBox.Header>
<Grid Margin="0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="*" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Title}"
Foreground="White"
VerticalAlignment="Center"
Margin="5,0,10,0" />
</Grid>
</GroupBox.Header>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
@@ -56,6 +66,7 @@
Text="串口名称:" Text="串口名称:"
VerticalAlignment="Center" Margin="0,6"/> VerticalAlignment="Center" Margin="0,6"/>
<ComboBox Grid.Row="0" Grid.Column="1" Margin="0,6" <ComboBox Grid.Row="0" Grid.Column="1" Margin="0,6"
materialDesign:HintAssist.Hint=""
IsEditable="True" IsEditable="True"
ItemsSource="{Binding AvailablePorts}" ItemsSource="{Binding AvailablePorts}"
Text="{Binding Config.PortName, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding Config.PortName, UpdateSourceTrigger=PropertyChanged}"/>
@@ -68,6 +79,7 @@
VerticalAlignment="Center" Margin="0,6"/> VerticalAlignment="Center" Margin="0,6"/>
<ComboBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6" <ComboBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6"
IsEditable="True" IsEditable="True"
materialDesign:HintAssist.Hint=""
ItemsSource="{Binding CommonBaudRates}" ItemsSource="{Binding CommonBaudRates}"
Text="{Binding Config.BaudRate, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding Config.BaudRate, UpdateSourceTrigger=PropertyChanged}"/>
@@ -76,6 +88,7 @@
VerticalAlignment="Center" Margin="0,6"/> VerticalAlignment="Center" Margin="0,6"/>
<ComboBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6" <ComboBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6"
ItemsSource="{Binding DataBitsList}" ItemsSource="{Binding DataBitsList}"
materialDesign:HintAssist.Hint=""
SelectedItem="{Binding Config.DataBits}"/> SelectedItem="{Binding Config.DataBits}"/>
<TextBlock Grid.Row="3" Grid.Column="0" <TextBlock Grid.Row="3" Grid.Column="0"
@@ -83,6 +96,7 @@
VerticalAlignment="Center" Margin="0,6"/> VerticalAlignment="Center" Margin="0,6"/>
<ComboBox Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6" <ComboBox Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6"
ItemsSource="{Binding StopBitsList}" ItemsSource="{Binding StopBitsList}"
materialDesign:HintAssist.Hint=""
SelectedItem="{Binding Config.StopBits}"/> SelectedItem="{Binding Config.StopBits}"/>
<TextBlock Grid.Row="4" Grid.Column="0" <TextBlock Grid.Row="4" Grid.Column="0"
@@ -90,6 +104,7 @@
VerticalAlignment="Center" Margin="0,6"/> VerticalAlignment="Center" Margin="0,6"/>
<ComboBox Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6" <ComboBox Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6"
ItemsSource="{Binding ParityList}" ItemsSource="{Binding ParityList}"
materialDesign:HintAssist.Hint=""
SelectedItem="{Binding Config.Parity}"/> SelectedItem="{Binding Config.Parity}"/>
<TextBlock Grid.Row="5" Grid.Column="0" <TextBlock Grid.Row="5" Grid.Column="0"
@@ -97,6 +112,7 @@
VerticalAlignment="Center" Margin="0,6"/> VerticalAlignment="Center" Margin="0,6"/>
<ComboBox Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6" <ComboBox Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6"
IsEditable="True" IsEditable="True"
materialDesign:HintAssist.Hint=""
ItemsSource="{Binding CommonTimeouts}" ItemsSource="{Binding CommonTimeouts}"
Text="{Binding Config.ReadTimeout, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding Config.ReadTimeout, UpdateSourceTrigger=PropertyChanged}"/>
@@ -105,6 +121,7 @@
VerticalAlignment="Center" Margin="0,6"/> VerticalAlignment="Center" Margin="0,6"/>
<ComboBox Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6" <ComboBox Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,6"
IsEditable="True" IsEditable="True"
materialDesign:HintAssist.Hint=""
ItemsSource="{Binding CommonTimeouts}" ItemsSource="{Binding CommonTimeouts}"
Text="{Binding Config.WriteTimeout, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding Config.WriteTimeout, UpdateSourceTrigger=PropertyChanged}"/>
</Grid> </Grid>

View File

@@ -1,6 +1,7 @@
<UserControl x:Class="SettingModule.Views.Dialogs.TCPConfigView" <UserControl x:Class="SettingModule.Views.Dialogs.TCPConfigView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SettingModule.Views.Dialogs" xmlns:local="clr-namespace:SettingModule.Views.Dialogs"
@@ -14,10 +15,8 @@
Width="420" Width="420"
Height="320"> Height="320">
<prism:Dialog.WindowStyle> <prism:Dialog.WindowStyle>
<Style TargetType="Window"> <Style BasedOn="{StaticResource DialogUserManageStyle}"
<Setter Property="ResizeMode" Value="NoResize"/> TargetType="Window" />
<Setter Property="SizeToContent" Value="WidthAndHeight"/>
</Style>
</prism:Dialog.WindowStyle> </prism:Dialog.WindowStyle>
<UserControl.Resources> <UserControl.Resources>
@@ -25,8 +24,20 @@
</UserControl.Resources> </UserControl.Resources>
<GroupBox Padding="12,8,12,8" <GroupBox Padding="12,8,12,8"
Header="{Binding Title}"
helpers:WindowDragHelper.EnableWindowDrag="True"> helpers:WindowDragHelper.EnableWindowDrag="True">
<GroupBox.Header>
<Grid Margin="0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="*" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Title}"
Foreground="White"
VerticalAlignment="Center"
Margin="5,0,10,0" />
</Grid>
</GroupBox.Header>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
@@ -51,6 +62,7 @@
Text="IP 地址:" Text="IP 地址:"
VerticalAlignment="Center" Margin="0,6"/> VerticalAlignment="Center" Margin="0,6"/>
<TextBox Grid.Row="0" Grid.Column="1" Margin="0,6" <TextBox Grid.Row="0" Grid.Column="1" Margin="0,6"
materialDesign:HintAssist.Hint=""
Text="{Binding Config.IPAddress, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding Config.IPAddress, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Grid.Row="1" Grid.Column="0" <TextBlock Grid.Row="1" Grid.Column="0"
@@ -58,6 +70,7 @@
VerticalAlignment="Center" Margin="0,6"/> VerticalAlignment="Center" Margin="0,6"/>
<ComboBox Grid.Row="1" Grid.Column="1" Margin="0,6" <ComboBox Grid.Row="1" Grid.Column="1" Margin="0,6"
IsEditable="True" IsEditable="True"
materialDesign:HintAssist.Hint=""
ItemsSource="{Binding CommonPorts}" ItemsSource="{Binding CommonPorts}"
Text="{Binding Config.Port, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding Config.Port, UpdateSourceTrigger=PropertyChanged}"/>
@@ -66,6 +79,7 @@
VerticalAlignment="Center" Margin="0,6"/> VerticalAlignment="Center" Margin="0,6"/>
<ComboBox Grid.Row="2" Grid.Column="1" Margin="0,6" <ComboBox Grid.Row="2" Grid.Column="1" Margin="0,6"
IsEditable="True" IsEditable="True"
materialDesign:HintAssist.Hint=""
ItemsSource="{Binding CommonTimeouts}" ItemsSource="{Binding CommonTimeouts}"
Text="{Binding Config.SendTimeout, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding Config.SendTimeout, UpdateSourceTrigger=PropertyChanged}"/>
@@ -74,6 +88,7 @@
VerticalAlignment="Center" Margin="0,6"/> VerticalAlignment="Center" Margin="0,6"/>
<ComboBox Grid.Row="3" Grid.Column="1" Margin="0,6" <ComboBox Grid.Row="3" Grid.Column="1" Margin="0,6"
IsEditable="True" IsEditable="True"
materialDesign:HintAssist.Hint=""
ItemsSource="{Binding CommonTimeouts}" ItemsSource="{Binding CommonTimeouts}"
Text="{Binding Config.ReceiveTimeout, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding Config.ReceiveTimeout, UpdateSourceTrigger=PropertyChanged}"/>
</Grid> </Grid>

View File

@@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/" xmlns:prism="http://prismlibrary.com/"
xmlns:b="clr-namespace:UIShare.Behaviors;assembly=UIShare" xmlns:b="clr-namespace:UIShare.Behaviors;assembly=UIShare"
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare" xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
@@ -235,19 +236,19 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="设备名称:" VerticalAlignment="Center" Margin="0,4"/> <TextBlock Grid.Row="0" Grid.Column="0" Text="设备名称:" VerticalAlignment="Center" Margin="0,4"/>
<TextBox Grid.Row="0" Grid.Column="1" Margin="0,4" <TextBox materialDesign:HintAssist.Hint="" Grid.Row="0" Grid.Column="1" Margin="0,4"
Text="{Binding SelectedDevice.DeviceName, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding SelectedDevice.DeviceName, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="设备类型:" VerticalAlignment="Center" Margin="0,4"/> <TextBlock Grid.Row="1" Grid.Column="0" Text="设备类型:" VerticalAlignment="Center" Margin="0,4"/>
<TextBox Grid.Row="1" Grid.Column="1" Margin="0,4" <TextBox materialDesign:HintAssist.Hint="" Grid.Row="1" Grid.Column="1" Margin="0,4"
Text="{Binding SelectedDevice.DeviceType, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding SelectedDevice.DeviceType, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="备注说明:" VerticalAlignment="Center" Margin="0,4"/> <TextBlock Grid.Row="2" Grid.Column="0" Text="备注说明:" VerticalAlignment="Center" Margin="0,4"/>
<TextBox Grid.Row="2" Grid.Column="1" Margin="0,4" <TextBox materialDesign:HintAssist.Hint="" Grid.Row="2" Grid.Column="1" Margin="0,4"
Text="{Binding SelectedDevice.Remark, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding SelectedDevice.Remark, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="启用状态:" VerticalAlignment="Center" Margin="0,4"/> <TextBlock Grid.Row="3" Grid.Column="0" Text="启用状态:" VerticalAlignment="Center" Margin="0,4"/>
<CheckBox Grid.Row="3" Grid.Column="1" Margin="0,6" <CheckBox materialDesign:HintAssist.Hint="" Grid.Row="3" Grid.Column="1" Margin="0,6"
VerticalAlignment="Center" VerticalAlignment="Center"
IsChecked="{Binding SelectedDevice.IsEnabled}" IsChecked="{Binding SelectedDevice.IsEnabled}"
Content="启用此设备"/> Content="启用此设备"/>
@@ -306,7 +307,7 @@
Text="连接方式:" Text="连接方式:"
VerticalAlignment="Center" VerticalAlignment="Center"
Margin="0,4"/> Margin="0,4"/>
<ComboBox Grid.Row="0" Grid.Column="1" <ComboBox materialDesign:HintAssist.Hint="" Grid.Row="0" Grid.Column="1"
Margin="0,4" Margin="0,4"
ItemsSource="{Binding ConnectionTypes}" ItemsSource="{Binding ConnectionTypes}"
SelectedItem="{Binding SelectedDevice.ConnectionType}"/> SelectedItem="{Binding SelectedDevice.ConnectionType}"/>
@@ -437,17 +438,9 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="标题:" VerticalAlignment="Center" Margin="0,4"/>
<TextBox Grid.Row="0" Grid.Column="1" Margin="0,4"
Text="{Binding SystemConfig.Title, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="TSMaster 名称:" VerticalAlignment="Center" Margin="0,4"/>
<TextBox Grid.Row="1" Grid.Column="1" Margin="0,4"
Text="{Binding SystemConfig.TSMasterName, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="性能等级:" VerticalAlignment="Center" Margin="0,4"/> <TextBlock Grid.Row="2" Grid.Column="0" Text="性能等级:" VerticalAlignment="Center" Margin="0,4"/>
<Grid Grid.Row="2" Grid.Column="1" Margin="0,4"> <Grid Grid.Row="2" Grid.Column="1" Margin="0,4">
@@ -490,23 +483,23 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="DLL 路径:" VerticalAlignment="Center" Margin="0,4"/> <TextBlock Grid.Row="0" Grid.Column="0" Text="DLL 路径:" VerticalAlignment="Center" Margin="0,4"/>
<TextBox Grid.Row="0" Grid.Column="1" Margin="0,4" <TextBox materialDesign:HintAssist.Hint="" Grid.Row="0" Grid.Column="1" Margin="0,4"
Text="{Binding SystemConfig.DLLFilePath, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding SystemConfig.DLLFilePath, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="子程序路径:" VerticalAlignment="Center" Margin="0,4"/> <TextBlock Grid.Row="1" Grid.Column="0" Text="子程序路径:" VerticalAlignment="Center" Margin="0,4"/>
<TextBox Grid.Row="1" Grid.Column="1" Margin="0,4" <TextBox materialDesign:HintAssist.Hint="" Grid.Row="1" Grid.Column="1" Margin="0,4"
Text="{Binding SystemConfig.SubProgramFilePath, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding SystemConfig.SubProgramFilePath, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="默认程序文件:" VerticalAlignment="Center" Margin="0,4"/> <TextBlock Grid.Row="2" Grid.Column="0" Text="默认程序文件:" VerticalAlignment="Center" Margin="0,4"/>
<TextBox Grid.Row="2" Grid.Column="1" Margin="0,4" <TextBox materialDesign:HintAssist.Hint="" Grid.Row="2" Grid.Column="1" Margin="0,4"
Text="{Binding SystemConfig.DefaultProgramFilePath, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding SystemConfig.DefaultProgramFilePath, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="默认 BLF 文件:" VerticalAlignment="Center" Margin="0,4"/> <TextBlock Grid.Row="3" Grid.Column="0" Text="默认 BLF 文件:" VerticalAlignment="Center" Margin="0,4"/>
<TextBox Grid.Row="3" Grid.Column="1" Margin="0,4" <TextBox materialDesign:HintAssist.Hint="" Grid.Row="3" Grid.Column="1" Margin="0,4"
Text="{Binding SystemConfig.DefaultBLFFilePath, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding SystemConfig.DefaultBLFFilePath, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Grid.Row="4" Grid.Column="0" Text="默认 DBC 文件:" VerticalAlignment="Center" Margin="0,4"/> <TextBlock Grid.Row="4" Grid.Column="0" Text="默认 DBC 文件:" VerticalAlignment="Center" Margin="0,4"/>
<TextBox Grid.Row="4" Grid.Column="1" Margin="0,4" <TextBox materialDesign:HintAssist.Hint="" Grid.Row="4" Grid.Column="1" Margin="0,4"
Text="{Binding SystemConfig.DefaultDBCFilePath, UpdateSourceTrigger=PropertyChanged}"/> Text="{Binding SystemConfig.DefaultDBCFilePath, UpdateSourceTrigger=PropertyChanged}"/>
</Grid> </Grid>
</StackPanel> </StackPanel>
@@ -518,13 +511,25 @@
<StackPanel> <StackPanel>
<TextBlock Text="只读信息" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/> <TextBlock Text="只读信息" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
<Grid> <Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="140"/> <ColumnDefinition Width="140"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="系统数据目录" VerticalAlignment="Center"/> <TextBlock Grid.Row="0" Grid.Column="0" Text="标题" VerticalAlignment="Center" />
<TextBlock Grid.Column="1" <TextBlock Grid.Row="0" Grid.Column="1" Margin="0,4" Foreground="#555"
Text="{Binding SystemConfig.SystemPath}" Text="{Binding SystemConfig.Title}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="TSMaster 名称:" VerticalAlignment="Center" Margin="0,4"/>
<TextBlock Grid.Row="1" Grid.Column="1" Margin="0,4" Foreground="#555"
Text="{Binding SystemConfig.TSMasterName}"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="系统数据目录:" VerticalAlignment="Center"/>
<TextBlock Grid.Column="1" Grid.Row="2"
Text="{Binding SystemConfig.SystemPath}" Margin="0,4"
Foreground="#555" Foreground="#555"
TextWrapping="Wrap"/> TextWrapping="Wrap"/>
</Grid> </Grid>

View File

@@ -8,7 +8,26 @@ namespace UIShare.GlobalVariable
public static class ConfigService public static class ConfigService
{ {
private static readonly object _fileLock = new(); private static readonly object _fileLock = new();
/// <summary>
/// 根据标题查询配置文件是否存在
/// </summary>
public static bool IsExit(string title)
{
if (string.IsNullOrEmpty(title))
{
return false;
}
// 临时实例化一个对象以获取默认的 SystemPath
var dummy = new SystemConfig();
string configPath = Path.Combine(dummy.SystemPath, $"{title}.json");
if (!File.Exists(configPath))
{
return false;
}
return true;
}
/// <summary> /// <summary>
/// 根据标题(格子标识)加载独立的配置文件 /// 根据标题(格子标识)加载独立的配置文件
/// </summary> /// </summary>

View File

@@ -1,4 +1,5 @@
using MaterialDesignThemes.Wpf; using DeviceCommand.Base;
using MaterialDesignThemes.Wpf;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@@ -27,6 +28,8 @@ namespace UIShare.GlobalVariable
public PackIconKind RunIcon { get; set; } = PackIconKind.Play; public PackIconKind RunIcon { get; set; } = PackIconKind.Play;
public StepModel SelectedStep { get; set; } public StepModel SelectedStep { get; set; }
public ParameterModel SelectedParameter { get; set; } public ParameterModel SelectedParameter { get; set; }
public List<IBaseInterface> DeviceList { get; set; } = new();
// 【新增测试属性】:每个实例被 new 出来时独一无二的随机身份 // 【新增测试属性】:每个实例被 new 出来时独一无二的随机身份
// 证 ID // 证 ID
public int DebugRandomId { get; private set; } public int DebugRandomId { get; private set; }

View File

@@ -26,14 +26,68 @@ namespace UIShare.GlobalVariable
public string DefaultProgramFilePath { get; set; } = ""; public string DefaultProgramFilePath { get; set; } = "";
public string DefaultBLFFilePath { get; set; } = ""; public string DefaultBLFFilePath { get; set; } = "";
public string DefaultDBCFilePath { get; set; } = ""; public string DefaultDBCFilePath { get; set; } = "";
public ObservableCollection<DeviceInfoModel> DeviceList = new();
// public ObservableCollection<DeviceInfoModel> DeviceList { get; set; } = new()
//{
// new DeviceInfoModel
// {
// DeviceName = "IT7800E",
// DeviceType = "IT7800E",
// Remark = "交流可编程电源供应器",
// ConnectionType = "Tcp",
// IsEnabled = true,
// IsConnected = false
// },
public ObservableCollection<DeviceInfoModel> DeviceList { get; set; } = new() // new DeviceInfoModel
{ // {
new DeviceInfoModel { DeviceName = "DAQ_001", DeviceType = "数据采集卡", Remark = "8 通道电压采集", IsEnabled = true, IsConnected = false }, // DeviceName = "N36200",
new DeviceInfoModel { DeviceName = "PSU_002", DeviceType = "可编程电源", Remark = "0-30V / 0-5A", IsEnabled = true, IsConnected = false }, // DeviceType = "N36200",
new DeviceInfoModel { DeviceName = "CAN_003", DeviceType = "CAN 通讯卡", Remark = "双通道 CAN-FD", IsEnabled = false, IsConnected = false }, // Remark = "宽范围可编程直流电源",
new DeviceInfoModel { DeviceName = "IO_004", DeviceType = "数字 I/O", Remark = "16 进 16 出", IsEnabled = true, IsConnected = false }, // ConnectionType = "Tcp",
new DeviceInfoModel { DeviceName = "Serial_005", DeviceType = "串口", Remark = "RS232 / RS485", IsEnabled = true, IsConnected = false }, // IsEnabled = true,
}; // IsConnected = false
// },
// new DeviceInfoModel
// {
// DeviceName = "N36600",
// DeviceType = "N36600",
// Remark = "便携式宽范围可编程直流电源",
// ConnectionType = "Tcp",
// IsEnabled = false,
// IsConnected = false
// },
// new DeviceInfoModel
// {
// DeviceName = "N69200",
// DeviceType = "N69200",
// Remark = "可编程直流电子负载",
// ConnectionType = "Tcp",
// IsEnabled = true,
// IsConnected = false
// },
// new DeviceInfoModel
// {
// DeviceName = "SDS2000X_HD",
// DeviceType = "SDS2000X_HD",
// Remark = "数字存储示波器",
// ConnectionType = "Tcp",
// IsEnabled = true,
// IsConnected = false
// },
// new DeviceInfoModel
// {
// DeviceName = "SPAW7000",
// DeviceType = "SPAW7000",
// Remark = "功率分析记录仪",
// ConnectionType = "Tcp",
// IsEnabled = true,
// IsConnected = false
// }
//};
} }
} }

View File

@@ -18,6 +18,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" /> <ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\DeviceCommand\DeviceCommand.csproj" />
<ProjectReference Include="..\Logger\Logger.csproj" /> <ProjectReference Include="..\Logger\Logger.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -14,6 +14,7 @@ namespace UIShare.ViewModelBase
public IEventAggregator _eventAggregator; public IEventAggregator _eventAggregator;
public IDialogService _dialogService; public IDialogService _dialogService;
public IRegionManager _regionManager; public IRegionManager _regionManager;
public IModuleManager _moduleManager;
private INotificationManager _notificationManager; private INotificationManager _notificationManager;
private GlobalInfo _globalInfo; private GlobalInfo _globalInfo;
public NavigateViewModelBase(IContainerProvider containerProvider) public NavigateViewModelBase(IContainerProvider containerProvider)
@@ -21,6 +22,7 @@ namespace UIShare.ViewModelBase
_globalInfo=containerProvider.Resolve<GlobalInfo>(); _globalInfo=containerProvider.Resolve<GlobalInfo>();
_eventAggregator = containerProvider.Resolve<IEventAggregator>(); _eventAggregator = containerProvider.Resolve<IEventAggregator>();
_dialogService = containerProvider.Resolve<IDialogService>(); _dialogService = containerProvider.Resolve<IDialogService>();
_moduleManager = containerProvider.Resolve<IModuleManager>();
_regionManager = containerProvider.Resolve<IRegionManager>(); _regionManager = containerProvider.Resolve<IRegionManager>();
_notificationManager = containerProvider.Resolve<INotificationManager>(); _notificationManager = containerProvider.Resolve<INotificationManager>();
} }