fix: 使用 CommunityToolkit.Mvvm

This commit is contained in:
Shiqvlizi Name
2026-05-28 23:26:37 +08:00
parent 47572fefb8
commit ef61ae7e6b
12 changed files with 310 additions and 512 deletions

View File

@@ -1,4 +1,4 @@
using CloudPrint.Client.Infrastructure;
using CommunityToolkit.Mvvm.ComponentModel;
namespace CloudPrint.Client.Models;
@@ -11,13 +11,22 @@ public enum PrintJobStatus
Cancelled
}
public sealed class PrintJob : ObservableObject
public sealed partial class PrintJob : ObservableObject
{
private PrintJobStatus _status = PrintJobStatus.Pending;
private int _progress;
private string _errorMessage = string.Empty;
private int? _windowsJobId;
private string _windowsJobStatus = string.Empty;
[ObservableProperty]
private int? windowsJobId;
[ObservableProperty]
private string windowsJobStatus = string.Empty;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(StatusText))]
private PrintJobStatus status = PrintJobStatus.Pending;
[ObservableProperty]
private string errorMessage = string.Empty;
private int progress;
public int Id { get; init; }
public string JobNo { get; init; } = string.Empty;
@@ -34,40 +43,10 @@ public sealed class PrintJob : ObservableObject
public DateTime? StartedAt { get; set; }
public DateTime? CompletedAt { get; set; }
public int? WindowsJobId
{
get => _windowsJobId;
set => SetProperty(ref _windowsJobId, value);
}
public string WindowsJobStatus
{
get => _windowsJobStatus;
set => SetProperty(ref _windowsJobStatus, value);
}
public PrintJobStatus Status
{
get => _status;
set
{
if (SetProperty(ref _status, value))
{
OnPropertyChanged(nameof(StatusText));
}
}
}
public int Progress
{
get => _progress;
set => SetProperty(ref _progress, Math.Clamp(value, 0, 100));
}
public string ErrorMessage
{
get => _errorMessage;
set => SetProperty(ref _errorMessage, value);
get => progress;
set => SetProperty(ref progress, Math.Clamp(value, 0, 100));
}
public string StatusText => Status switch
@@ -107,4 +86,4 @@ public sealed class PrintJob : ObservableObject
Status = PrintJobStatus.Cancelled;
CompletedAt = DateTime.Now;
}
}
}