修改代码
This commit is contained in:
1 parent
f03e2b08f4
commit
3dcb6a1c34
24 files changed
+882
-480
No files matched your search
@@ -0,0 +1,44 @@
|
||||
using MAX.Common.WPF.Helpers;
|
||||
using MAX.Core.DependencyInjection;
|
||||
using Prism.Mvvm;
|
||||
|
||||
namespace Store.Management.Framework.Services;
|
||||
|
||||
public enum StatusLevel
|
||||
{
|
||||
Info,
|
||||
Success,
|
||||
Warning,
|
||||
Error
|
||||
}
|
||||
|
||||
public sealed record StatusBarMessage(string Text, StatusLevel Level, int? Progress);
|
||||
|
||||
/// <summary>各页面共享主窗口底部的最新状态。</summary>
|
||||
public interface IStatusBarService
|
||||
{
|
||||
StatusBarMessage Current { get; }
|
||||
|
||||
/// <summary>发布一条状态。进度范围为 0 到 100,省略时隐藏进度条。</summary>
|
||||
void Report(string text, StatusLevel level = StatusLevel.Info, int? progress = null);
|
||||
}
|
||||
|
||||
internal sealed class StatusBarService : BindableBase, IStatusBarService, ISingletonDependency
|
||||
{
|
||||
private StatusBarMessage _current = new("就绪", StatusLevel.Info, null);
|
||||
public StatusBarMessage Current
|
||||
{
|
||||
get => _current;
|
||||
private set => SetProperty(ref _current, value);
|
||||
}
|
||||
|
||||
public void Report(string text, StatusLevel level = StatusLevel.Info, int? progress = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(text);
|
||||
if (progress is < 0 or > 100)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(progress), "进度必须在 0 到 100 之间。");
|
||||
}
|
||||
DispatcherHelper.RunInDispatcher(() => Current = new StatusBarMessage(text, level, progress));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user