diff --git a/ACP/ViewModels/Dialogs/MessageBoxViewModel.cs b/ACP/ViewModels/Dialogs/MessageBoxViewModel.cs
index 19ce3a6..7114a69 100644
--- a/ACP/ViewModels/Dialogs/MessageBoxViewModel.cs
+++ b/ACP/ViewModels/Dialogs/MessageBoxViewModel.cs
@@ -1,7 +1,9 @@
using UIShare.PubEvent;
using UIShare.ViewModelBase;
+using System;
using System.Windows.Input;
using System.Windows.Media;
+using System.Windows.Threading;
namespace ACP.ViewModels.Dialogs
{
@@ -69,6 +71,11 @@ namespace ACP.ViewModels.Dialogs
public DialogCloseListener RequestClose { get; set; }
+ ///
+ /// 自动关闭定时器:自动关闭秒数大于 0 时启动,到时自动关闭弹窗(同时解除阻塞等待)
+ ///
+ private DispatcherTimer _autoCloseTimer;
+
public MessageBoxViewModel(IContainerProvider containerProvider):base(containerProvider)
{
YesCommand = new DelegateCommand(OnYes);
@@ -93,6 +100,7 @@ namespace ACP.ViewModels.Dialogs
public override void OnDialogClosed()
{
+ _autoCloseTimer?.Stop();
_eventAggregator.GetEvent().Publish(false);
}
@@ -117,6 +125,21 @@ namespace ACP.ViewModels.Dialogs
ShowNo = parameters.GetValue("ShowNo");
ShowOk = parameters.GetValue("ShowOk");
ShowCancel = parameters.GetValue("ShowCancel");
+
+ // 自动关闭:秒数大于 0 时启动定时器,到时自动关闭(供命令库 弹窗 命令的自动关闭参数使用)
+ if (parameters.TryGetValue("AutoCloseSeconds", out double autoCloseSeconds) && autoCloseSeconds > 0)
+ {
+ _autoCloseTimer = new DispatcherTimer
+ {
+ Interval = TimeSpan.FromSeconds(autoCloseSeconds)
+ };
+ _autoCloseTimer.Tick += (s, e) =>
+ {
+ _autoCloseTimer.Stop();
+ RequestClose.Invoke(new DialogResult(ButtonResult.OK));
+ };
+ _autoCloseTimer.Start();
+ }
}
#endregion
}
diff --git a/Command/CommandDialog.cs b/Command/CommandDialog.cs
new file mode 100644
index 0000000..a067303
--- /dev/null
+++ b/Command/CommandDialog.cs
@@ -0,0 +1,63 @@
+using Common.Attributes;
+using System;
+using System.ComponentModel;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Command
+{
+ ///
+ /// 对话框命令:在测试流程中弹出提示窗口。
+ /// 命令库为纯 .NET 类库,不直接引用 WPF 程序集;
+ /// 实际的弹窗能力由宿主程序(ACP 外壳)在启动时注入到 委托中实现(依赖倒置)。
+ ///
+ [ACPCommand]
+ public static class CommandDialog
+ {
+ ///
+ /// 弹窗类型
+ ///
+ public enum DialogType
+ {
+ ///
+ /// 信息提示
+ ///
+ Info,
+ ///
+ /// 警告提示
+ ///
+ Warning,
+ ///
+ /// 错误提示
+ ///
+ Error
+ }
+
+ ///
+ /// 弹窗处理委托(参数依次为:弹窗类型、弹窗详细、是否阻塞、自动关闭秒数、取消令牌)。
+ /// 由宿主程序启动时注入实现;未注入时弹窗命令降级为仅输出日志,不会抛异常。
+ ///
+ [Browsable(false)]
+ public static Func 弹窗处理器;
+
+ ///
+ /// 弹窗:在界面上显示一个提示对话框。
+ ///
+ /// 弹窗样式:Info 信息 / Warning 警告 / Error 错误
+ /// 弹窗中显示的详细内容
+ /// true = 步骤暂停,等待用户关闭(或自动关闭)后才继续;false = 弹出后步骤立即继续
+ /// 大于 0 时,弹窗在指定秒数后自动关闭;小于等于 0 时不自动关闭,需用户手动关闭
+ /// 异步取消令牌
+ public static async Task 弹窗(DialogType 弹窗类型, string 弹窗详细, bool 是否阻塞, float 自动关闭秒数, CancellationToken ct)
+ {
+ var handler = 弹窗处理器;
+ if (handler == null)
+ {
+ Console.WriteLine($"[弹窗命令] 宿主未注入弹窗处理器,跳过弹窗:{弹窗详细}");
+ return;
+ }
+ await handler(弹窗类型, 弹窗详细, 是否阻塞, 自动关闭秒数, ct);
+ }
+ }
+}
+