From 3610c1e89fbdb7a48218509581d0220699fa72f1 Mon Sep 17 00:00:00 2001 From: Argo Date: Tue, 30 Mar 2021 13:03:49 +0800 Subject: [PATCH] =?UTF-8?q?!1229=20docs(#I3E6RM):=20update=20Table=20Colum?= =?UTF-8?q?n=20sample=20code=20*=20docs:=20=E6=9B=B4=E6=96=B0=E5=88=97?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E6=96=87=E6=A1=A3=20*=20chore:=20update=20nu?= =?UTF-8?q?get=20package=20source=20*=20chore:=20update=20eidtorconfig=20f?= =?UTF-8?q?ile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 4 +- NuGet.Config | 3 +- .../Pages/Samples/Table/TablesBaseColumn.cs | 65 --------- .../Pages/Samples/Table/TablesColumn.razor | 4 +- .../Pages/Samples/Table/TablesColumn.razor.cs | 129 ++++++++++++++++++ 5 files changed, 134 insertions(+), 71 deletions(-) delete mode 100644 src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesBaseColumn.cs create mode 100644 src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesColumn.razor.cs diff --git a/.editorconfig b/.editorconfig index 04875a7e0..4a2590edd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -64,8 +64,8 @@ dotnet_style_explicit_tuple_names = true:suggestion dotnet_style_null_propagation = true:suggestion dotnet_style_coalesce_expression = true:suggestion dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent -dotnet_prefer_inferred_tuple_names = true:suggestion -dotnet_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion dotnet_style_prefer_auto_properties = true:silent dotnet_style_prefer_conditional_expression_over_assignment = true:silent dotnet_style_prefer_conditional_expression_over_return = true:silent diff --git a/NuGet.Config b/NuGet.Config index 93ead7f9a..e8e354d1f 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,8 @@ - + + diff --git a/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesBaseColumn.cs b/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesBaseColumn.cs deleted file mode 100644 index 8d93032d8..000000000 --- a/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesBaseColumn.cs +++ /dev/null @@ -1,65 +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 BootstrapBlazor.Components; -using BootstrapBlazor.Shared.Pages.Components; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace BootstrapBlazor.Shared.Pages -{ - /// - /// - /// - public abstract class TablesBaseColumn : TablesBaseQuery - { - /// - /// - /// - /// - /// - protected Task IntFormatter(object? d) - { - var data = (int?)d; - return Task.FromResult(data?.ToString("0.00") ?? ""); - } - - /// - /// - /// - /// - protected Task CustomerButton(IEnumerable items) - { - var cate = ToastCategory.Information; - var title = "自定义按钮处理方法"; - var content = $"通过不同的函数区分按钮处理逻辑,参数 Items 为 Table 组件中选中的行数据集合,当前选择数据 {items.Count()} 条"; - ToastService?.Show(new ToastOption() - { - Category = cate, - Title = title, - Content = content - }); - return Task.CompletedTask; - } - - /// - /// - /// - /// - protected Task OnRowButtonClick(Foo item) - { - var cate = ToastCategory.Success; - var title = "行内按钮处理方法"; - var content = "通过不同的函数区分按钮处理逻辑,参数 Item 为当前行数据"; - ToastService?.Show(new ToastOption() - { - Category = cate, - Title = title, - Content = content - }); - return Task.CompletedTask; - } - } -} diff --git a/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesColumn.razor b/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesColumn.razor index 7819c8ef8..450a3b756 100644 --- a/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesColumn.razor +++ b/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesColumn.razor @@ -1,6 +1,4 @@ -@using Foo = BootstrapBlazor.Shared.Pages.Components.Foo -@inherits TablesBaseColumn -@page "/tables/column" +@page "/tables/column"

Table 表格

diff --git a/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesColumn.razor.cs b/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesColumn.razor.cs new file mode 100644 index 000000000..30cdee718 --- /dev/null +++ b/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesColumn.razor.cs @@ -0,0 +1,129 @@ +// 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 BootstrapBlazor.Components; +using BootstrapBlazor.Shared.Pages.Components; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Threading.Tasks; + +namespace BootstrapBlazor.Shared.Pages.Table +{ + /// + /// Table 组件列属性示例代码 + /// + public partial class TablesColumn + { + private static readonly ConcurrentDictionary, string, SortOrder, IEnumerable>> SortLambdaCache = new(); + + [NotNull] + private List? Items { get; set; } + + [Inject] + [NotNull] + private IStringLocalizer? Localizer { get; set; } + + [Inject] + [NotNull] + private ToastService? ToastService { get; set; } + private static IEnumerable PageItemsSource => new int[] { 4, 10, 20 }; + + /// + /// OnInitialized 方法 + /// + protected override void OnInitialized() + { + base.OnInitialized(); + + Items = Foo.GenerateFoo(Localizer); + } + + /// + /// + /// + /// + /// + protected static Task IntFormatter(object? d) + { + var data = (int?)d; + return Task.FromResult(data?.ToString("0.00") ?? ""); + } + + private Task> OnQueryAsync(QueryPageOptions options) + { + IEnumerable items = Items; + + // 过滤 + var isFiltered = false; + if (options.Filters.Any()) + { + items = items.Where(options.Filters.GetFilterFunc()); + isFiltered = true; + } + + // 排序 + var isSorted = false; + if (!string.IsNullOrEmpty(options.SortName)) + { + var invoker = SortLambdaCache.GetOrAdd(typeof(Foo), key => LambdaExtensions.GetSortLambda().Compile()); + items = invoker(items, options.SortName, options.SortOrder); + isSorted = true; + } + + // 设置记录总数 + var total = items.Count(); + + // 内存分页 + items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList(); + + return Task.FromResult(new QueryData() + { + Items = items, + TotalCount = total, + IsSorted = isSorted, + IsFiltered = isFiltered, + IsSearch = true + }); + } + + /// + /// + /// + /// + protected async Task CustomerButton(IEnumerable items) + { + var cate = ToastCategory.Information; + var title = "自定义按钮处理方法"; + var content = $"通过不同的函数区分按钮处理逻辑,参数 Items 为 Table 组件中选中的行数据集合,当前选择数据 {items.Count()} 条"; + await ToastService.Show(new ToastOption() + { + Category = cate, + Title = title, + Content = content + }); + } + + /// + /// + /// + /// + protected async Task OnRowButtonClick(Foo item) + { + var cate = ToastCategory.Success; + var title = "行内按钮处理方法"; + var content = "通过不同的函数区分按钮处理逻辑,参数 Item 为当前行数据"; + await ToastService.Show(new ToastOption() + { + Category = cate, + Title = title, + Content = content + }); + } + } +}