From 76c968ac394942b35342f561ced30be35b071788 Mon Sep 17 00:00:00 2001 From: croire <1432593898@qq.com> Date: Sat, 7 May 2022 12:55:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90AlertDialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DownKyi/App.xaml.cs | 1 + DownKyi/DownKyi.csproj | 9 ++ DownKyi/Images/SystemIcon.cs | 32 ++++ DownKyi/Languages/Default.xaml | 5 + DownKyi/Services/AlertService.cs | 71 +++++++++ DownKyi/ViewModels/BaseViewModel.cs | 8 + .../ViewModels/Dialogs/BaseDialogViewModel.cs | 6 +- .../Dialogs/ViewAlertDialogViewModel.cs | 65 ++++++++ DownKyi/ViewModels/ViewIndexViewModel.cs | 8 +- .../ViewModels/ViewVideoDetailViewModel.cs | 6 +- DownKyi/Views/Dialogs/ViewAlertDialog.xaml | 144 ++++++++++++++++++ DownKyi/Views/Dialogs/ViewAlertDialog.xaml.cs | 28 ++++ DownKyi/Views/Dialogs/ViewDownloadSetter.xaml | 5 +- .../Views/Dialogs/ViewParsingSelector.xaml | 5 +- 14 files changed, 381 insertions(+), 12 deletions(-) create mode 100644 DownKyi/Services/AlertService.cs create mode 100644 DownKyi/ViewModels/Dialogs/ViewAlertDialogViewModel.cs create mode 100644 DownKyi/Views/Dialogs/ViewAlertDialog.xaml create mode 100644 DownKyi/Views/Dialogs/ViewAlertDialog.xaml.cs diff --git a/DownKyi/App.xaml.cs b/DownKyi/App.xaml.cs index 6a5d6a9..48f9caf 100644 --- a/DownKyi/App.xaml.cs +++ b/DownKyi/App.xaml.cs @@ -194,6 +194,7 @@ namespace DownKyi containerRegistry.RegisterForNavigation(ViewModels.UserSpace.ViewChannelViewModel.Tag); // dialogs + containerRegistry.RegisterDialog(ViewAlertDialogViewModel.Tag); containerRegistry.RegisterDialog(ViewDownloadSetterViewModel.Tag); containerRegistry.RegisterDialog(ViewParsingSelectorViewModel.Tag); diff --git a/DownKyi/DownKyi.csproj b/DownKyi/DownKyi.csproj index 1f6c474..33eefbb 100644 --- a/DownKyi/DownKyi.csproj +++ b/DownKyi/DownKyi.csproj @@ -115,10 +115,12 @@ + + @@ -186,6 +188,9 @@ + + ViewAlertDialog.xaml + ViewDownloadSetter.xaml @@ -344,6 +349,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/DownKyi/Images/SystemIcon.cs b/DownKyi/Images/SystemIcon.cs index b6bec27..b2b83cb 100644 --- a/DownKyi/Images/SystemIcon.cs +++ b/DownKyi/Images/SystemIcon.cs @@ -65,6 +65,34 @@ l1.8-2.2c0-0.1,0-0.5-0.1-0.8l-3.1-3.6C29.7,17.1,29.5,17,29.2,17z", Fill = "#FF000000" }; + + Info = new VectorImage + { + Height = 20, + Width = 20, + Data = @"M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 + 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z", + Fill = "#FF00bcf2" + }; + + Warning = new VectorImage + { + Height = 20, + Width = 20, + Data = @"M12 5.99L19.53 19H4.47L12 5.99M2.74 18c-.77 1.33.19 3 1.73 3h15.06c1.54 0 2.5-1.67 1.73-3L13.73 + 4.99c-.77-1.33-2.69-1.33-3.46 0L2.74 18zM11 11v2c0 .55.45 1 1 1s1-.45 1-1v-2c0-.55-.45-1-1-1s-1 .45-1 1zm0 5h2v2h-2z", + Fill = "#FFffb900" + }; + + Error = new VectorImage + { + Height = 20, + Width = 20, + Data = @"M12 7c.55 0 1 .45 1 1v4c0 .55-.45 1-1 1s-1-.45-1-1V8c0-.55.45-1 1-1zm-.01-5C6.47 2 2 6.48 2 12s4.47 + 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 + 8-3.58 8-8 8zm1-3h-2v-2h2v2z", + Fill = "#FFd83b01" + }; } public VectorImage Close { get; private set; } @@ -72,5 +100,9 @@ public VectorImage Minimize { get; private set; } public VectorImage Restore { get; private set; } public VectorImage Skin { get; private set; } + + public VectorImage Info { get; private set; } + public VectorImage Warning { get; private set; } + public VectorImage Error { get; private set; } } } diff --git a/DownKyi/Languages/Default.xaml b/DownKyi/Languages/Default.xaml index 91d20c1..eab777e 100644 --- a/DownKyi/Languages/Default.xaml +++ b/DownKyi/Languages/Default.xaml @@ -293,6 +293,11 @@ 提取视频 + 信息 + 警告 + 错误 + + 确定 取消 请选择文件夹 diff --git a/DownKyi/Services/AlertService.cs b/DownKyi/Services/AlertService.cs new file mode 100644 index 0000000..504c758 --- /dev/null +++ b/DownKyi/Services/AlertService.cs @@ -0,0 +1,71 @@ +using DownKyi.Images; +using DownKyi.Utils; +using DownKyi.ViewModels.Dialogs; +using Prism.Services.Dialogs; + +namespace DownKyi.Services +{ + public class AlertService + { + private readonly IDialogService dialogService; + + public AlertService(IDialogService dialogService) + { + this.dialogService = dialogService; + } + + /// + /// 显示一个信息弹窗 + /// + /// + /// + public ButtonResult ShowInfo(string message) + { + VectorImage image = SystemIcon.Instance().Info; + string title = DictionaryResource.GetString("Info"); + return ShowMessage(image, title, message); + } + + /// + /// 显示一个警告弹窗 + /// + /// + /// + public ButtonResult ShowWarning(string message) + { + VectorImage image = SystemIcon.Instance().Warning; + string title = DictionaryResource.GetString("Warning"); + return ShowMessage(image, title, message); + } + + /// + /// 显示一个错误弹窗 + /// + /// + /// + public ButtonResult ShowError(string message) + { + VectorImage image = SystemIcon.Instance().Error; + string title = DictionaryResource.GetString("Error"); + return ShowMessage(image, title, message); + } + + private ButtonResult ShowMessage(VectorImage image, string type, string message) + { + ButtonResult result = ButtonResult.None; + + DialogParameters param = new DialogParameters + { + { "image", image }, + { "title", type }, + { "message", message } + }; + dialogService.ShowDialog(ViewAlertDialogViewModel.Tag, param, buttonResult => + { + result = buttonResult.Result; + }); + return result; + } + + } +} diff --git a/DownKyi/ViewModels/BaseViewModel.cs b/DownKyi/ViewModels/BaseViewModel.cs index 54d623f..89d5852 100644 --- a/DownKyi/ViewModels/BaseViewModel.cs +++ b/DownKyi/ViewModels/BaseViewModel.cs @@ -1,6 +1,7 @@ using Prism.Events; using Prism.Mvvm; using Prism.Regions; +using Prism.Services.Dialogs; using System; using System.Windows; @@ -9,6 +10,7 @@ namespace DownKyi.ViewModels public class BaseViewModel : BindableBase, INavigationAware { protected readonly IEventAggregator eventAggregator; + protected readonly IDialogService dialogService; protected string ParentView = string.Empty; public BaseViewModel(IEventAggregator eventAggregator) @@ -16,6 +18,12 @@ namespace DownKyi.ViewModels this.eventAggregator = eventAggregator; } + public BaseViewModel(IEventAggregator eventAggregator, IDialogService dialogService) + { + this.eventAggregator = eventAggregator; + this.dialogService = dialogService; + } + public bool IsNavigationTarget(NavigationContext navigationContext) { return true; diff --git a/DownKyi/ViewModels/Dialogs/BaseDialogViewModel.cs b/DownKyi/ViewModels/Dialogs/BaseDialogViewModel.cs index 2da4b97..287d65b 100644 --- a/DownKyi/ViewModels/Dialogs/BaseDialogViewModel.cs +++ b/DownKyi/ViewModels/Dialogs/BaseDialogViewModel.cs @@ -115,16 +115,16 @@ namespace DownKyi.ViewModels.Dialogs public event Action RequestClose; - public bool CanCloseDialog() + public virtual bool CanCloseDialog() { return true; } - public void OnDialogClosed() + public virtual void OnDialogClosed() { } - public void OnDialogOpened(IDialogParameters parameters) + public virtual void OnDialogOpened(IDialogParameters parameters) { } diff --git a/DownKyi/ViewModels/Dialogs/ViewAlertDialogViewModel.cs b/DownKyi/ViewModels/Dialogs/ViewAlertDialogViewModel.cs new file mode 100644 index 0000000..4a61093 --- /dev/null +++ b/DownKyi/ViewModels/Dialogs/ViewAlertDialogViewModel.cs @@ -0,0 +1,65 @@ +using DownKyi.Images; +using Prism.Commands; +using Prism.Services.Dialogs; + +namespace DownKyi.ViewModels.Dialogs +{ + public class ViewAlertDialogViewModel : BaseDialogViewModel + { + public const string Tag = "DialogAlert"; + + #region 页面属性申明 + + private VectorImage image; + public VectorImage Image + { + get => image; + set => SetProperty(ref image, value); + } + + private string message; + public string Message + { + get { return message; } + set { SetProperty(ref message, value); } + } + + #endregion + + public ViewAlertDialogViewModel() + { + + } + + #region 命令申明 + + // 确认事件 + private DelegateCommand allowCommand; + public DelegateCommand AllowCommand => allowCommand ?? (allowCommand = new DelegateCommand(ExecuteAllowCommand)); + + /// + /// 确认事件 + /// + private void ExecuteAllowCommand() + { + ButtonResult result = ButtonResult.OK; + RaiseRequestClose(new DialogResult(result)); + } + + #endregion + + #region 接口实现 + + public override void OnDialogOpened(IDialogParameters parameters) + { + base.OnDialogOpened(parameters); + + Image = parameters.GetValue("image"); + Title = parameters.GetValue("title"); + Message = parameters.GetValue("message"); + } + + #endregion + + } +} diff --git a/DownKyi/ViewModels/ViewIndexViewModel.cs b/DownKyi/ViewModels/ViewIndexViewModel.cs index 66a230d..ee1fbc8 100644 --- a/DownKyi/ViewModels/ViewIndexViewModel.cs +++ b/DownKyi/ViewModels/ViewIndexViewModel.cs @@ -9,6 +9,7 @@ using DownKyi.Utils; using Prism.Commands; using Prism.Events; using Prism.Regions; +using Prism.Services.Dialogs; using System; using System.IO; using System.Threading.Tasks; @@ -88,7 +89,7 @@ namespace DownKyi.ViewModels #endregion - public ViewIndexViewModel(IEventAggregator eventAggregator) : base(eventAggregator) + public ViewIndexViewModel(IEventAggregator eventAggregator, IDialogService dialogService) : base(eventAggregator, dialogService) { #region 属性初始化 @@ -207,7 +208,10 @@ namespace DownKyi.ViewModels /// private void EnterBili() { - if (InputText == null || InputText == string.Empty) { return; } + if (InputText == null || InputText == string.Empty) + { + return; + } LogManager.Debug(Tag, $"InputText: {InputText}"); diff --git a/DownKyi/ViewModels/ViewVideoDetailViewModel.cs b/DownKyi/ViewModels/ViewVideoDetailViewModel.cs index edb6cf2..088a7ae 100644 --- a/DownKyi/ViewModels/ViewVideoDetailViewModel.cs +++ b/DownKyi/ViewModels/ViewVideoDetailViewModel.cs @@ -27,8 +27,6 @@ namespace DownKyi.ViewModels { public const string Tag = "PageVideoDetail"; - private readonly IDialogService dialogService; - // 保存输入字符串,避免被用户修改 private string input = null; @@ -106,10 +104,8 @@ namespace DownKyi.ViewModels #endregion - public ViewVideoDetailViewModel(IEventAggregator eventAggregator, IDialogService dialogService) : base(eventAggregator) + public ViewVideoDetailViewModel(IEventAggregator eventAggregator, IDialogService dialogService) : base(eventAggregator, dialogService) { - this.dialogService = dialogService; - #region 属性初始化 // 初始化loading gif diff --git a/DownKyi/Views/Dialogs/ViewAlertDialog.xaml b/DownKyi/Views/Dialogs/ViewAlertDialog.xaml new file mode 100644 index 0000000..16de4ef --- /dev/null +++ b/DownKyi/Views/Dialogs/ViewAlertDialog.xaml @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +