From a5e1dc137326bf6acdca00cef342358d198146a0 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 27 Mar 2022 11:11:55 +0800 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20partial=20?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/FullScreen/FullScreen.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/FullScreen/FullScreen.cs b/src/BootstrapBlazor/Components/FullScreen/FullScreen.cs index 65e5d7c7b..9680b2fa2 100644 --- a/src/BootstrapBlazor/Components/FullScreen/FullScreen.cs +++ b/src/BootstrapBlazor/Components/FullScreen/FullScreen.cs @@ -9,7 +9,7 @@ namespace BootstrapBlazor.Components; /// /// FullScreen 组件部分类 /// -public partial class FullScreen : BootstrapComponentBase, IDisposable +public class FullScreen : BootstrapComponentBase, IDisposable { /// /// DialogServices 服务实例 -- Gitee From 1eb7edfcb2efb96dad6395ce1f079585e6cf239f Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 27 Mar 2022 13:35:33 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=B2=98?= =?UTF-8?q?=E8=B4=B4=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Anchor/AnchorLink.js | 18 ------ .../BaseComponents/BootstrapBlazorRoot.razor | 1 + .../Components/Clipboard/Clipboard.cs | 57 +++++++++++++++++++ .../Components/Clipboard/Clipboard.js | 19 +++++++ .../Components/Clipboard/ClipboardOption.cs | 23 ++++++++ .../Components/Clipboard/ClipboardService.cs | 13 +++++ ...tstrapBlazorServiceCollectionExtensions.cs | 1 + 7 files changed, 114 insertions(+), 18 deletions(-) create mode 100644 src/BootstrapBlazor/Components/Clipboard/Clipboard.cs create mode 100644 src/BootstrapBlazor/Components/Clipboard/Clipboard.js create mode 100644 src/BootstrapBlazor/Components/Clipboard/ClipboardOption.cs create mode 100644 src/BootstrapBlazor/Components/Clipboard/ClipboardService.cs diff --git a/src/BootstrapBlazor/Components/Anchor/AnchorLink.js b/src/BootstrapBlazor/Components/Anchor/AnchorLink.js index b81efeec1..042d28d52 100644 --- a/src/BootstrapBlazor/Components/Anchor/AnchorLink.js +++ b/src/BootstrapBlazor/Components/Anchor/AnchorLink.js @@ -1,22 +1,4 @@ (function ($) { - $.extend({ - bb_copyText: function (ele) { - if (navigator.clipboard) { - navigator.clipboard.writeText(ele); - } - else { - if (typeof ele !== "string") return false; - var input = document.createElement('input'); - input.setAttribute('type', 'text'); - input.setAttribute('value', ele); - document.body.appendChild(input); - input.select(); - document.execCommand('copy'); - document.body.removeChild(input); - } - } - }); - $(function () { $(document) .on('click', '.anchor-link', function (e) { diff --git a/src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor b/src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor index be6251b6b..2d2c2e33f 100644 --- a/src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor +++ b/src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor @@ -21,6 +21,7 @@ else + @code { diff --git a/src/BootstrapBlazor/Components/Clipboard/Clipboard.cs b/src/BootstrapBlazor/Components/Clipboard/Clipboard.cs new file mode 100644 index 000000000..9ce3ab41f --- /dev/null +++ b/src/BootstrapBlazor/Components/Clipboard/Clipboard.cs @@ -0,0 +1,57 @@ +// 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; + +/// <summary> +/// FullScreen 组件部分类 +/// </summary> +public class Clipboard : BootstrapComponentBase, IDisposable +{ + /// <summary> + /// DialogServices 服务实例 + /// </summary> + [Inject] + [NotNull] + private ClipboardService? ClipboardService { get; set; } + + /// <summary> + /// OnInitialized 方法 + /// </summary> + protected override void OnInitialized() + { + base.OnInitialized(); + + // 注册 ClipboardService 弹窗事件 + ClipboardService.Register(this, Copy); + } + + private async Task Copy(ClipboardOption option) + { + await JSRuntime.InvokeVoidAsync(option.Element, "bb_copyText"); + } + + /// <summary> + /// Dispose 方法 + /// </summary> + /// <param name="disposing"></param> + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + ClipboardService.UnRegister(this); + } + } + + /// <summary> + /// Dispose 方法 + /// </summary> + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } +} diff --git a/src/BootstrapBlazor/Components/Clipboard/Clipboard.js b/src/BootstrapBlazor/Components/Clipboard/Clipboard.js new file mode 100644 index 000000000..d3d2544c6 --- /dev/null +++ b/src/BootstrapBlazor/Components/Clipboard/Clipboard.js @@ -0,0 +1,19 @@ +(function ($) { + $.extend({ + bb_copyText: function (ele) { + if (navigator.clipboard) { + navigator.clipboard.writeText(ele); + } + else { + if (typeof ele !== "string") return false; + var input = document.createElement('input'); + input.setAttribute('type', 'text'); + input.setAttribute('value', ele); + document.body.appendChild(input); + input.select(); + document.execCommand('copy'); + document.body.removeChild(input); + } + } + }); +})(jQuery); diff --git a/src/BootstrapBlazor/Components/Clipboard/ClipboardOption.cs b/src/BootstrapBlazor/Components/Clipboard/ClipboardOption.cs new file mode 100644 index 000000000..fe36bad38 --- /dev/null +++ b/src/BootstrapBlazor/Components/Clipboard/ClipboardOption.cs @@ -0,0 +1,23 @@ +// 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; + +/// <summary> +/// Clipboard 配置类 +/// </summary> +public class ClipboardOption +{ + /// <summary> + /// + /// </summary> + public ElementReference Element { get; set; } + + /// <summary> + /// + /// </summary> + public string? Id { get; set; } +} diff --git a/src/BootstrapBlazor/Components/Clipboard/ClipboardService.cs b/src/BootstrapBlazor/Components/Clipboard/ClipboardService.cs new file mode 100644 index 000000000..3aa4b2901 --- /dev/null +++ b/src/BootstrapBlazor/Components/Clipboard/ClipboardService.cs @@ -0,0 +1,13 @@ +// 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/ + +namespace BootstrapBlazor.Components; + +/// <summary> +/// 粘贴板服务 +/// </summary> +public class ClipboardService : BootstrapServiceBase<ClipboardOption> +{ + +} diff --git a/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs b/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs index 0a97c6066..e14bb764c 100644 --- a/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs +++ b/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs @@ -51,6 +51,7 @@ public static class BootstrapBlazorServiceCollectionExtensions services.TryAddScoped<WebClientService>(); services.TryAddScoped<AjaxService>(); services.TryAddScoped(typeof(DragDropService<>)); + services.TryAddScoped<ClipboardService>(); services.TryAddSingleton<IConfigureOptions<BootstrapBlazorOptions>, ConfigureOptions<BootstrapBlazorOptions>>(); services.ConfigureBootstrapBlazorOption(configureOptions); -- Gitee From aec7b76aa193e7fae8b2aa8b4c12c96e6821e064 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo <argo@163.com> Date: Sun, 27 Mar 2022 14:24:00 +0800 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=20Option=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Clipboard/Clipboard.cs | 2 +- src/BootstrapBlazor/Components/Clipboard/Clipboard.js | 6 +++--- .../Components/Clipboard/ClipboardOption.cs | 11 ++--------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/BootstrapBlazor/Components/Clipboard/Clipboard.cs b/src/BootstrapBlazor/Components/Clipboard/Clipboard.cs index 9ce3ab41f..e5b023992 100644 --- a/src/BootstrapBlazor/Components/Clipboard/Clipboard.cs +++ b/src/BootstrapBlazor/Components/Clipboard/Clipboard.cs @@ -31,7 +31,7 @@ public class Clipboard : BootstrapComponentBase, IDisposable private async Task Copy(ClipboardOption option) { - await JSRuntime.InvokeVoidAsync(option.Element, "bb_copyText"); + await JSRuntime.InvokeVoidAsync(null, "bb_copyText", option.Text); } /// <summary> diff --git a/src/BootstrapBlazor/Components/Clipboard/Clipboard.js b/src/BootstrapBlazor/Components/Clipboard/Clipboard.js index d3d2544c6..48d8f509f 100644 --- a/src/BootstrapBlazor/Components/Clipboard/Clipboard.js +++ b/src/BootstrapBlazor/Components/Clipboard/Clipboard.js @@ -1,14 +1,14 @@ (function ($) { $.extend({ - bb_copyText: function (ele) { + bb_copyText: function (text) { if (navigator.clipboard) { - navigator.clipboard.writeText(ele); + navigator.clipboard.writeText(text); } else { if (typeof ele !== "string") return false; var input = document.createElement('input'); input.setAttribute('type', 'text'); - input.setAttribute('value', ele); + input.setAttribute('value', text); document.body.appendChild(input); input.select(); document.execCommand('copy'); diff --git a/src/BootstrapBlazor/Components/Clipboard/ClipboardOption.cs b/src/BootstrapBlazor/Components/Clipboard/ClipboardOption.cs index fe36bad38..ee9efe5d9 100644 --- a/src/BootstrapBlazor/Components/Clipboard/ClipboardOption.cs +++ b/src/BootstrapBlazor/Components/Clipboard/ClipboardOption.cs @@ -2,8 +2,6 @@ // 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; /// <summary> @@ -12,12 +10,7 @@ namespace BootstrapBlazor.Components; public class ClipboardOption { /// <summary> - /// - /// </summary> - public ElementReference Element { get; set; } - - /// <summary> - /// + /// 获得/设置 要拷贝的文字 /// </summary> - public string? Id { get; set; } + public string Text { get; set; } = ""; } -- Gitee From 682e4d98966876c59abc8cc98208e4d912c5fde6 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo <argo@163.com> Date: Sun, 27 Mar 2022 14:31:11 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20Copy=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Clipboard/ClipboardService.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/Clipboard/ClipboardService.cs b/src/BootstrapBlazor/Components/Clipboard/ClipboardService.cs index 3aa4b2901..b2399baf4 100644 --- a/src/BootstrapBlazor/Components/Clipboard/ClipboardService.cs +++ b/src/BootstrapBlazor/Components/Clipboard/ClipboardService.cs @@ -9,5 +9,10 @@ namespace BootstrapBlazor.Components; /// </summary> public class ClipboardService : BootstrapServiceBase<ClipboardOption> { - + /// <summary> + /// 拷贝方法 + /// </summary> + /// <param name="text"></param> + /// <returns></returns> + public Task Copy(string? text) => Invoke(new ClipboardOption() { Text = text ?? "" }); } -- Gitee From 5c8b333ec34d0643ad652981a3be1a83529c4538 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo <argo@163.com> Date: Mon, 28 Mar 2022 01:55:49 +0800 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Clipboard/Clipboard.cs | 2 +- src/BootstrapBlazor/Components/Clipboard/ClipboardOption.cs | 2 +- src/BootstrapBlazor/Components/Clipboard/ClipboardService.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BootstrapBlazor/Components/Clipboard/Clipboard.cs b/src/BootstrapBlazor/Components/Clipboard/Clipboard.cs index e5b023992..07ab16560 100644 --- a/src/BootstrapBlazor/Components/Clipboard/Clipboard.cs +++ b/src/BootstrapBlazor/Components/Clipboard/Clipboard.cs @@ -31,7 +31,7 @@ public class Clipboard : BootstrapComponentBase, IDisposable private async Task Copy(ClipboardOption option) { - await JSRuntime.InvokeVoidAsync(null, "bb_copyText", option.Text); + await JSRuntime.InvokeVoidAsync(null, "bb_copyText", option.Text ?? string.Empty); } /// <summary> diff --git a/src/BootstrapBlazor/Components/Clipboard/ClipboardOption.cs b/src/BootstrapBlazor/Components/Clipboard/ClipboardOption.cs index ee9efe5d9..b9675824e 100644 --- a/src/BootstrapBlazor/Components/Clipboard/ClipboardOption.cs +++ b/src/BootstrapBlazor/Components/Clipboard/ClipboardOption.cs @@ -12,5 +12,5 @@ public class ClipboardOption /// <summary> /// 获得/设置 要拷贝的文字 /// </summary> - public string Text { get; set; } = ""; + public string? Text { get; set; } } diff --git a/src/BootstrapBlazor/Components/Clipboard/ClipboardService.cs b/src/BootstrapBlazor/Components/Clipboard/ClipboardService.cs index b2399baf4..e4d9f9ead 100644 --- a/src/BootstrapBlazor/Components/Clipboard/ClipboardService.cs +++ b/src/BootstrapBlazor/Components/Clipboard/ClipboardService.cs @@ -14,5 +14,5 @@ public class ClipboardService : BootstrapServiceBase<ClipboardOption> /// </summary> /// <param name="text"></param> /// <returns></returns> - public Task Copy(string? text) => Invoke(new ClipboardOption() { Text = text ?? "" }); + public Task Copy(string? text) => Invoke(new ClipboardOption() { Text = text }); } -- Gitee