| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Services.Dialogs;
- using SKMC.Api.Client.UI;
- using SKMC.Api.Common;
- using SKMC.Api.Core;
- using System;
- namespace SKMC.Api.Client.Views
- {
- /// <summary>
- /// 封装Editor基础类
- /// </summary>
- /// <typeparam name="T"></typeparam>
- public class BaseEditorModel<T> : BindableBase, IShowDialog
- {
- private readonly ClientCacher clientCacher = ObjectFactory.Resolve<ClientCacher>();
- public string Id { get; set; }
- public string Title { get; set; }
- public event Action<IDialogResult> 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<T>("model") != null)
- {
- Model = parameters.GetValue<T>("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));
- }
- }
- }
|