using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; using SKMC.Api.Client.UI; using SKMC.Api.Common; using System; namespace SKMC.Api.Client.Views { /// /// 封装Editor基础类 /// /// public class BaseEditorModel : BindableBase, IShowDialog { private readonly ClientCacher clientCacher = ObjectFactory.Resolve(); public string Id { get; set; } public string Title { get; set; } public event Action RequestClose; public T Model { get; set; } public DelegateCommand SaveCommand { get; set; } public DelegateCommand CancelCommand { get; set; } public bool CanCloseDialog() => true; public BaseEditorModel() { SaveCommand = new DelegateCommand(() => { DialogParameters parameters = new DialogParameters { { "Id", Id } }; if (Model != null) parameters.Add("result", Model); RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters)); }); CancelCommand = new DelegateCommand(() => { DialogParameters parameters = new DialogParameters { { "Id", Id } }; RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters)); }); } public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { if (parameters.GetValue("model") != null) { Model = parameters.GetValue("model"); } Id = CommonUtil.StringId(); clientCacher.ShowCommonDialogs.Add(this); } public void CloseDialog() { DialogParameters parameters = new DialogParameters { { "Id", Id } }; if (Model != null) parameters.Add("result", Model); RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters)); } } }