From c5f91e82d10aeb82fa5a49dcf130f2608584a1eb Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Tue, 2 Nov 2021 10:45:31 +0800 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=94=B9=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=96=87=E4=BB=B6=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Print/PrintButton.razor.cs | 2 +- src/BootstrapBlazor/Locales/en.json | 2 +- src/BootstrapBlazor/Locales/zh.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BootstrapBlazor/Components/Print/PrintButton.razor.cs b/src/BootstrapBlazor/Components/Print/PrintButton.razor.cs index 9003596be..9a4bc7d0d 100644 --- a/src/BootstrapBlazor/Components/Print/PrintButton.razor.cs +++ b/src/BootstrapBlazor/Components/Print/PrintButton.razor.cs @@ -22,7 +22,7 @@ namespace BootstrapBlazor.Components [Inject] [NotNull] - private IStringLocalizer? Localizer { get; set; } + private IStringLocalizer? Localizer { get; set; } private string? Target { get; set; } diff --git a/src/BootstrapBlazor/Locales/en.json b/src/BootstrapBlazor/Locales/en.json index 77d46c22e..ae49043cf 100644 --- a/src/BootstrapBlazor/Locales/en.json +++ b/src/BootstrapBlazor/Locales/en.json @@ -169,7 +169,7 @@ "BootstrapBlazor.Components.PopoverService": { "InvalidOperationExceptionMessage": "Please place element on current page" }, - "BootstrapBlazor.Components.Print": { + "BootstrapBlazor.Components.PrintButton": { "Text": "Print" }, "BootstrapBlazor.Components.PrintService": { diff --git a/src/BootstrapBlazor/Locales/zh.json b/src/BootstrapBlazor/Locales/zh.json index e0100c760..39120c0e3 100644 --- a/src/BootstrapBlazor/Locales/zh.json +++ b/src/BootstrapBlazor/Locales/zh.json @@ -169,7 +169,7 @@ "BootstrapBlazor.Components.PopoverService": { "InvalidOperationExceptionMessage": "请在网页中添加 元素" }, - "BootstrapBlazor.Components.Print": { + "BootstrapBlazor.Components.PrintButton": { "Text": "打印" }, "BootstrapBlazor.Components.PrintService": { -- Gitee From 5b2b2bb1c6598474d40fac2d192e4f42278a5ece Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Tue, 2 Nov 2021 10:45:59 +0800 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=94=B9=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E5=90=8D=E7=A7=B0=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Print/{print.js => PrintButton.js} | 0 src/BootstrapBlazor/Components/Print/PrintButton.razor.cs | 4 +--- 2 files changed, 1 insertion(+), 3 deletions(-) rename src/BootstrapBlazor/Components/Print/{print.js => PrintButton.js} (100%) diff --git a/src/BootstrapBlazor/Components/Print/print.js b/src/BootstrapBlazor/Components/Print/PrintButton.js similarity index 100% rename from src/BootstrapBlazor/Components/Print/print.js rename to src/BootstrapBlazor/Components/Print/PrintButton.js diff --git a/src/BootstrapBlazor/Components/Print/PrintButton.razor.cs b/src/BootstrapBlazor/Components/Print/PrintButton.razor.cs index 9a4bc7d0d..3e4addf6e 100644 --- a/src/BootstrapBlazor/Components/Print/PrintButton.razor.cs +++ b/src/BootstrapBlazor/Components/Print/PrintButton.razor.cs @@ -15,7 +15,7 @@ namespace BootstrapBlazor.Components public partial class PrintButton { /// - /// 获得/设置 预览模板地址 必填项 默认为空 + /// 获得/设置 预览模板地址 默认为空 /// [Parameter] public string? PreviewUrl { get; set; } @@ -32,7 +32,6 @@ namespace BootstrapBlazor.Components protected override void OnInitialized() { // 不需要走 base.OnInitialized 方法 - ButtonIcon = Icon; Text ??= Localizer[nameof(Text)]; } @@ -43,7 +42,6 @@ namespace BootstrapBlazor.Components protected override void OnParametersSet() { // 不需要走 base.OnParametersSet 方法 - if (string.IsNullOrEmpty(PreviewUrl)) { AdditionalAttributes ??= new Dictionary(); -- Gitee From bcf4ab78e0498fa27243b0b69fcf251e838840fd Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Tue, 2 Nov 2021 11:35:20 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20PrintService?= =?UTF-8?q?=20=E6=89=93=E5=8D=B0=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/DataDialogComponent.razor | 1 - src/BootstrapBlazor/Components/Print/Print.cs | 38 +++++++------------ .../Components/Print/PrintOption.cs | 29 -------------- .../Components/Print/PrintService.cs | 21 +++++++++- 4 files changed, 32 insertions(+), 57 deletions(-) delete mode 100644 src/BootstrapBlazor/Components/Print/PrintOption.cs diff --git a/src/BootstrapBlazor.Shared/Components/DataDialogComponent.razor b/src/BootstrapBlazor.Shared/Components/DataDialogComponent.razor index 9cec78d6e..ec5f599d5 100644 --- a/src/BootstrapBlazor.Shared/Components/DataDialogComponent.razor +++ b/src/BootstrapBlazor.Shared/Components/DataDialogComponent.razor @@ -46,7 +46,6 @@ [NotNull] private IEnumerable? Hobbys { get; set; } - /// /// /// diff --git a/src/BootstrapBlazor/Components/Print/Print.cs b/src/BootstrapBlazor/Components/Print/Print.cs index 9498b2b15..33236f244 100644 --- a/src/BootstrapBlazor/Components/Print/Print.cs +++ b/src/BootstrapBlazor/Components/Print/Print.cs @@ -13,9 +13,9 @@ namespace BootstrapBlazor.Components /// /// /// - /// FullScreen 组件部分类 + /// 打印组件类 /// - public partial class Print : BootstrapComponentBase, IDisposable + public class Print : BootstrapComponentBase, IDisposable { /// /// PrintService 服务实例 @@ -25,38 +25,26 @@ namespace BootstrapBlazor.Components private PrintService? PrintService { get; set; } /// - /// OnInitialized 方法 + /// 获得 弹窗注入服务 /// - protected override void OnInitialized() - { - base.OnInitialized(); - - // 注册 FullScreen 弹窗事件 - PrintService.Register(this, PrintDocument); - } + [Inject] + [NotNull] + private DialogService? DialogService { get; set; } /// - /// OnAfterRenderAsync 方法 + /// OnInitialized 方法 /// - /// - /// - protected override async Task OnAfterRenderAsync(bool firstRender) + protected override void OnInitialized() { - await base.OnAfterRenderAsync(firstRender); + base.OnInitialized(); - if (Option != null) - { - await JSRuntime.InvokeVoidAsync(); - Option = null; - } + // 注册 打印弹窗事件 + PrintService.Register(this, PrintDialogAsync); } - private PrintOption? Option { get; set; } - - private Task PrintDocument(PrintOption option) + private Task PrintDialogAsync(DialogOption option) { - Option = option; - StateHasChanged(); + DialogService.Show(option); return Task.CompletedTask; } diff --git a/src/BootstrapBlazor/Components/Print/PrintOption.cs b/src/BootstrapBlazor/Components/Print/PrintOption.cs deleted file mode 100644 index 0a018f7ef..000000000 --- a/src/BootstrapBlazor/Components/Print/PrintOption.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -// Website: https://www.blazor.zone or https://argozhang.github.io/ - -using Microsoft.AspNetCore.Components; - -namespace BootstrapBlazor.Components -{ - /// - /// Print 配置类 - /// - public class PrintOption - { - /// - /// 获得/设置 打印内容 - /// - public RenderFragment? PrintBody { get; set; } - - /// - /// 获得/设置 打印组件 - /// - public BootstrapDynamicComponent? PrintComponent { get; set; } - - /// - /// 获得/设置 是否显示打印预览弹窗 - /// - public bool ShowPrintViewDialog { get; set; } - } -} diff --git a/src/BootstrapBlazor/Components/Print/PrintService.cs b/src/BootstrapBlazor/Components/Print/PrintService.cs index 1955c4265..9e7159099 100644 --- a/src/BootstrapBlazor/Components/Print/PrintService.cs +++ b/src/BootstrapBlazor/Components/Print/PrintService.cs @@ -2,7 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Website: https://www.blazor.zone or https://argozhang.github.io/ +using Microsoft.AspNetCore.Components; using Microsoft.Extensions.Localization; +using System; +using System.Collections.Generic; using System.Threading.Tasks; namespace BootstrapBlazor.Components @@ -10,7 +13,7 @@ namespace BootstrapBlazor.Components /// /// Print 服务 /// - public class PrintService : BootstrapServiceBase + public class PrintService : BootstrapServiceBase { /// /// 构造函数 @@ -25,6 +28,20 @@ namespace BootstrapBlazor.Components /// /// /// - public Task Print(PrintOption? option = null) => Invoke(option ?? new()); + public Task PrintAsync(DialogOption option) => Invoke(option); + + /// + /// 打印方法 + /// + /// + /// + /// + public async Task PrintAsync(Func>> parametersFactory) where TComponent : ComponentBase + { + var option = new DialogOption(); + var parameters = parametersFactory(option); + option.Component = BootstrapDynamicComponent.CreateComponent(parameters); + await PrintAsync(option); + } } } -- Gitee From 4c9abe00d0e06e1d2f4f312ed90d80ed3745754f Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Tue, 2 Nov 2021 11:35:30 +0800 Subject: [PATCH 4/5] =?UTF-8?q?doc:=20=E5=A2=9E=E5=8A=A0=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E8=B0=83=E7=94=A8=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pages/Samples/Prints.razor | 5 ++++ .../Pages/Samples/Prints.razor.cs | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/BootstrapBlazor.Shared/Pages/Samples/Prints.razor b/src/BootstrapBlazor.Shared/Pages/Samples/Prints.razor index c8074b314..2004c4a08 100644 --- a/src/BootstrapBlazor.Shared/Pages/Samples/Prints.razor +++ b/src/BootstrapBlazor.Shared/Pages/Samples/Prints.razor @@ -31,4 +31,9 @@