From 4a2cf1dea11373a04210f7222a334ff6802ba739 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 25 Feb 2025 18:06:49 +0800 Subject: [PATCH 1/7] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=20toJson=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/wwwroot/modules/ajax.js | 31 ++++++++++----------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/BootstrapBlazor/wwwroot/modules/ajax.js b/src/BootstrapBlazor/wwwroot/modules/ajax.js index 366967c4b66..85309447753 100644 --- a/src/BootstrapBlazor/wwwroot/modules/ajax.js +++ b/src/BootstrapBlazor/wwwroot/modules/ajax.js @@ -3,6 +3,7 @@ method: 'POST', url: null, data: null, + toJson: true, ...option } @@ -11,27 +12,25 @@ return null } - const init = { - method: option.method, - headers: { - 'Content-Type': 'application/json' - } - } - - if (option.method === 'POST' && option.data) { - init.body = JSON.stringify(option.data) - } - - let json = null; + let result = null; try { - - const response = await fetch(option.url, init) - json = await response.json() + const toJson = opitons.toJson; + delete options.toJson; + result = await fetch(option.url, { + method: option.method, + headers: { + 'Content-Type': 'application/json' + }, + body: option.method === 'POST' ? JSON.stringify(option.data) : null + }); + if (toJson === true) { + result = await result.json() + } } catch (e) { console.info(e); } - return json + return result } export function goto(url) { From e31de7a5851bee79923caad724d89493803fbc9d Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 25 Feb 2025 18:09:22 +0800 Subject: [PATCH 2/7] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=20ToJson=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/Ajax/AjaxOption.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/BootstrapBlazor/Components/Ajax/AjaxOption.cs b/src/BootstrapBlazor/Components/Ajax/AjaxOption.cs index e526fcc9739..c28e1c12e4a 100644 --- a/src/BootstrapBlazor/Components/Ajax/AjaxOption.cs +++ b/src/BootstrapBlazor/Components/Ajax/AjaxOption.cs @@ -26,4 +26,10 @@ public class AjaxOption /// [NotNull] public string? Url { get; set; } + + /// + /// 获得/设置 是否获得序列化 Json 结果 参数 默认为 true + /// + [NotNull] + public bool ToJson { get; set; } } From e3502bce702cdf4a1b7af8d3bfbf3e2b50a5cb65 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 25 Feb 2025 18:09:30 +0800 Subject: [PATCH 3/7] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/AjaxTest.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/UnitTest/Components/AjaxTest.cs b/test/UnitTest/Components/AjaxTest.cs index 98222ad4c14..b9fea2f3a58 100644 --- a/test/UnitTest/Components/AjaxTest.cs +++ b/test/UnitTest/Components/AjaxTest.cs @@ -14,7 +14,8 @@ public async Task Ajax_Test() { Url = "/api/Login", Method = "POST", - Data = new { UserName = "admin", Password = "1234567" } + Data = new { UserName = "admin", Password = "1234567" }, + ToJson = false }; Assert.Equal("/api/Login", option.Url); Assert.Equal("POST", option.Method); From b5f3be5ec31436018ddbc99d8bcc380d401a4fe0 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 25 Feb 2025 18:10:05 +0800 Subject: [PATCH 4/7] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/AjaxTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/UnitTest/Components/AjaxTest.cs b/test/UnitTest/Components/AjaxTest.cs index b9fea2f3a58..9ba34065910 100644 --- a/test/UnitTest/Components/AjaxTest.cs +++ b/test/UnitTest/Components/AjaxTest.cs @@ -19,6 +19,7 @@ public async Task Ajax_Test() }; Assert.Equal("/api/Login", option.Url); Assert.Equal("POST", option.Method); + Assert.False(option.ToJson); Assert.NotNull(option.Data); var service = Context.Services.GetRequiredService(); From bda4c25c87e3106021b6eef4b16a1beb9d0dd6e4 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 25 Feb 2025 18:51:20 +0800 Subject: [PATCH 5/7] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=AD=A3=E5=8D=95?= =?UTF-8?q?=E8=AF=8D=E6=8B=BC=E5=86=99=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/wwwroot/modules/ajax.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor/wwwroot/modules/ajax.js b/src/BootstrapBlazor/wwwroot/modules/ajax.js index 85309447753..4ca28e56556 100644 --- a/src/BootstrapBlazor/wwwroot/modules/ajax.js +++ b/src/BootstrapBlazor/wwwroot/modules/ajax.js @@ -14,8 +14,8 @@ let result = null; try { - const toJson = opitons.toJson; - delete options.toJson; + const toJson = option.toJson; + delete option.toJson; result = await fetch(option.url, { method: option.method, headers: { From 66227ae014ebeb9af03c842248c32a9abf2fbce0 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 25 Feb 2025 19:43:42 +0800 Subject: [PATCH 6/7] chore: bump version 9.3.1-beta34 --- 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 96cbdeff417..6a509ca7282 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 9.3.1-beta33 + 9.3.1-beta34 From ecfa81174c5cfb0578d1c01634970d2229b5a6e7 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 25 Feb 2025 19:49:05 +0800 Subject: [PATCH 7/7] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=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/wwwroot/modules/ajax.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/BootstrapBlazor/wwwroot/modules/ajax.js b/src/BootstrapBlazor/wwwroot/modules/ajax.js index 4ca28e56556..793d042c6b4 100644 --- a/src/BootstrapBlazor/wwwroot/modules/ajax.js +++ b/src/BootstrapBlazor/wwwroot/modules/ajax.js @@ -14,14 +14,13 @@ let result = null; try { - const toJson = option.toJson; - delete option.toJson; - result = await fetch(option.url, { - method: option.method, + const { toJson, url, method, data } = option; + result = await fetch(url, { + method: method, headers: { 'Content-Type': 'application/json' }, - body: option.method === 'POST' ? JSON.stringify(option.data) : null + body: method === 'POST' ? JSON.stringify(data) : null }); if (toJson === true) { result = await result.json()