2026-01-23 10:13:53 +08:00

81 lines
2.0 KiB
C#

using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace NFCLockDemoV2.ViewModels;
public class MainViewModel : ObservableObject
{
private ViewModels.OperationType? _operation;
public ViewModels.OperationType? Operation
{
get => _operation;
set => SetProperty(ref _operation, value);
}
private int _arcProgress;
public int ArcProgress
{
get => _arcProgress;
set => SetProperty(ref _arcProgress, value);
}
private string _deviceId = "--";
public string DeviceId
{
get => _deviceId;
set => SetProperty(ref _deviceId, value);
}
private string _deviceStatus = "";
public string DeviceStatus
{
get => _deviceStatus;
set => SetProperty(ref _deviceStatus, value);
}
private string _deviceRssi = "--";
public string DeviceRssi
{
get => _deviceRssi;
set => SetProperty(ref _deviceRssi, value);
}
private string _password = "123456";
public string Password
{
get => _password;
set => SetProperty(ref _password, value);
}
public ICommand ControlCommand { get; set; }
public void UpdateMessage(string message)
{
DeviceStatus = message;
}
public MainViewModel()
{
ControlCommand = new AsyncRelayCommand<string>(val =>
{
switch (val)
{
case "Lock":
Operation = ViewModels.OperationType.LOCK;
break;
case "Unlock":
Operation = ViewModels.OperationType.UNLOCK;
break;
case "SetPassword":
Operation = ViewModels.OperationType.SET_PASSWORD;
break;
default:
Operation = null;
break;
}
return Task.CompletedTask;
});
}
}