记录界面
This commit is contained in:
148
SettingModule/ViewModels/SettingViewModel.cs
Normal file
148
SettingModule/ViewModels/SettingViewModel.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using UIShare.GlobalVariable;
|
||||
using UIShare.PubEvent;
|
||||
using UIShare.UIViewModel;
|
||||
using UIShare.ViewModelBase;
|
||||
|
||||
namespace SettingModule.ViewModels
|
||||
{
|
||||
|
||||
public class SettingViewModel : NavigateViewModelBase, IRegionMemberLifetime, IDisposable
|
||||
{
|
||||
#region 私有字段
|
||||
private readonly IScopedProvider _scope;
|
||||
private readonly SystemConfig _systemConfig;
|
||||
#endregion
|
||||
|
||||
#region 隔离 / 标题
|
||||
public bool KeepAlive => true;
|
||||
public ScopedContext _scopedContext { get; }
|
||||
// 公开一份 GlobalInfo 供双击展开使用(基类 _globalInfo 是 private)
|
||||
public GlobalInfo GlobalInfoRef { get; }
|
||||
|
||||
private string _testStatus = string.Empty;
|
||||
public string TestStatus
|
||||
{
|
||||
get => _testStatus;
|
||||
set => SetProperty(ref _testStatus, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 设备列表 / 选中设备
|
||||
/// <summary>左侧设备列表,直接绑定 SystemConfig.DeviceList</summary>
|
||||
public ObservableCollection<DeviceInfoModel> DeviceList { get; }
|
||||
|
||||
private DeviceInfoModel? _selectedDevice;
|
||||
public DeviceInfoModel? SelectedDevice
|
||||
{
|
||||
get => _selectedDevice;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _selectedDevice, value))
|
||||
{
|
||||
OnSelectedDeviceChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _statusMessage = "请在左侧选择设备查看 / 编辑配置";
|
||||
public string StatusMessage
|
||||
{
|
||||
get => _statusMessage;
|
||||
set => SetProperty(ref _statusMessage, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 命令
|
||||
// 双击展开 / 折叠九宫格(与 MonitorView/RecordView 共用同一套 ExpandViewEvent)
|
||||
public ICommand RefreshCommand { get; }
|
||||
public ICommand SaveCommand { get; }
|
||||
public ICommand ResetCommand { get; }
|
||||
#endregion
|
||||
|
||||
public SettingViewModel(IContainerExtension container) : base(container)
|
||||
{
|
||||
_scope = container.CreateScope();
|
||||
GlobalInfoRef = container.Resolve<GlobalInfo>();
|
||||
_scopedContext = _scope.Resolve<ScopedContext>();
|
||||
_systemConfig = _scope.Resolve<SystemConfig>();
|
||||
|
||||
// 直接复用 SystemConfig 的 DeviceList,外部修改可同步反映
|
||||
DeviceList = _systemConfig.DeviceList;
|
||||
|
||||
RefreshCommand = new DelegateCommand(OnExpand);
|
||||
SaveCommand = new DelegateCommand(OnSave);
|
||||
ResetCommand = new DelegateCommand(OnReset);
|
||||
|
||||
// 进来默认选中第一个,让右侧不为空
|
||||
if (DeviceList.Count > 0)
|
||||
{
|
||||
SelectedDevice = DeviceList[0];
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_scope?.Dispose();
|
||||
}
|
||||
|
||||
#region 命令处理
|
||||
/// <summary>
|
||||
/// 选中设备切换:右侧配置面板靠 SelectedDevice 绑定自动刷新,
|
||||
/// 这里只负责更新状态栏提示。
|
||||
/// </summary>
|
||||
private void OnSelectedDeviceChanged()
|
||||
{
|
||||
if (SelectedDevice == null)
|
||||
{
|
||||
StatusMessage = "未选中设备";
|
||||
return;
|
||||
}
|
||||
StatusMessage = $"当前配置:{SelectedDevice.DeviceName}({SelectedDevice.DeviceType})";
|
||||
}
|
||||
|
||||
/// <summary>双击展开 / 折叠九宫格。</summary>
|
||||
private void OnExpand()
|
||||
{
|
||||
if (string.IsNullOrEmpty(TestStatus)) return;
|
||||
_eventAggregator.GetEvent<ExpandViewEvent>().Publish(TestStatus);
|
||||
GlobalInfoRef.CurrentScope = TestStatus;
|
||||
}
|
||||
|
||||
/// <summary>保存当前选中设备的配置(占位,实际写盘逻辑后续接入)。</summary>
|
||||
private void OnSave()
|
||||
{
|
||||
if (SelectedDevice == null)
|
||||
{
|
||||
StatusMessage = "无可保存的设备";
|
||||
return;
|
||||
}
|
||||
StatusMessage = $"已保存设备 [{SelectedDevice.DeviceName}] 的配置({DateTime.Now:HH:mm:ss})";
|
||||
}
|
||||
|
||||
/// <summary>重置当前选中设备的配置(占位)。</summary>
|
||||
private void OnReset()
|
||||
{
|
||||
if (SelectedDevice == null)
|
||||
{
|
||||
StatusMessage = "无可重置的设备";
|
||||
return;
|
||||
}
|
||||
StatusMessage = $"已重置设备 [{SelectedDevice.DeviceName}] 的配置";
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 导航
|
||||
public override void OnNavigatedTo(NavigationContext navigationContext)
|
||||
{
|
||||
base.OnNavigatedTo(navigationContext);
|
||||
if (navigationContext.Parameters.ContainsKey("Name"))
|
||||
{
|
||||
TestStatus = navigationContext.Parameters.GetValue<string>("Name");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user