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