コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        protected void ShowEditorDialog()
        {
            DialogOption.IsScrolling  = ScrollingDialogContent;
            DialogOption.ShowFooter   = false;
            DialogOption.Size         = Size.ExtraLarge;
            DialogOption.Title        = EditModalTitleString;
            DialogOption.OnCloseAsync = async() =>
            {
                if (UseInjectDataService && GetDataService() is IEntityFrameworkCoreDataService ef)
                {
                    // EFCore
                    await ef.CancelAsync();
                }
            };
            var editorParameters = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>(nameof(TableEditorDialog <TItem> .Model), EditModel),
                new KeyValuePair <string, object>(nameof(TableEditorDialog <TItem> .Columns), Columns.Where(i => i.Editable)),
                new KeyValuePair <string, object>(nameof(TableEditorDialog <TItem> .OnCloseAsync), new Func <Task>(DialogOption.OnCloseAsync)),
                new KeyValuePair <string, object>(nameof(TableEditorDialog <TItem> .OnSaveAsync), new Func <EditContext, Task>(SaveAsync)),
                new KeyValuePair <string, object>(nameof(TableEditorDialog <TItem> .ShowLabel), false),
                new KeyValuePair <string, object>(nameof(TableEditorDialog <TItem> .BodyTemplate), EditTemplate !)
            };

            if (!string.IsNullOrEmpty(EditDialogSaveButtonText))
            {
                editorParameters.Add(new KeyValuePair <string, object>(nameof(TableEditorDialog <TItem> .SaveButtonText), EditDialogSaveButtonText));
            }

            DialogOption.Component = DynamicComponent.CreateComponent <TableEditorDialog <TItem> >(editorParameters);

            DialogService.Show(DialogOption);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        protected void ShowEditorDialog()
        {
            DialogOption.IsScrolling = true;
            DialogOption.ShowFooter  = false;
            DialogOption.Size        = Size.ExtraLarge;
            DialogOption.Title       = EditModalTitleString ?? "未设置";

            var editorParameters = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>(nameof(TableEditorDialog <TItem> .Model), EditModel),
                new KeyValuePair <string, object>(nameof(TableEditorDialog <TItem> .Columns), Columns),
                new KeyValuePair <string, object>(nameof(TableEditorDialog <TItem> .OnSaveAsync), new Func <EditContext, Task>(Save)),
                new KeyValuePair <string, object>(nameof(TableEditorDialog <TItem> .ShowLabel), false),
                new KeyValuePair <string, object>(nameof(TableEditorDialog <TItem> .BodyTemplate), EditTemplate)
            };

            DialogOption.Component = DynamicComponent.CreateComponent <TableEditorDialog <TItem> >(editorParameters);

            DialogService?.Show(DialogOption);
        }
コード例 #3
0
        private async Task Show(DialogOption option)
        {
            option.Dialog = ModalContainer;
            var parameters = option.ToAttributes().ToList();

            if (option.BodyTemplate != null)
            {
                parameters.Add(new KeyValuePair <string, object>(nameof(ModalDialogBase.BodyTemplate), option.BodyTemplate));
            }
            else if (option.Component != null)
            {
                parameters.Add(new KeyValuePair <string, object>(nameof(ModalDialogBase.BodyTemplate), option.Component.Render()));
            }
            else
            {
                parameters.Add(new KeyValuePair <string, object>(nameof(ModalDialogBase.BodyTemplate), DynamicComponent.CreateComponent <Empty>().Render()));
            }

            if (option.FooterTemplate != null)
            {
                parameters.Add(new KeyValuePair <string, object>(nameof(ModalDialogBase.FooterTemplate), option.FooterTemplate));
            }

            parameters.Add(new KeyValuePair <string, object>(nameof(ModalDialogBase.OnClose), new Func <Task>(async() =>
            {
                // 回调 OnClose 方法
                if (option.OnCloseAsync != null)
                {
                    await option.OnCloseAsync();
                }
            })));

            await ModalDialog.SetParametersAsync(ParameterView.FromDictionary(parameters.ToDictionary(key => key.Key, value => value.Value)));

            IsShowDialog = true;
            StateHasChanged();
        }