Skip to content

Commit

Permalink
feat(TableExportOptions): add TableExportOptions class for Table expo…
Browse files Browse the repository at this point in the history
…rt (#3246)

* feat: 增加 TableExportOptions

* feat: ITableExport 导出方法增加 TableExportOptions 类

* chore: bump version 8.4.2-beta02

* test: 增加单元测试
  • Loading branch information
ArgoZhang authored Apr 9, 2024
1 parent 09ab7e2 commit 46a731e
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>8.4.2-beta01</Version>
<Version>8.4.2-beta02</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Options/BootstrapBlazorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ public class BootstrapBlazorOptions : IOptions<BootstrapBlazorOptions>
public string? JSModuleVersion { get; set; }

/// <summary>
/// 获得/设置 ConnectionHubOptions 配置 默认为 null
/// 获得/设置 ConnectionHubOptions 配置 默认为不为空
/// </summary>
public ConnectionHubOptions ConnectionHubOptions { get; set; } = new();

/// <summary>
/// 获得/设置 IpLocatorOptions 配置 默认为 null
/// 获得/设置 IpLocatorOptions 配置 默认为不为空
/// </summary>
public IpLocatorOptions IpLocatorOptions { get; set; } = new();

Expand Down
40 changes: 40 additions & 0 deletions src/BootstrapBlazor/Options/TableExportOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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 System.ComponentModel;

namespace BootstrapBlazor.Components;

/// <summary>
/// Table 导出 Excel 配置类
/// </summary>
public class TableExportOptions
{
/// <summary>
/// 获得/设置 是否使用格式化 默认 true 如果设置 <see cref="TableColumn{TItem, TType}.FormatString"/> 或者 <see cref="TableColumn{TItem, TType}.Formatter"/> 后使用格式化值
/// </summary>
/// <remarks>注意格式化后返回值是 <code>string</code> 会导致原始值类型改变</remarks>
public bool EnableFormat { get; set; } = true;

/// <summary>
/// 获得/设置 是否使用 Lookup 默认 true
/// </summary>
public bool EnableLookup { get; set; } = true;

/// <summary>
/// 获得/设置 是否将数组类型值进行合并操作 默认 true
/// </summary>
public bool AutoMergeArray { get; set; } = true;

/// <summary>
/// 获得/设置 是否使用枚举类型的 <see cref="DescriptionAttribute"/> 标签 默认 true
/// </summary>
public bool UseEnumDescription { get; set; } = true;

/// <summary>
/// 获得/设置 数组类型合并操作时使用的分隔符 默认使用逗号
/// </summary>
/// <remarks>注意格式化后返回值是 <code>string</code> 会导致原始值类型改变</remarks>
public string ArrayDelimiter { get; set; } = ",";
}
5 changes: 5 additions & 0 deletions src/BootstrapBlazor/Options/TableSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ public class TableSettings
/// 获得/设置 表格渲染模式
/// </summary>
public TableRenderMode? TableRenderMode { get; set; }

/// <summary>
/// 获得/设置 TableExportExcelOptions 配置 默认为不为空
/// </summary>
public TableExportOptions TableExportOptions { get; set; } = new();
}
10 changes: 6 additions & 4 deletions src/BootstrapBlazor/Services/DefaultTableExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DefaultTableExport : ITableExport
/// <inheritdoc/>
/// </summary>
/// <returns></returns>
public Task<bool> ExportAsync<TItem>(IEnumerable<TItem> items, IEnumerable<ITableColumn>? cols = null, string? fileName = null)
public Task<bool> ExportAsync<TItem>(IEnumerable<TItem> items, IEnumerable<ITableColumn>? cols = null, string? fileName = null, TableExportOptions? options = null)
{
return Task.FromResult(false);
}
Expand All @@ -19,7 +19,7 @@ public Task<bool> ExportAsync<TItem>(IEnumerable<TItem> items, IEnumerable<ITabl
/// <inheritdoc/>
/// </summary>
/// <returns></returns>
public Task<bool> ExportExcelAsync<TItem>(IEnumerable<TItem> items, IEnumerable<ITableColumn>? cols = null, string? fileName = null)
public Task<bool> ExportExcelAsync<TItem>(IEnumerable<TItem> items, IEnumerable<ITableColumn>? cols = null, string? fileName = null, TableExportOptions? options = null)
{
return Task.FromResult(false);
}
Expand All @@ -31,8 +31,9 @@ public Task<bool> ExportExcelAsync<TItem>(IEnumerable<TItem> items, IEnumerable<
/// <param name="items"></param>
/// <param name="cols"></param>
/// <param name="fileName"></param>
/// <param name="options"></param>
/// <returns></returns>
public Task<bool> ExportCsvAsync<TItem>(IEnumerable<TItem> items, IEnumerable<ITableColumn>? cols, string? fileName = null)
public Task<bool> ExportCsvAsync<TItem>(IEnumerable<TItem> items, IEnumerable<ITableColumn>? cols, string? fileName = null, TableExportOptions? options = null)
{
return Task.FromResult(false);
}
Expand All @@ -44,8 +45,9 @@ public Task<bool> ExportCsvAsync<TItem>(IEnumerable<TItem> items, IEnumerable<IT
/// <param name="items"></param>
/// <param name="cols"></param>
/// <param name="fileName"></param>
/// <param name="options"></param>
/// <returns></returns>
public Task<bool> ExportPdfAsync<TItem>(IEnumerable<TItem> items, IEnumerable<ITableColumn>? cols, string? fileName = null)
public Task<bool> ExportPdfAsync<TItem>(IEnumerable<TItem> items, IEnumerable<ITableColumn>? cols, string? fileName = null, TableExportOptions? options = null)
{
return Task.FromResult(false);
}
Expand Down
12 changes: 8 additions & 4 deletions src/BootstrapBlazor/Services/ITableExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,33 @@ public interface ITableExport
/// <param name="items">导出数据集合</param>
/// <param name="cols">当前可见列数据集合 默认 null 导出全部列</param>
/// <param name="fileName">文件名 默认 null ExportData_{DateTime.Now:yyyyMMddHHmmss}.xlsx</param>
Task<bool> ExportAsync<TModel>(IEnumerable<TModel> items, IEnumerable<ITableColumn>? cols, string? fileName = null);
/// <param name="options">导出配置实例</param>
Task<bool> ExportAsync<TModel>(IEnumerable<TModel> items, IEnumerable<ITableColumn>? cols, string? fileName = null, TableExportOptions? options = null);

/// <summary>
/// 导出 Excel 方法
/// </summary>
/// <param name="items">导出数据集合</param>
/// <param name="cols">当前可见列数据集合 默认 null 导出全部列</param>
/// <param name="fileName">文件名 默认 null ExportData_{DateTime.Now:yyyyMMddHHmmss}.xlsx</param>
Task<bool> ExportExcelAsync<TModel>(IEnumerable<TModel> items, IEnumerable<ITableColumn>? cols, string? fileName = null);
/// <param name="options">导出配置实例</param>
Task<bool> ExportExcelAsync<TModel>(IEnumerable<TModel> items, IEnumerable<ITableColumn>? cols, string? fileName = null, TableExportOptions? options = null);

/// <summary>
/// 导出 Csv 方法
/// </summary>
/// <param name="items">导出数据集合</param>
/// <param name="cols">当前可见列数据集合 默认 null 导出全部列</param>
/// <param name="fileName">文件名 默认 null ExportData_{DateTime.Now:yyyyMMddHHmmss}.xlsx</param>
Task<bool> ExportCsvAsync<TModel>(IEnumerable<TModel> items, IEnumerable<ITableColumn>? cols, string? fileName = null);
/// <param name="options">导出配置实例</param>
Task<bool> ExportCsvAsync<TModel>(IEnumerable<TModel> items, IEnumerable<ITableColumn>? cols, string? fileName = null, TableExportOptions? options = null);

/// <summary>
/// 导出 Pdf 方法
/// </summary>
/// <param name="items">导出数据集合</param>
/// <param name="cols">当前可见列数据集合 默认 null 导出全部列</param>
/// <param name="fileName">文件名 默认 null ExportData_{DateTime.Now:yyyyMMddHHmmss}.xlsx</param>
Task<bool> ExportPdfAsync<TModel>(IEnumerable<TModel> items, IEnumerable<ITableColumn>? cols, string? fileName = null);
/// <param name="options">导出配置实例</param>
Task<bool> ExportPdfAsync<TModel>(IEnumerable<TModel> items, IEnumerable<ITableColumn>? cols, string? fileName = null, TableExportOptions? options = null);
}
22 changes: 22 additions & 0 deletions test/UnitTest/Options/BootstrapBlazorOptionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,26 @@ public void Options_StepSettings()
Assert.Equal("0.01", options.GetStep<double?>());
Assert.Equal("0.001", options.GetStep<decimal?>());
}

[Fact]
public void Options_TableExportOptions()
{
var options = new BootstrapBlazorOptions();
Assert.NotNull(options.TableSettings.TableExportOptions);

var exportOptions = options.TableSettings.TableExportOptions;

exportOptions.EnableLookup = false;
exportOptions.EnableFormat = false;
exportOptions.AutoMergeArray = false;
exportOptions.ArrayDelimiter = ",";
exportOptions.UseEnumDescription = false;

Assert.False(exportOptions.EnableLookup);
Assert.False(exportOptions.EnableFormat);
Assert.False(exportOptions.AutoMergeArray);
Assert.False(exportOptions.UseEnumDescription);

Assert.Equal(",", exportOptions.ArrayDelimiter);
}
}

0 comments on commit 46a731e

Please sign in to comment.