From 11e972b1ce3c9cc0ed3100baa58c3663336ca763 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sat, 15 Jan 2022 12:42:39 +0800 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=20ClientInfo?= =?UTF-8?q?=20=E5=AE=9E=E4=BD=93=E7=B1=BB=E7=94=A8=E4=BA=8E=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E5=AE=A2=E6=88=B7=E7=AB=AF=E8=AF=B7=E6=B1=82=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/WebClientService.cs | 139 ++++++++++-------- 1 file changed, 78 insertions(+), 61 deletions(-) diff --git a/src/BootstrapBlazor/Services/WebClientService.cs b/src/BootstrapBlazor/Services/WebClientService.cs index c932c7967..e31dc3d6e 100644 --- a/src/BootstrapBlazor/Services/WebClientService.cs +++ b/src/BootstrapBlazor/Services/WebClientService.cs @@ -14,56 +14,6 @@ namespace BootstrapBlazor.Components; /// public class WebClientService : IDisposable { - /// - /// 获得/设置 操作日志主键ID - /// - public string? Id { get; private set; } - - /// - /// 获得/设置 客户端IP - /// - public string? Ip { get; private set; } - - /// - /// 获得/设置 客户端地点 - /// - public string? City { get; private set; } - - /// - /// 获得/设置 客户端浏览器 - /// - public string? Browser { get; private set; } - - /// - /// 获得/设置 客户端操作系统 - /// - public string? OS { get; private set; } - - /// - /// 获得/设置 客户端设备类型 - /// - public string? Device { get; private set; } - - /// - /// 获得/设置 客户端浏览器语言 - /// - public string? Language { get; private set; } - - /// - /// 获取/设置 请求网址 - /// - public string? RequestUrl { get; private set; } - - /// - /// 获得/设置 客户端 UserAgent - /// - public string? UserAgent { get; private set; } - - /// - /// 获得/设置 浏览器引擎信息 - /// - public string? Engine { get; private set; } - /// /// 获得/设置 模态弹窗返回值任务实例 /// @@ -75,6 +25,8 @@ public class WebClientService : IDisposable private JSInterop? Interop { get; set; } + private ClientInfo? Client { get; set; } + /// /// /// @@ -86,15 +38,21 @@ public class WebClientService : IDisposable /// /// /// - public async Task RetrieveRemoteInfo() + public async Task GetClientInfo() { Interop ??= new JSInterop(_runtime); await Interop.InvokeVoidAsync(this, null, "webClient", "ip.axd", nameof(SetData)); - RequestUrl = _navigation.Uri; + + Client = new ClientInfo() + { + RequestUrl = _navigation.Uri + }; // 等待 SetData 方法执行完毕 ReturnTask = new TaskCompletionSource(); - return await ReturnTask.Task; + await ReturnTask.Task; + + return Client; } /// @@ -111,14 +69,17 @@ public class WebClientService : IDisposable [JSInvokable] public void SetData(string id, string ip, string os, string browser, string device, string language, string engine, string agent) { - Id = id; - Ip = ip; - OS = os; - Browser = browser; - Device = device; - Language = language; - Engine = engine; - UserAgent = agent; + if (Client != null) + { + Client.Id = id; + Client.Ip = ip; + Client.OS = os; + Client.Browser = browser; + Client.Device = device; + Client.Language = language; + Client.Engine = engine; + Client.UserAgent = agent; + } ReturnTask?.TrySetResult(true); } @@ -144,3 +105,59 @@ public class WebClientService : IDisposable GC.SuppressFinalize(this); } } + +/// +/// 客户端请求信息实体类 +/// +public class ClientInfo +{ + /// + /// 获得/设置 操作日志主键ID + /// + public string? Id { get; set; } + + /// + /// 获得/设置 客户端IP + /// + public string? Ip { get; set; } + + /// + /// 获得/设置 客户端地点 + /// + public string? City { get; set; } + + /// + /// 获得/设置 客户端浏览器 + /// + public string? Browser { get; set; } + + /// + /// 获得/设置 客户端操作系统 + /// + public string? OS { get; set; } + + /// + /// 获得/设置 客户端设备类型 + /// + public string? Device { get; set; } + + /// + /// 获得/设置 客户端浏览器语言 + /// + public string? Language { get; set; } + + /// + /// 获取/设置 请求网址 + /// + public string? RequestUrl { get; set; } + + /// + /// 获得/设置 客户端 UserAgent + /// + public string? UserAgent { get; set; } + + /// + /// 获得/设置 浏览器引擎信息 + /// + public string? Engine { get; set; } +} -- Gitee From 586e8be6a9ea35cbd7a89fbcef992315f653bdf0 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sat, 15 Jan 2022 12:42:54 +0800 Subject: [PATCH 2/5] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Shared/Locales/en.json | 6 +++--- src/BootstrapBlazor.Shared/Locales/zh.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/BootstrapBlazor.Shared/Locales/en.json b/src/BootstrapBlazor.Shared/Locales/en.json index 55bbffc7f..94e0e4f44 100644 --- a/src/BootstrapBlazor.Shared/Locales/en.json +++ b/src/BootstrapBlazor.Shared/Locales/en.json @@ -2038,9 +2038,9 @@ "BasicUsageTitle": "Basic usage", "BasicUsageIntro": "The injection service displays client information", "BasicUsageP1": "Introduction to usage", - "BasicUsageP2": "1.The UseBootstrapBlazor middleware in the Startup.cs file that client information collection is performed.", - "BasicUsageTips": "app. UseBootstrapBlazor Middleware is located assembly BootstrapBlazor.Middleware , please refer to this package yourself for proper use", - "BasicUsageP3": "2. The component uses the injection service WebClientService to call the Retrieve RemoteInfo method.", + "BasicUsageP2": "1. The UseBootstrapBlazor middleware in the Startup.cs file that client information collection is performed.", + "BasicUsageTips": "app.UseBootstrapBlazor Middleware is located assembly BootstrapBlazor.Middleware, please refer to this package yourself for proper use", + "BasicUsageP3": "2. The component uses the injection service WebClientService to call the GetClientInfo method.", "GroupBoxTitle": "Connection information", "Id": "Connection ID", "RequestUrl": "RequestUrl", diff --git a/src/BootstrapBlazor.Shared/Locales/zh.json b/src/BootstrapBlazor.Shared/Locales/zh.json index 8cf35f516..5d349cbb7 100644 --- a/src/BootstrapBlazor.Shared/Locales/zh.json +++ b/src/BootstrapBlazor.Shared/Locales/zh.json @@ -2043,7 +2043,7 @@ "BasicUsageP1": "用法介绍", "BasicUsageP2": "1. Startup.cs 文件中使用 UseBootstrapBlazor 中间件进行客户端信息收集", "BasicUsageTips": "app.UseBootstrapBlazor 中间件位于程序集 BootstrapBlazor.Middleware,请自行引用此包才能正常使用", - "BasicUsageP3": "2. 组件中使用注入服务 WebClientService 调用 RetrieveRemoteInfo 方法", + "BasicUsageP3": "2. 组件中使用注入服务 WebClientService 调用 GetClientInfo 方法", "GroupBoxTitle": "您的连接信息", "Id": "连接 ID", "RequestUrl": "请求地址", -- Gitee From bb51863938a3d2921aad287929ac7f3e1b99b31f Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sat, 15 Jan 2022 12:48:06 +0800 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=20ClientInfo?= =?UTF-8?q?=20=E5=AE=9E=E4=BD=93=E7=B1=BB=E6=96=B9=E4=BE=BF=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Samples/Client.razor | 22 ++++++++++--------- .../Samples/Client.razor.cs | 5 +++-- .../Shared/MainLayout.razor.cs | 5 +++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/BootstrapBlazor.Shared/Samples/Client.razor b/src/BootstrapBlazor.Shared/Samples/Client.razor index c44d0bffd..64ca9d420 100644 --- a/src/BootstrapBlazor.Shared/Samples/Client.razor +++ b/src/BootstrapBlazor.Shared/Samples/Client.razor @@ -33,13 +33,15 @@ [NotNull] private WebClientService? ClientService { get; set; } +private ClientInfo? ClientInfo { get; set; } + protected override async Task OnAfterRenderAsync(bool firstRender) { await base.OnAfterRenderAsync(firstRender); if (firstRender) { - await ClientService.RetrieveRemoteInfo(); + ClientInfo = await ClientService.GetClientInfo(); StateHasChanged(); } } @@ -49,31 +51,31 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
- +
- +
- +
- +
- +
- +
- +
- +
- +
diff --git a/src/BootstrapBlazor.Shared/Samples/Client.razor.cs b/src/BootstrapBlazor.Shared/Samples/Client.razor.cs index c2a2196d3..d281dd757 100644 --- a/src/BootstrapBlazor.Shared/Samples/Client.razor.cs +++ b/src/BootstrapBlazor.Shared/Samples/Client.razor.cs @@ -18,6 +18,8 @@ public partial class Client [NotNull] private WebClientService? ClientService { get; set; } + private ClientInfo ClientInfo { get; set; } = new ClientInfo(); + /// /// /// @@ -29,8 +31,7 @@ public partial class Client if (firstRender) { - await ClientService.RetrieveRemoteInfo(); - + ClientInfo = await ClientService.GetClientInfo(); StateHasChanged(); } } diff --git a/src/BootstrapBlazor.Shared/Shared/MainLayout.razor.cs b/src/BootstrapBlazor.Shared/Shared/MainLayout.razor.cs index 55b09abf0..bd52f98b2 100644 --- a/src/BootstrapBlazor.Shared/Shared/MainLayout.razor.cs +++ b/src/BootstrapBlazor.Shared/Shared/MainLayout.razor.cs @@ -46,9 +46,10 @@ public partial class MainLayout : IDisposable if (entry.Entry != null) { // 获得当前用户 IP 地址 - if (await ClientService.RetrieveRemoteInfo() && ClientService.Ip != null) + var clientInfo = await ClientService.GetClientInfo(); + if (clientInfo.Ip != null) { - var location = await IPLocator.Locate(ClientService.Ip); + var location = await IPLocator.Locate(clientInfo.Ip); await Toast.Show(new ToastOption() { Title = "Dispatch 服务测试", -- Gitee From 28ccfcdb9f7d273990653fe0e8c319e3efbd70b3 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sat, 15 Jan 2022 12:48:21 +0800 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20=E6=A0=B9=E6=8D=AE=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E6=9B=B4=E6=94=B9=20Locator=20=E5=86=85=E9=83=A8?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Shared/Samples/Locator.razor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor.Shared/Samples/Locator.razor.cs b/src/BootstrapBlazor.Shared/Samples/Locator.razor.cs index a720635a7..5cf67b73c 100644 --- a/src/BootstrapBlazor.Shared/Samples/Locator.razor.cs +++ b/src/BootstrapBlazor.Shared/Samples/Locator.razor.cs @@ -37,8 +37,8 @@ public partial class Locator if (firstRender) { - await ClientService.RetrieveRemoteInfo(); - Ip = ClientService.Ip; + var clientInfo = await ClientService.GetClientInfo(); + Ip = clientInfo.Ip; StateHasChanged(); } } -- Gitee From ccaefa85340793d4e9412ada9a38f3b1e3a29f43 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sat, 15 Jan 2022 12:51:12 +0800 Subject: [PATCH 5/5] chore: bump version to beta08 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 693e87e58..be41c7a41 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 6.2.7-beta07 + 6.2.7-beta08 -- Gitee