| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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
- {
- /// <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));
- }
- }
- }
|