From 1679565888c15710659a6d76c34de9b8fa41fba3 Mon Sep 17 00:00:00 2001 From: "2248356998 qq.com" <2248356998@qq.com> Date: Fri, 12 Dec 2025 11:19:14 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20QueryPageOptions=20jso?= =?UTF-8?q?n=E5=BA=8F=E5=88=97=E5=8C=96=E5=A4=B1=E8=B4=A5=E4=BE=8B?= =?UTF-8?q?=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Samples/Table/TablesFilter.razor.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs index f866e2c678d..3aa3fa9b8f8 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs @@ -1,8 +1,10 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone +using System.Text.Json; + namespace BootstrapBlazor.Server.Components.Samples.Table; /// @@ -48,6 +50,12 @@ private async Task> OnGetAddressItemsAsync() private Task> OnQueryAsync(QueryPageOptions options) { + + //增加filter,序列化不通过 + var json = JsonSerializer.Serialize(options); + var op = JsonSerializer.Deserialize(json); + + // 通过 options 获得用户组合的过滤条件 var filters = options.ToFilter(); From d2db59e522a5c27873bd8f73b2e4d6ef16f6c66a Mon Sep 17 00:00:00 2001 From: "2248356998 qq.com" <2248356998@qq.com> Date: Fri, 12 Dec 2025 15:35:34 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Samples/Table/TablesFilter.razor.cs | 2 +- .../Filters/FilterKeyValueAction.cs | 3 +- .../Components/Table/Table.razor.Edit.cs | 2 +- .../Converter/JsonQueryPageOptionConverter.cs | 117 ++---------------- .../Converter/ObjectWithTypeConverter.cs | 34 +++++ .../Extensions/QueryPageOptionsExtensions.cs | 4 +- .../Options/QueryPageOptions.cs | 13 +- 7 files changed, 64 insertions(+), 111 deletions(-) create mode 100644 src/BootstrapBlazor/Converter/ObjectWithTypeConverter.cs diff --git a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs index 3aa3fa9b8f8..ea6df272697 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs @@ -51,7 +51,7 @@ private async Task> OnGetAddressItemsAsync() private Task> OnQueryAsync(QueryPageOptions options) { - //增加filter,序列化不通过 + //增加filter,序列化测试通过 var json = JsonSerializer.Serialize(options); var op = JsonSerializer.Deserialize(json); diff --git a/src/BootstrapBlazor/Components/Filters/FilterKeyValueAction.cs b/src/BootstrapBlazor/Components/Filters/FilterKeyValueAction.cs index 6586227bc66..ccae1945a18 100644 --- a/src/BootstrapBlazor/Components/Filters/FilterKeyValueAction.cs +++ b/src/BootstrapBlazor/Components/Filters/FilterKeyValueAction.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone @@ -20,6 +20,7 @@ public class FilterKeyValueAction /// /// 获得/设置 Filter 项字段值 /// + [JsonConverter(typeof(ObjectWithTypeConverter))] public object? FieldValue { get; set; } /// diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs b/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs index dca2cde199f..86171f93ed1 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone diff --git a/src/BootstrapBlazor/Converter/JsonQueryPageOptionConverter.cs b/src/BootstrapBlazor/Converter/JsonQueryPageOptionConverter.cs index d4c9620a95e..9de0c633ee6 100644 --- a/src/BootstrapBlazor/Converter/JsonQueryPageOptionConverter.cs +++ b/src/BootstrapBlazor/Converter/JsonQueryPageOptionConverter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone @@ -104,80 +104,14 @@ public class JsonQueryPageOptionsConverter : JsonConverter reader.Read(); ret.IsVirtualScroll = reader.GetBoolean(); } - else if (propertyName == "searches") + + else if (propertyName == "filterKeyValueAction") { reader.Read(); - if (reader.TokenType == JsonTokenType.StartArray) - { - while (reader.Read()) - { - if (reader.TokenType == JsonTokenType.EndArray) - { - break; - } - var val = JsonSerializer.Deserialize(ref reader, options); - if (val != null) - { - ret.Searches.Add(val); - } - } - } - } - else if (propertyName == "customerSearches") - { - reader.Read(); - if (reader.TokenType == JsonTokenType.StartArray) - { - while (reader.Read()) - { - if (reader.TokenType == JsonTokenType.EndArray) - { - break; - } - var val = JsonSerializer.Deserialize(ref reader, options); - if (val != null) - { - ret.CustomerSearches.Add(val); - } - } - } - } - else if (propertyName == "advanceSearches") - { - reader.Read(); - if (reader.TokenType == JsonTokenType.StartArray) - { - while (reader.Read()) - { - if (reader.TokenType == JsonTokenType.EndArray) - { - break; - } - var val = JsonSerializer.Deserialize(ref reader, options); - if (val != null) - { - ret.AdvanceSearches.Add(val); - } - } - } - } - else if (propertyName == "filters") - { - reader.Read(); - if (reader.TokenType == JsonTokenType.StartArray) + var val = JsonSerializer.Deserialize(ref reader, options); + if (val != null) { - while (reader.Read()) - { - if (reader.TokenType == JsonTokenType.EndArray) - { - break; - } - var val = JsonSerializer.Deserialize(ref reader, options); - if (val != null) - { - ret.Filters.Add(val); - } - } + ret.FilterKeyValueAction = val; } } else if (propertyName == "isFirstQuery") @@ -252,41 +186,12 @@ public override void Write(Utf8JsonWriter writer, QueryPageOptions value, JsonSe { writer.WriteBoolean("isVirtualScroll", value.IsVirtualScroll); } - if (value.Searches.Count != 0) - { - writer.WriteStartArray("searches"); - foreach (var filter in value.Searches) - { - writer.WriteRawValue(JsonSerializer.Serialize(filter, options)); - } - writer.WriteEndArray(); - } - if (value.CustomerSearches.Count != 0) - { - writer.WriteStartArray("customerSearches"); - foreach (var filter in value.CustomerSearches) - { - writer.WriteRawValue(JsonSerializer.Serialize(filter, options)); - } - writer.WriteEndArray(); - } - if (value.AdvanceSearches.Count != 0) - { - writer.WriteStartArray("advanceSearches"); - foreach (var filter in value.AdvanceSearches) - { - writer.WriteRawValue(JsonSerializer.Serialize(filter, options)); - } - writer.WriteEndArray(); - } - if (value.Filters.Count != 0) + + if (value.Searches.Count != 0||value.CustomerSearches.Count != 0||value.AdvanceSearches.Count != 0|| value.Filters.Count != 0) { - writer.WriteStartArray("filters"); - foreach (var filter in value.Filters) - { - writer.WriteRawValue(JsonSerializer.Serialize(filter, options)); - } - writer.WriteEndArray(); + writer.WritePropertyName("filterKeyValueAction"); + var filterKeyValueAction = value.ToFilter(); + writer.WriteRawValue(JsonSerializer.Serialize(filterKeyValueAction, options)); } if (value.IsFirstQuery) { diff --git a/src/BootstrapBlazor/Converter/ObjectWithTypeConverter.cs b/src/BootstrapBlazor/Converter/ObjectWithTypeConverter.cs new file mode 100644 index 00000000000..4833decaf0f --- /dev/null +++ b/src/BootstrapBlazor/Converter/ObjectWithTypeConverter.cs @@ -0,0 +1,34 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License +// See the LICENSE file in the project root for more information. +// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone + +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace BootstrapBlazor.Components; + +internal class ObjectWithTypeConverter : JsonConverter +{ + public override object? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + using var doc = JsonDocument.ParseValue(ref reader); + + if (!doc.RootElement.TryGetProperty("$type", out var typeProp)) + return doc.RootElement.Clone(); // 无类型信息 + + var type = Type.GetType(typeProp.GetString()!)!; + + var valueElement = doc.RootElement.GetProperty("value"); + return JsonSerializer.Deserialize(valueElement.GetRawText(), type, options); + } + + public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + writer.WriteString("$type", value.GetType().AssemblyQualifiedName); + writer.WritePropertyName("value"); + JsonSerializer.Serialize(writer, value, value.GetType(), options); + writer.WriteEndObject(); + } +} diff --git a/src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs b/src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs index cf3c52ce585..af30e09225f 100644 --- a/src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs +++ b/src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone @@ -19,6 +19,8 @@ public static class QueryPageOptionsExtensions /// public static FilterKeyValueAction ToFilter(this QueryPageOptions option) { + if(option.FilterKeyValueAction!=null) return option.FilterKeyValueAction; + var filter = new FilterKeyValueAction(); // 处理模糊搜索 diff --git a/src/BootstrapBlazor/Options/QueryPageOptions.cs b/src/BootstrapBlazor/Options/QueryPageOptions.cs index 9e41df89652..1df052e63c8 100644 --- a/src/BootstrapBlazor/Options/QueryPageOptions.cs +++ b/src/BootstrapBlazor/Options/QueryPageOptions.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone @@ -41,6 +41,7 @@ public class QueryPageOptions /// /// 获得 搜索条件绑定模型 未设置 时为 泛型模型 /// + [JsonConverter(typeof(ObjectWithTypeConverter))] public object? SearchModel { get; set; } /// @@ -79,6 +80,7 @@ public class QueryPageOptions /// /// 获得 通过列集合中的 列与 拼装 IFilterAction 集合 /// + [JsonIgnore] public List Searches { get; } = new(20); /// @@ -91,6 +93,7 @@ public class QueryPageOptions /// /// 获得 中过滤条件 模板中的条件请使用 获得 /// + [JsonIgnore] public List CustomerSearches { get; } = new(20); /// @@ -103,13 +106,21 @@ public class QueryPageOptions /// /// 获得 中过滤条件 /// + [JsonIgnore] public List AdvanceSearches { get; } = new(20); /// /// 获得 过滤条件集合 等同于 值 /// + [JsonIgnore] public List Filters { get; } = new(20); + /// + /// Gets or sets the action to take when filtering key-value pairs during processing. + /// + [JsonIgnore] + internal FilterKeyValueAction? FilterKeyValueAction { get; set; } + /// /// 获得 是否为首次查询 默认 false /// From 0bbbb21c28f60f384224332f0aa6401f12a7621a Mon Sep 17 00:00:00 2001 From: "2248356998 qq.com" <2248356998@qq.com> Date: Fri, 12 Dec 2025 15:42:38 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Samples/Table/TablesFilter.razor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs index ea6df272697..ffd8c63fb1e 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs @@ -53,7 +53,7 @@ private Task> OnQueryAsync(QueryPageOptions options) //增加filter,序列化测试通过 var json = JsonSerializer.Serialize(options); - var op = JsonSerializer.Deserialize(json); + options = JsonSerializer.Deserialize(json); // 通过 options 获得用户组合的过滤条件 From 1fb327a135afea4c859f44105607a3d98dc413c0 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 12 Dec 2025 19:53:07 +0800 Subject: [PATCH 4/7] =?UTF-8?q?revert:=20=E6=92=A4=E9=94=80=E6=9B=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Samples/Table/TablesFilter.razor.cs | 8 -------- src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs index ffd8c63fb1e..513327b3ea8 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs @@ -3,8 +3,6 @@ // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone -using System.Text.Json; - namespace BootstrapBlazor.Server.Components.Samples.Table; /// @@ -50,12 +48,6 @@ private async Task> OnGetAddressItemsAsync() private Task> OnQueryAsync(QueryPageOptions options) { - - //增加filter,序列化测试通过 - var json = JsonSerializer.Serialize(options); - options = JsonSerializer.Deserialize(json); - - // 通过 options 获得用户组合的过滤条件 var filters = options.ToFilter(); diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs b/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs index 86171f93ed1..dca2cde199f 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone From ebb0ac1c737628f6f65d1b5a294912e264dbac22 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 12 Dec 2025 19:55:17 +0800 Subject: [PATCH 5/7] =?UTF-8?q?revert:=20=E6=92=A4=E9=94=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Samples/Table/TablesFilter.razor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs index 513327b3ea8..f866e2c678d 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/Table/TablesFilter.razor.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone From 439ea7350a0d5549bc6906cc281a629df789c468 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 12 Dec 2025 19:56:23 +0800 Subject: [PATCH 6/7] =?UTF-8?q?refactor:=20=E4=BB=A3=E7=A0=81=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs b/src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs index af30e09225f..2e5731908a7 100644 --- a/src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs +++ b/src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs @@ -19,7 +19,7 @@ public static class QueryPageOptionsExtensions /// public static FilterKeyValueAction ToFilter(this QueryPageOptions option) { - if(option.FilterKeyValueAction!=null) return option.FilterKeyValueAction; + if (option.FilterKeyValueAction != null) return option.FilterKeyValueAction; var filter = new FilterKeyValueAction(); From 59e52e85f3d74eb9a3098e338044f7b1b31cc6f4 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 12 Dec 2025 19:59:59 +0800 Subject: [PATCH 7/7] =?UTF-8?q?doc:=20=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Diego <82756760+kimdiego2098@users.noreply.github.com> --- src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs b/src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs index 2e5731908a7..3a83629ac8b 100644 --- a/src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs +++ b/src/BootstrapBlazor/Extensions/QueryPageOptionsExtensions.cs @@ -19,6 +19,7 @@ public static class QueryPageOptionsExtensions /// public static FilterKeyValueAction ToFilter(this QueryPageOptions option) { + // 后续再更改 if (option.FilterKeyValueAction != null) return option.FilterKeyValueAction; var filter = new FilterKeyValueAction();