示例#1
0
        private async Task Show(DialogOption option)
        {
            if (ModalDialog != null)
            {
                option.Modal = ModalContainer;

                var parameters = option.ToAttributes().ToList();
                parameters.Add(new KeyValuePair <string, object>(nameof(ModalDialogBase.BodyContext), option.BodyContext));

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

                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() =>
                {
                    if (!option.KeepChildrenState)
                    {
                        await Task.Delay(500);
                        await ModalDialog.SetParametersAsync(ParameterView.FromDictionary(new Dictionary <string, object>()
                        {
                            [nameof(ModalDialogBase.BodyContext)]  = option.BodyContext,
                            [nameof(ModalDialogBase.BodyTemplate)] = new RenderFragment <object>(context => builder => builder.AddContent(0, ""))
                        }));
                    }
                })));

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

                IsShowDialog = true;
                StateHasChanged();
            }
        }
示例#2
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();
        }
示例#3
0
        private async Task Show(DialogOption option)
        {
            option.Dialog = ModalContainer;
            var parameters = option.ToAttributes().ToList();

            var content = option.BodyTemplate ?? option.Component?.Render();

            if (content != null)
            {
                parameters.Add(new KeyValuePair <string, object>(nameof(ModalDialogBase.BodyTemplate), option.KeepChildrenState ? content : new RenderFragment(builder =>
                {
                    builder.OpenElement(0, "div");
                    builder.SetKey(option);
                    builder.AddContent(1, content);
                    builder.CloseElement();
                })));
            }

            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();
        }