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); /// 各页面共享主窗口底部的最新状态。 public interface IStatusBarService { StatusBarMessage Current { get; } /// 发布一条状态。进度范围为 0 到 100,省略时隐藏进度条。 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)); } }