From ec00e69ce6636fd65277bbf04ec698ef93456174 Mon Sep 17 00:00:00 2001 From: utilcore <8907060@qq.com> Date: Sun, 18 Feb 2024 15:07:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BA=95=E9=83=A8=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E6=A0=8F=E6=A0=87=E7=AD=BE,=20?= =?UTF-8?q?=E5=B0=81=E8=A3=85=20Ng-Alain=20=E5=BA=95=E9=83=A8=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E6=A0=8F=20=20=E7=BB=84=E4=BB=B6.=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9F=A5=E8=AF=A2=E8=A1=A8=E5=8D=95=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=20,=E8=87=AA=E5=8A=A8=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=86=85=E9=83=A8=E6=A0=85=E6=A0=BC=E5=88=97=20span.?= =?UTF-8?q?=20=20=E6=A0=87=E7=AD=BE=E6=96=B0=E5=A2=9E=20enable?= =?UTF-8?q?-custom-column=20=E5=B1=9E=E6=80=A7,=E5=BC=80=E5=90=AF=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=88=97=E8=AE=BE=E7=BD=AE.=20=20?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=96=B0=E5=A2=9E=20show-table-settings=20?= =?UTF-8?q?=E5=B1=9E=E6=80=A7,=E7=82=B9=E5=87=BB=E5=BC=B9=E5=87=BA?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E8=87=AA=E5=AE=9A=E4=B9=89=E5=88=97=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E7=95=8C=E9=9D=A2.=20=20=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=20is-search=20=E5=B1=9E=E6=80=A7,=20?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=85=B7=E6=9C=89=E5=B1=95=E5=BC=80=E5=92=8C?= =?UTF-8?q?=E6=94=B6=E8=B5=B7=E6=95=88=E6=9E=9C=E7=9A=84=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=8C=89=E9=92=AE.=20=E4=BF=AE=E5=A4=8D=20Util.Data.EntityFram?= =?UTF-8?q?eworkCore.StoreBase=20=E6=9B=B4=E6=96=B0=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E5=B9=B6=E5=8F=91=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/version.props | 2 +- .../StoreBase.cs | 16 +- src/Util.Ui.Angular/Configs/AngularConst.cs | 4 + .../Builders/FooterToolbarBuilder.cs | 47 + .../FooterToolbars/FooterToolbarTagHelper.cs | 32 + .../Renders/FooterToolbarRender.cs | 39 + .../Components/Links/ATagHelper.cs | 4 + .../Components/Links/Builders/ABuilder.cs | 26 +- .../Tables/Builders/TableBuilder.cs | 28 +- .../Tables/Builders/TableColumnBuilder.cs | 31 +- .../Tables/Builders/TableHeadColumnBuilder.cs | 49 +- .../Tables/Builders/TableSettingsBuilder.cs | 61 ++ .../Tables/Builders/TotalTemplateBuilder.cs | 3 +- .../Tables/Configs/TableColumnShareConfig.cs | 34 +- .../Configs/TableHeadColumnShareConfig.cs | 42 +- .../Tables/Configs/TableShareConfig.cs | 44 +- .../Components/Tables/Helpers/ColumnInfo.cs | 24 +- .../Components/Tables/Helpers/CustomColumn.cs | 62 ++ .../Tables/Helpers/HeadColumnInfo.cs | 30 + .../Tables/Helpers/TableColumnService.cs | 8 +- .../Tables/Helpers/TableHeadColumnService.cs | 18 +- .../Components/Tables/Helpers/TableService.cs | 18 +- .../Components/Tables/Renders/TableRender.cs | 20 +- .../Components/Tables/TableColumnTagHelper.cs | 8 + .../Tables/TableHeadColumnTagHelper.cs | 9 +- .../Components/Tables/TableTagHelper.cs | 9 +- .../Templates/Builders/TemplateBuilder.cs | 1 - src/Util.Ui.NgZorro/NgZorroOptions.cs | 4 + src/Util.Ui/Configs/UiConst.cs | 20 + .../Tests/ProductRepositoryTest.cs | 26 + .../Fakes/ProductFakeService.cs | 1 + .../EllipsisTagHelperTest.Expression.cs | 18 +- .../Ellipsis/EllipsisTagHelperTest.cs | 166 ++-- .../FooterToolbarTagHelperTest.cs | 94 ++ .../I18n/I18nTagHelperTest.cs | 134 +-- .../PageHeaders/PageHeaderTagHelperTest.cs | 884 +++++++++--------- .../Util.Ui.NgAlain.Tests/Samples/Customer.cs | 154 +-- test/Util.Ui.NgAlain.Tests/Startup.cs | 26 +- .../TinymceTagHelperTest.Expression.cs | 21 +- .../Tinymce/TinymceTagHelperTest.cs | 226 ++--- .../Forms/SearchFormTagHelperTest.cs | 2 +- .../Links/ATagHelperTest.cs | 27 + .../Tables/TableColumnTagHelperTest.cs | 22 + .../Tables/TableHeadColumnTagHelperTest.cs | 22 + .../Tables/TableTagHelperTest.CustomColumn.cs | 492 ++++++++++ .../Tables/TableTagHelperTest.cs | 11 + 46 files changed, 2159 insertions(+), 860 deletions(-) create mode 100644 src/Util.Ui.NgAlain/Components/FooterToolbars/Builders/FooterToolbarBuilder.cs create mode 100644 src/Util.Ui.NgAlain/Components/FooterToolbars/FooterToolbarTagHelper.cs create mode 100644 src/Util.Ui.NgAlain/Components/FooterToolbars/Renders/FooterToolbarRender.cs create mode 100644 src/Util.Ui.NgZorro/Components/Tables/Builders/TableSettingsBuilder.cs create mode 100644 src/Util.Ui.NgZorro/Components/Tables/Helpers/CustomColumn.cs create mode 100644 src/Util.Ui.NgZorro/Components/Tables/Helpers/HeadColumnInfo.cs create mode 100644 test/Util.Ui.NgAlain.Tests/FooterToolbars/FooterToolbarTagHelperTest.cs create mode 100644 test/Util.Ui.NgZorro.Tests/Tables/TableTagHelperTest.CustomColumn.cs diff --git a/build/version.props b/build/version.props index 850226962..202a3baf8 100644 --- a/build/version.props +++ b/build/version.props @@ -4,6 +4,6 @@ 0 1 $(VersionMajor).$(VersionMinor).$(VersionPatch) - pre-6 + \ No newline at end of file diff --git a/src/Util.Data.EntityFrameworkCore/StoreBase.cs b/src/Util.Data.EntityFrameworkCore/StoreBase.cs index 9ac299d15..7ec7824c0 100644 --- a/src/Util.Data.EntityFrameworkCore/StoreBase.cs +++ b/src/Util.Data.EntityFrameworkCore/StoreBase.cs @@ -3,7 +3,7 @@ using Util.Exceptions; using Util.Validation; -namespace Util.Data.EntityFrameworkCore; +namespace Util.Data.EntityFrameworkCore; /// /// 存储器 @@ -133,7 +133,7 @@ public TEntity FindById( object id ) { if ( id.SafeString().IsEmpty() ) return null; var key = GetKey( id ); - if( IsTracking ) + if ( IsTracking ) return Set.Find( key ); return Single( t => t.Id.Equals( key ) ); } @@ -142,7 +142,7 @@ public TEntity FindById( object id ) { /// 获取标识 /// protected object GetKey( object id ) { - if( id is TKey ) + if ( id is TKey ) return id; return Util.Helpers.Convert.To( id ); } @@ -158,7 +158,7 @@ protected object GetKey( object id ) { if ( id.SafeString().IsEmpty() ) return null; var key = GetKey( id ); - if( IsTracking ) + if ( IsTracking ) return await Set.FindAsync( new[] { key }, cancellationToken ); return await SingleAsync( t => t.Id.Equals( key ), cancellationToken ); } @@ -212,7 +212,7 @@ public virtual TEntity Single( Expression> condition ) { } /// - public virtual TEntity Single( Expression> condition,Func, IQueryable> action ) { + public virtual TEntity Single( Expression> condition, Func, IQueryable> action ) { if ( action == null ) return Single( condition ); return action( Find() ).FirstOrDefault( condition ); @@ -328,7 +328,7 @@ public virtual int Count( Expression> condition = null ) { /// protected virtual void Validate( IEnumerable entities ) { entities.CheckNull( nameof( entities ) ); - foreach ( var entity in entities ) + foreach ( var entity in entities ) Validate( entity ); } @@ -337,7 +337,7 @@ protected virtual void Validate( IEnumerable entities ) { /// protected virtual void Validate( TEntity entity ) { entity.CheckNull( nameof( entity ) ); - if ( entity is IValidation validation ) + if ( entity is IValidation validation ) validation.Validate(); } @@ -382,6 +382,8 @@ protected void Update( TEntity entity ) { protected virtual void ValidateVersion( EntityEntry entry, TEntity entity ) { if ( entity is not IVersion current ) return; + if ( entry.State == EntityState.Added ) + return; if ( current.Version == null || current.Version.Length == 0 ) { ThrowConcurrencyException( entity ); return; diff --git a/src/Util.Ui.Angular/Configs/AngularConst.cs b/src/Util.Ui.Angular/Configs/AngularConst.cs index 4cd0aea67..7b91f2114 100644 --- a/src/Util.Ui.Angular/Configs/AngularConst.cs +++ b/src/Util.Ui.Angular/Configs/AngularConst.cs @@ -1700,4 +1700,8 @@ public static class AngularConst { /// 自动换行 /// public const string BindWrap = "bind-wrap"; + /// + /// 单元格控件 + /// + public const string BindCellControl = "bind-cell-control"; } \ No newline at end of file diff --git a/src/Util.Ui.NgAlain/Components/FooterToolbars/Builders/FooterToolbarBuilder.cs b/src/Util.Ui.NgAlain/Components/FooterToolbars/Builders/FooterToolbarBuilder.cs new file mode 100644 index 000000000..97c5037e0 --- /dev/null +++ b/src/Util.Ui.NgAlain/Components/FooterToolbars/Builders/FooterToolbarBuilder.cs @@ -0,0 +1,47 @@ +using Util.Ui.Angular.Builders; +using Util.Ui.Angular.Configs; +using Util.Ui.Configs; + +namespace Util.Ui.NgAlain.Components.FooterToolbars.Builders; + +/// +/// 底部工具栏生成器 +/// +public class FooterToolbarBuilder : AngularTagBuilder { + /// + /// 配置 + /// + private readonly Config _config; + /// + /// 初始化底部工具栏生成器 + /// + /// 配置 + public FooterToolbarBuilder( Config config ) : base( config, "footer-toolbar" ) { + _config = config; + } + + /// + /// 配置错误收集 + /// + public FooterToolbarBuilder ErrorCollect() { + AttributeIfNotEmpty( "[errorCollect]", _config.GetValue( UiConst.ErrorCollect ) ); + return this; + } + + /// + /// 配置额外信息 + /// + public FooterToolbarBuilder Extra() { + AttributeIfNotEmpty( "extra", _config.GetValue( UiConst.Extra ) ); + AttributeIfNotEmpty( "[extra]", _config.GetValue( AngularConst.BindExtra ) ); + return this; + } + + /// + /// 配置 + /// + public override void Config() { + base.Config(); + ErrorCollect().Extra(); + } +} \ No newline at end of file diff --git a/src/Util.Ui.NgAlain/Components/FooterToolbars/FooterToolbarTagHelper.cs b/src/Util.Ui.NgAlain/Components/FooterToolbars/FooterToolbarTagHelper.cs new file mode 100644 index 000000000..4adb60a48 --- /dev/null +++ b/src/Util.Ui.NgAlain/Components/FooterToolbars/FooterToolbarTagHelper.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Razor.TagHelpers; +using Util.Ui.Angular.TagHelpers; +using Util.Ui.Configs; +using Util.Ui.NgAlain.Components.FooterToolbars.Renders; +using Util.Ui.Renders; + +namespace Util.Ui.NgAlain.Components.FooterToolbars; + +/// +/// ng-alain 底部工具栏,生成的标签为<footer-toolbar></footer-toolbar> +/// +[HtmlTargetElement( "util-footer-toolbar" )] +public class FooterToolbarTagHelper : AngularTagHelperBase { + /// + /// [errorCollect],是否收集表单错误,需要放入 form 标签内, 默认值: false + /// + public string ErrorCollect { get; set; } + /// + /// extra,额外信息,显示在左边 + /// + public string Extra { get; set; } + /// + /// [extra],额外信息,显示在左边 + /// + public string BindExtra { get; set; } + + /// + protected override IRender GetRender( TagHelperContext context, TagHelperOutput output, TagHelperContent content ) { + var config = new Config( context, output, content ); + return new FooterToolbarRender( config ); + } +} \ No newline at end of file diff --git a/src/Util.Ui.NgAlain/Components/FooterToolbars/Renders/FooterToolbarRender.cs b/src/Util.Ui.NgAlain/Components/FooterToolbars/Renders/FooterToolbarRender.cs new file mode 100644 index 000000000..20aa7ccec --- /dev/null +++ b/src/Util.Ui.NgAlain/Components/FooterToolbars/Renders/FooterToolbarRender.cs @@ -0,0 +1,39 @@ +using Util.Ui.Angular.Extensions; +using Util.Ui.Builders; +using Util.Ui.Configs; +using Util.Ui.NgAlain.Components.FooterToolbars.Builders; +using Util.Ui.Renders; + +namespace Util.Ui.NgAlain.Components.FooterToolbars.Renders; + +/// +/// 底部工具栏渲染器 +/// +public class FooterToolbarRender : RenderBase { + /// + /// 配置 + /// + private readonly Config _config; + + /// + /// 初始化底部工具栏渲染器 + /// + /// 配置 + public FooterToolbarRender( Config config ) { + _config = config; + } + + /// + /// 获取标签生成器 + /// + protected override TagBuilder GetTagBuilder() { + var builder = new FooterToolbarBuilder( _config ); + builder.Config(); + return builder; + } + + /// + public override IHtmlContent Clone() { + return new FooterToolbarRender( _config.CopyRemoveAttributes() ); + } +} \ No newline at end of file diff --git a/src/Util.Ui.NgZorro/Components/Links/ATagHelper.cs b/src/Util.Ui.NgZorro/Components/Links/ATagHelper.cs index 4c9ca92d1..d5469a262 100644 --- a/src/Util.Ui.NgZorro/Components/Links/ATagHelper.cs +++ b/src/Util.Ui.NgZorro/Components/Links/ATagHelper.cs @@ -43,6 +43,10 @@ public class ATagHelper : ButtonTagHelperBase { /// 扩展属性,是否查询表单链接,折叠时显示展开文本,展开时显示收起文本 /// public bool IsSearch { get; set; } + /// + /// 扩展属性,显示表格设置,参数值为表格标识 + /// + public string ShowTableSettings { get; set; } /// protected override IRender GetRender( TagHelperContext context, TagHelperOutput output, TagHelperContent content ) { diff --git a/src/Util.Ui.NgZorro/Components/Links/Builders/ABuilder.cs b/src/Util.Ui.NgZorro/Components/Links/Builders/ABuilder.cs index 3a868106b..63c52100c 100644 --- a/src/Util.Ui.NgZorro/Components/Links/Builders/ABuilder.cs +++ b/src/Util.Ui.NgZorro/Components/Links/Builders/ABuilder.cs @@ -4,6 +4,8 @@ using Util.Ui.NgZorro.Components.Base; using Util.Ui.NgZorro.Components.Icons.Builders; using Util.Ui.NgZorro.Configs; +using Util.Ui.NgZorro.Directives.Tooltips; +using Util.Ui.NgZorro.Enums; namespace Util.Ui.NgZorro.Components.Links.Builders; @@ -70,8 +72,8 @@ public ABuilder IsSearch() { return this; this.OnClick( "expand=!expand" ); var options = NgZorroOptionsService.GetOptions(); - if (options.EnableI18n) - AppendContent("{{" + $"expand?('{I18nKeys.Collapse}'|i18n):('{I18nKeys.Expand}'|i18n)" + "}}"); + if ( options.EnableI18n ) + AppendContent( "{{" + $"expand?('{I18nKeys.Collapse}'|i18n):('{I18nKeys.Expand}'|i18n)" + "}}" ); else AppendContent( "{{expand?'收起':'展开'}}" ); var icon = new IconBuilder( _config ); @@ -80,11 +82,29 @@ public ABuilder IsSearch() { return this; } + /// + /// 配置显示表格设置 + /// + public ABuilder ShowTableSettings() { + var tableId = _config.GetValue( UiConst.ShowTableSettings ); + if ( tableId.IsEmpty() ) + return this; + this.OnClick( $"ts_{tableId}.show()" ); + Class( "btn-table-settings" ); + var options = NgZorroOptionsService.GetOptions(); + this.TooltipTitle( options.EnableI18n ? "util.tableSettings" : "表格设置" ); + var icon = new IconBuilder( _config ); + icon.Type( AntDesignIcon.Setting ); + AppendContent( icon ); + return this; + } + /// /// 配置 /// public override void Config() { base.Config(); - ConfigButton().Href().Target().Rel().RouterLink().DropdownMenu().DropdownMenuPlacement().IsSearch(); + ConfigButton().Href().Target().Rel().RouterLink().DropdownMenu() + .DropdownMenuPlacement().IsSearch().ShowTableSettings(); } } \ No newline at end of file diff --git a/src/Util.Ui.NgZorro/Components/Tables/Builders/TableBuilder.cs b/src/Util.Ui.NgZorro/Components/Tables/Builders/TableBuilder.cs index 41586b764..619e67fd6 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/Builders/TableBuilder.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/Builders/TableBuilder.cs @@ -1,7 +1,6 @@ using Util.Ui.Angular.Builders; using Util.Ui.Angular.Configs; using Util.Ui.Angular.Extensions; -using Util.Ui.Configs; using Util.Ui.Extensions; using Util.Ui.NgZorro.Components.Tables.Configs; using Util.Ui.NgZorro.Components.Tables.Helpers; @@ -499,6 +498,32 @@ public TableBuilder ConfigKeys() { return this; } + /// + /// 配置自定义列 + /// + public TableBuilder CustomColumn() { + CustomColumn( _config.GetValue( UiConst.CustomColumn ) ); + return this; + } + + /// + /// 配置自定义列 + /// + public TableBuilder CustomColumn( string value ) { + AttributeIfNotEmpty( "[nzCustomColumn]", value ); + return this; + } + + /// + /// 配置启用自定义列 + /// + public TableBuilder EnableCustomColumn() { + if (_shareConfig.IsEnableCustomColumn == false) + return this; + CustomColumn( $"{_shareConfig.TableSettingsId}.columns" ); + return this; + } + /// /// 配置事件 /// @@ -566,6 +591,7 @@ public override void Config() { .Layout() .QueryParam().Url().DeleteUrl() .Sort().AutoLoad().ConfigKeys() + .CustomColumn().EnableCustomColumn() .Events(); ConfigAutoCreate(); if ( _shareConfig.IsEnableExtend ) diff --git a/src/Util.Ui.NgZorro/Components/Tables/Builders/TableColumnBuilder.cs b/src/Util.Ui.NgZorro/Components/Tables/Builders/TableColumnBuilder.cs index bda92e2cc..fe4d8937c 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/Builders/TableColumnBuilder.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/Builders/TableColumnBuilder.cs @@ -1,7 +1,6 @@ using Util.Ui.Angular.Builders; using Util.Ui.Angular.Configs; using Util.Ui.Builders; -using Util.Ui.Configs; using Util.Ui.NgZorro.Components.Tables.Builders.Contents; using Util.Ui.NgZorro.Components.Tables.Configs; using Util.Ui.NgZorro.Enums; @@ -160,6 +159,34 @@ public TableColumnBuilder IndentSize() { return this; } + /// + /// 配置单元格控件 + /// + public virtual TableColumnBuilder CellControl() { + CellControl( _config.GetValue( UiConst.CellControl ) ); + AttributeIfNotEmpty( "[nzCellControl]", _config.GetValue( AngularConst.BindCellControl ) ); + return this; + } + + /// + /// 配置单元格控件 + /// + /// 值 + public virtual TableColumnBuilder CellControl( string value ) { + AttributeIfNotEmpty( "nzCellControl", value ); + return this; + } + + /// + /// 配置启用自定义列 + /// + public TableColumnBuilder EnableCustomColumn() { + if ( _shareConfig.IsEnableCustomColumn == false ) + return this; + CellControl( _shareConfig.CellControl ); + return this; + } + /// /// 配置事件 /// @@ -177,7 +204,7 @@ public override void Config() { ShowCheckbox().Disabled().Indeterminate().Checked() .ShowExpand().Expand() .Left().Right().Align().BreakWord().Ellipsis() - .IndentSize() + .IndentSize().CellControl().EnableCustomColumn() .Events(); ConfigContent(); } diff --git a/src/Util.Ui.NgZorro/Components/Tables/Builders/TableHeadColumnBuilder.cs b/src/Util.Ui.NgZorro/Components/Tables/Builders/TableHeadColumnBuilder.cs index 4fbbc428c..3f95248a1 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/Builders/TableHeadColumnBuilder.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/Builders/TableHeadColumnBuilder.cs @@ -1,14 +1,13 @@ using Util.Ui.Angular.Builders; using Util.Ui.Angular.Configs; using Util.Ui.Angular.Extensions; -using Util.Ui.Configs; using Util.Ui.NgZorro.Components.Tables.Configs; using Util.Ui.NgZorro.Components.Tables.Helpers; using Util.Ui.NgZorro.Configs; using Util.Ui.NgZorro.Enums; using Util.Ui.NgZorro.Extensions; -namespace Util.Ui.NgZorro.Components.Tables.Builders; +namespace Util.Ui.NgZorro.Components.Tables.Builders; /// /// 表头单元格标签生成器 @@ -28,7 +27,7 @@ public class TableHeadColumnBuilder : AngularTagBuilder { /// /// 配置 /// 表头列共享配置 - public TableHeadColumnBuilder( Config config, TableHeadColumnShareConfig shareConfig ) : base( config,"th" ) { + public TableHeadColumnBuilder( Config config, TableHeadColumnShareConfig shareConfig ) : base( config, "th" ) { _config = config; _shareConfig = shareConfig; } @@ -194,6 +193,8 @@ public TableHeadColumnBuilder FilterMultiple() { /// 配置列宽 /// public TableHeadColumnBuilder Width() { + if ( _shareConfig.IsEnableCustomColumn ) + return this; this.Width( _config.GetValue( UiConst.Width ) ); BindWidth( _config.GetValue( AngularConst.BindWidth ) ); return this; @@ -352,6 +353,41 @@ public virtual void Title( string title ) { AppendContent( title ); } + /// + /// 配置单元格控件 + /// + public virtual TableHeadColumnBuilder CellControl() { + CellControl( _config.GetValue( UiConst.CellControl ) ); + AttributeIfNotEmpty( "[nzCellControl]", _config.GetValue( AngularConst.BindCellControl ) ); + return this; + } + + /// + /// 配置单元格控件 + /// + /// 值 + public virtual TableHeadColumnBuilder CellControl( string value ) { + AttributeIfNotEmpty( "nzCellControl", value ); + return this; + } + + /// + /// 配置启用自定义列 + /// + public TableHeadColumnBuilder EnableCustomColumn() { + return EnableCustomColumn( _shareConfig.CellControl ); + } + + /// + /// 配置启用自定义列 + /// + public TableHeadColumnBuilder EnableCustomColumn( string cellControl ) { + if ( _shareConfig.IsEnableCustomColumn == false ) + return this; + CellControl( cellControl ); + return this; + } + /// /// 配置事件 /// @@ -382,6 +418,7 @@ public override void Config() { .Width().Left().Right().Align().BreakWord().Ellipsis() .Colspan().Rowspan().ColumnKey() .TitleOperation().Title() + .CellControl().EnableCustomColumn() .Events() .CheckBox().Radio().LineNumber(); } @@ -498,16 +535,18 @@ public virtual void AddColumn( ColumnInfo column ) { if ( column.IsSort ) Sort( column.Column ); Title( column.Title ); - this.Width( column.Width ); + if ( _shareConfig.IsEnableCustomColumn == false ) + this.Width( column.Width ); Left( column.IsLeft ); Right( column.IsRight ); SetAcl( column.Acl, column.AclElseTemplateId ); + EnableCustomColumn( column.GetCellControl() ); } /// /// 配置访问控制列表 /// - public TableHeadColumnBuilder SetAcl( string acl,string aclElseTemplateId ) { + public TableHeadColumnBuilder SetAcl( string acl, string aclElseTemplateId ) { _config.SetAttribute( UiConst.Acl, acl ); _config.SetAttribute( UiConst.AclElseTemplateId, aclElseTemplateId ); this.Acl( _config ); diff --git a/src/Util.Ui.NgZorro/Components/Tables/Builders/TableSettingsBuilder.cs b/src/Util.Ui.NgZorro/Components/Tables/Builders/TableSettingsBuilder.cs new file mode 100644 index 000000000..5a0324274 --- /dev/null +++ b/src/Util.Ui.NgZorro/Components/Tables/Builders/TableSettingsBuilder.cs @@ -0,0 +1,61 @@ +using Util.Ui.Angular.Builders; +using Util.Ui.NgZorro.Components.Tables.Configs; + +namespace Util.Ui.NgZorro.Components.Tables.Builders; + +/// +/// 表格设置标签生成器 +/// +public class TableSettingsBuilder : AngularTagBuilder { + /// + /// 配置 + /// + private readonly Config _config; + /// + /// 表格共享配置 + /// + private TableShareConfig _tableShareConfig; + + /// + /// 初始化表格设置标签生成器 + /// + /// 配置 + public TableSettingsBuilder( Config config ) : base( config, "x-table-settings" ) { + _config = config; + _tableShareConfig = GetTableShareConfig(); + } + + /// + /// 获取表格共享配置 + /// + public TableShareConfig GetTableShareConfig() { + return _tableShareConfig ??= _config.GetValueFromItems() ?? new TableShareConfig(); + } + + /// + /// 配置初始设置的列集合 + /// + public TableSettingsBuilder InitColumns() { + if ( _tableShareConfig.ColumnNumber == 0 ) + return this; + Attribute( "[initColumns]", GetColumnsJson() ); + return this; + } + + /// + /// 获取自定义列Json + /// + private string GetColumnsJson() { + var customColumns = _tableShareConfig.Columns.Select( column => column.ToCustomColumn() ); + return Util.Helpers.Json.ToJson( customColumns, new JsonOptions { ToSingleQuotes = true, IgnoreNullValues = true } ); + } + + /// + /// 配置 + /// + public override void Config() { + Attribute( $"#{_tableShareConfig.TableSettingsId}" ); + Attribute( "customColumnKey", _tableShareConfig.CustomColumnKey ); + InitColumns(); + } +} \ No newline at end of file diff --git a/src/Util.Ui.NgZorro/Components/Tables/Builders/TotalTemplateBuilder.cs b/src/Util.Ui.NgZorro/Components/Tables/Builders/TotalTemplateBuilder.cs index 36e4aad68..8a910426a 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/Builders/TotalTemplateBuilder.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/Builders/TotalTemplateBuilder.cs @@ -1,5 +1,4 @@ -using Util.Ui.Configs; -using Util.Ui.NgZorro.Components.Tables.Configs; +using Util.Ui.NgZorro.Components.Tables.Configs; using Util.Ui.NgZorro.Components.Templates.Builders; namespace Util.Ui.NgZorro.Components.Tables.Builders; diff --git a/src/Util.Ui.NgZorro/Components/Tables/Configs/TableColumnShareConfig.cs b/src/Util.Ui.NgZorro/Components/Tables/Configs/TableColumnShareConfig.cs index d17b7c605..7d947d25b 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/Configs/TableColumnShareConfig.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/Configs/TableColumnShareConfig.cs @@ -1,7 +1,7 @@ using Util.Helpers; using Util.Ui.NgZorro.Components.Tables.Helpers; -namespace Util.Ui.NgZorro.Components.Tables.Configs; +namespace Util.Ui.NgZorro.Components.Tables.Configs; /// /// 表格列共享配置 @@ -23,6 +23,8 @@ public class TableColumnShareConfig { public TableColumnShareConfig( TableShareConfig tableShareConfig ) { _tableShareConfig = tableShareConfig; IsAutoCreateControl = true; + Index = _tableShareConfig.ColumnNumber; + _tableShareConfig.ColumnNumber++; Column = Id.Create(); } @@ -41,6 +43,11 @@ public TableColumnShareConfig( TableShareConfig tableShareConfig ) { /// public bool IsEnableEdit => _tableShareConfig.IsEnableEdit; + /// + /// 是否启用自定义列 + /// + public bool IsEnableCustomColumn => _tableShareConfig.IsEnableCustomColumn; + /// /// 表格扩展标识 /// @@ -61,6 +68,21 @@ public TableColumnShareConfig( TableShareConfig tableShareConfig ) { /// public string Column { get; set; } + /// + /// 索引 + /// + public int Index { get; set; } + + /// + /// 自定义列标识 + /// + public string CellControl { + get { + var column = _tableShareConfig.GetColumn( Index ); + return column.GetCellControl(); + } + } + /// /// 编辑控件模板标识 /// @@ -134,7 +156,17 @@ public void SetControlTemplateId( string controlTemplateId ) { public void AddColumn( ColumnInfo column ) { if ( column == null ) return; + column.Index = Index; Column = column.Column; + var headColumn = _tableShareConfig.GetHeadColumn( Index ); + if ( headColumn != null ) { + if ( headColumn.Title.IsEmpty() == false ) + column.Title = headColumn.Title; + if ( headColumn.CellControl.IsEmpty() == false ) + column.CellControl = headColumn.CellControl; + if ( headColumn.Width.IsEmpty() == false ) + column.Width = headColumn.Width; + } _tableShareConfig.Columns.Add( column ); } diff --git a/src/Util.Ui.NgZorro/Components/Tables/Configs/TableHeadColumnShareConfig.cs b/src/Util.Ui.NgZorro/Components/Tables/Configs/TableHeadColumnShareConfig.cs index 09f1508db..509ee4658 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/Configs/TableHeadColumnShareConfig.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/Configs/TableHeadColumnShareConfig.cs @@ -1,4 +1,6 @@ -namespace Util.Ui.NgZorro.Components.Tables.Configs; +using Util.Ui.NgZorro.Components.Tables.Helpers; + +namespace Util.Ui.NgZorro.Components.Tables.Configs; /// /// 表头列共享配置 @@ -15,6 +17,8 @@ public class TableHeadColumnShareConfig { /// 表格共享配置 public TableHeadColumnShareConfig( TableShareConfig tableShareConfig ) { _tableShareConfig = tableShareConfig; + Index = _tableShareConfig.HeadColumnNumber; + _tableShareConfig.HeadColumnNumber++; } /// @@ -32,6 +36,11 @@ public TableHeadColumnShareConfig( TableShareConfig tableShareConfig ) { /// public string TableEditId => _tableShareConfig.TableEditId; + /// + /// 是否启用自定义列 + /// + public bool IsEnableCustomColumn => _tableShareConfig.IsEnableCustomColumn; + /// /// 是否显示复选框 /// @@ -75,12 +84,39 @@ public bool IsAutoCreateHeadColumn { /// public bool IsFirst { get; set; } + /// + /// 索引 + /// + public int Index { get; set; } + + /// + /// 自定义列标识 + /// + public string CellControl { + get { + var column = _tableShareConfig.GetColumn( Index ); + if (column == null) + return null; + return column.GetCellControl(); + } + } + /// /// 设置第一列 /// public void SetIsFirst() { - if ( _tableShareConfig.HeadColumnNumber == 0 ) + if ( Index == 0 ) IsFirst = true; - _tableShareConfig.HeadColumnNumber++; + } + + /// + /// 添加列 + /// + /// 列信息 + public void AddColumn( HeadColumnInfo column ) { + if ( column == null ) + return; + column.Index = Index; + _tableShareConfig.HeadColumns.Add( column ); } } \ No newline at end of file diff --git a/src/Util.Ui.NgZorro/Components/Tables/Configs/TableShareConfig.cs b/src/Util.Ui.NgZorro/Components/Tables/Configs/TableShareConfig.cs index 05126a5c6..ce20dc7bf 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/Configs/TableShareConfig.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/Configs/TableShareConfig.cs @@ -1,6 +1,6 @@ using Util.Ui.NgZorro.Components.Tables.Helpers; -namespace Util.Ui.NgZorro.Components.Tables.Configs; +namespace Util.Ui.NgZorro.Components.Tables.Configs; /// /// 表格共享配置 @@ -17,6 +17,7 @@ public class TableShareConfig { /// 表格标识 public TableShareConfig( string id = null ) { Id = id.IsEmpty() ? Util.Helpers.Id.Create() : id; + HeadColumns = new List(); Columns = new List(); IsAutoCreateHead = true; IsAutoCreateHeadRow = true; @@ -45,6 +46,11 @@ public TableShareConfig( string id = null ) { /// public string RowId => _rowId.IsEmpty() ? $"{Id}_row" : _rowId; + /// + /// 表格设置组件标识 + /// + public string TableSettingsId => $"ts_{Id}"; + /// /// 设置表格主体行标识 /// @@ -58,6 +64,11 @@ public void SetRowId( string rowId ) { /// public string TotalTemplateId => $"total_{Id}"; + /// + /// 表头列信息集合 + /// + public List HeadColumns { get; } + /// /// 列信息集合 /// @@ -68,6 +79,11 @@ public void SetRowId( string rowId ) { /// public int HeadColumnNumber { get; set; } + /// + /// 列数 + /// + public int ColumnNumber { get; set; } + /// /// 是否自动创建表头thead /// @@ -133,6 +149,11 @@ public void SetRowId( string rowId ) { /// public bool IsEnableEdit { get; set; } + /// + /// 是否启用自定义列 + /// + public bool IsEnableCustomColumn { get; set; } + /// /// 是否显示复选框 /// @@ -187,4 +208,25 @@ public void SetRowId( string rowId ) { /// 点击是否仅选中该行 /// public bool SelectOnlyOnClickRow { get; set; } + + /// + /// 自定义列标识 + /// + public string CustomColumnKey { get; set; } + + /// + /// 获取列信息 + /// + /// 列索引 + public ColumnInfo GetColumn( int index ) { + return Columns.Find( t => t.Index == index ); + } + + /// + /// 获取表头列信息 + /// + /// 列索引 + public HeadColumnInfo GetHeadColumn( int index ) { + return HeadColumns.Find( t => t.Index == index ); + } } \ No newline at end of file diff --git a/src/Util.Ui.NgZorro/Components/Tables/Helpers/ColumnInfo.cs b/src/Util.Ui.NgZorro/Components/Tables/Helpers/ColumnInfo.cs index bb2b84b47..d5ded3c72 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/Helpers/ColumnInfo.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/Helpers/ColumnInfo.cs @@ -1,9 +1,13 @@ -namespace Util.Ui.NgZorro.Components.Tables.Helpers; +namespace Util.Ui.NgZorro.Components.Tables.Helpers; /// /// 列配置信息 /// public class ColumnInfo { + /// + /// 索引 + /// + public int Index { get; set; } /// /// 标题 /// @@ -13,6 +17,10 @@ public class ColumnInfo { /// public string Column { get; set; } /// + /// 自定义列标识 + /// + public string CellControl { get; set; } + /// /// 是否排序 /// public bool IsSort { get; set; } @@ -40,4 +48,18 @@ public class ColumnInfo { /// 访问控制列表模板标识 /// public string AclElseTemplateId { get; set; } + + /// + /// 转换为自定义列 + /// + public CustomColumn ToCustomColumn() { + return new CustomColumn( GetCellControl(), Width, Acl ); + } + + /// + /// 获取自定义列标识 + /// + public string GetCellControl() { + return CellControl.IsEmpty() ? Title : CellControl; + } } \ No newline at end of file diff --git a/src/Util.Ui.NgZorro/Components/Tables/Helpers/CustomColumn.cs b/src/Util.Ui.NgZorro/Components/Tables/Helpers/CustomColumn.cs new file mode 100644 index 000000000..b8cca2912 --- /dev/null +++ b/src/Util.Ui.NgZorro/Components/Tables/Helpers/CustomColumn.cs @@ -0,0 +1,62 @@ +using Util.Ui.NgZorro.Configs; + +namespace Util.Ui.NgZorro.Components.Tables.Helpers; + +/// +/// 自定义列信息 +/// +public class CustomColumn { + /// + /// 初始化自定义列信息 + /// + /// 值 + /// 宽度 + /// 访问控制 + public CustomColumn( string value, string width, string acl ) { + Value = value; + Default = true; + Width = GetWidth( width ); + if ( acl.IsEmpty() == false ) + Acl = acl; + } + + /// + /// 获取宽度 + /// + private double GetWidth( string value ) { + var defaultWidth = NgZorroOptionsService.GetOptions().TableColumnDefaultWidth; + if ( value.IsEmpty() ) + return defaultWidth; + if ( Util.Helpers.Validation.IsNumber( value ) ) + return Util.Helpers.Convert.ToDouble( value ); + if ( value.EndsWith( "px" ) ) + return Util.Helpers.Convert.ToDouble( value.RemoveEnd( "px" ) ); + if ( value.EndsWith( "%" ) ) + return 10 * Util.Helpers.Convert.ToDouble( value.RemoveEnd( "%" ) ); + return defaultWidth; + } + + /// + /// 值 + /// + [JsonPropertyName( "value" )] + public string Value { get; } + + /// + /// 默认 + /// + [JsonPropertyName( "default" )] + public bool Default { get; } + + /// + /// 宽度 + /// + [JsonPropertyName( "width" )] + public double Width { get; } + + /// + /// 访问控制 + /// + [JsonPropertyName( "acl" )] + public string Acl { get; } +} \ No newline at end of file diff --git a/src/Util.Ui.NgZorro/Components/Tables/Helpers/HeadColumnInfo.cs b/src/Util.Ui.NgZorro/Components/Tables/Helpers/HeadColumnInfo.cs new file mode 100644 index 000000000..e85cf8850 --- /dev/null +++ b/src/Util.Ui.NgZorro/Components/Tables/Helpers/HeadColumnInfo.cs @@ -0,0 +1,30 @@ +namespace Util.Ui.NgZorro.Components.Tables.Helpers; + +/// +/// 表头列配置信息 +/// +public class HeadColumnInfo { + /// + /// 索引 + /// + public int Index { get; set; } + /// + /// 标题 + /// + public string Title { get; set; } + /// + /// 宽度 + /// + public string Width { get; set; } + /// + /// 自定义列标识 + /// + public string CellControl { get; set; } + + /// + /// 获取自定义列标识 + /// + public string GetCellControl() { + return CellControl.IsEmpty() ? Title : CellControl; + } +} \ No newline at end of file diff --git a/src/Util.Ui.NgZorro/Components/Tables/Helpers/TableColumnService.cs b/src/Util.Ui.NgZorro/Components/Tables/Helpers/TableColumnService.cs index 7c923caa1..b4d9bbc8b 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/Helpers/TableColumnService.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/Helpers/TableColumnService.cs @@ -1,8 +1,7 @@ -using Util.Ui.Configs; -using Util.Ui.NgZorro.Components.Tables.Configs; +using Util.Ui.NgZorro.Components.Tables.Configs; using Util.Ui.NgZorro.Configs; -namespace Util.Ui.NgZorro.Components.Tables.Helpers; +namespace Util.Ui.NgZorro.Components.Tables.Helpers; /// /// 表格列服务 @@ -64,7 +63,7 @@ public void SetIsFirst() { /// private void EnableEdit() { var result = _config.GetValue( UiConst.IsEdit ); - if( result ) + if ( result ) _shareConfig.EnableEdit(); } @@ -99,6 +98,7 @@ private ColumnInfo GetColumnInfo() { var result = new ColumnInfo { Title = GetTitle(), Column = _config.GetValue( UiConst.Column ), + CellControl = _config.GetValue( UiConst.CellControl ), Width = _config.GetValue( UiConst.Width ), IsSort = _config.GetValue( UiConst.Sort ), IsFirst = _shareConfig.IsFirst, diff --git a/src/Util.Ui.NgZorro/Components/Tables/Helpers/TableHeadColumnService.cs b/src/Util.Ui.NgZorro/Components/Tables/Helpers/TableHeadColumnService.cs index b314eac88..d64000b6d 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/Helpers/TableHeadColumnService.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/Helpers/TableHeadColumnService.cs @@ -1,8 +1,7 @@ -using Util.Ui.Configs; -using Util.Ui.Expressions; +using Util.Ui.Expressions; using Util.Ui.NgZorro.Components.Tables.Configs; -namespace Util.Ui.NgZorro.Components.Tables.Helpers; +namespace Util.Ui.NgZorro.Components.Tables.Helpers; /// /// 表头单元格服务 @@ -32,6 +31,7 @@ public void Init() { CreateTableHeadColumnShareConfig(); CancelAutoCreateHeadColumn(); SetIsFirst(); + SetColumn(); LoadExpression(); } @@ -39,7 +39,7 @@ public void Init() { /// 创建表头列共享配置 /// private void CreateTableHeadColumnShareConfig() { - _shareConfig = new TableHeadColumnShareConfig( GetTableShareConfig()); + _shareConfig = new TableHeadColumnShareConfig( GetTableShareConfig() ); _config.SetValueToItems( _shareConfig ); } @@ -64,6 +64,16 @@ public void SetIsFirst() { _shareConfig.SetIsFirst(); } + /// + /// 设置表头列 + /// + public void SetColumn() { + var title = _config.GetValue( UiConst.Title ); + var width = _config.GetValue( UiConst.Width ); + var cellControl = _config.GetValue( UiConst.CellControl ); + _shareConfig.AddColumn( new HeadColumnInfo { Title = title, Width = width, CellControl = cellControl } ); + } + /// /// 加载表达式 /// diff --git a/src/Util.Ui.NgZorro/Components/Tables/Helpers/TableService.cs b/src/Util.Ui.NgZorro/Components/Tables/Helpers/TableService.cs index 75dcd95ae..0a7be752c 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/Helpers/TableService.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/Helpers/TableService.cs @@ -2,7 +2,7 @@ using Util.Ui.Configs; using Util.Ui.NgZorro.Components.Tables.Configs; -namespace Util.Ui.NgZorro.Components.Tables.Helpers; +namespace Util.Ui.NgZorro.Components.Tables.Helpers; /// /// 表格服务 @@ -44,6 +44,7 @@ public void InitTreeTable() { /// public void Init() { CreateShareConfig(); + SetEnableCustomColumn(); SetIsShowCheckbox(); SetIsShowRadio(); SetIsCheckLeafOnly(); @@ -67,6 +68,17 @@ private string GetTableId() { return _config.GetValue( UiConst.Id ); } + /// + /// 设置启用自定义列 + /// + private void SetEnableCustomColumn() { + var key = _config.GetValue( UiConst.EnableCustomColumn ); + if ( key.IsEmpty() || key.ToLower() == "true" ) + return; + _shareConfig.IsEnableCustomColumn = true; + _shareConfig.CustomColumnKey = key; + } + /// /// 设置是否显示复选框 /// @@ -115,7 +127,7 @@ private void EnableExtend() { _shareConfig.IsEnableExtend = false; return; } - if ( GetEnableExtend() == true || + if ( GetEnableExtend() == true || GetUrl().IsEmpty() == false || GetBindUrl().IsEmpty() == false || GetLoadUrl().IsEmpty() == false || @@ -125,7 +137,7 @@ private void EnableExtend() { GetLoadChildrenUrl().IsEmpty() == false || GetBindLoadChildrenUrl().IsEmpty() == false || _shareConfig.IsShowCheckbox || - _shareConfig.IsShowRadio || + _shareConfig.IsShowRadio || _shareConfig.IsShowLineNumber ) { _shareConfig.IsEnableExtend = true; } diff --git a/src/Util.Ui.NgZorro/Components/Tables/Renders/TableRender.cs b/src/Util.Ui.NgZorro/Components/Tables/Renders/TableRender.cs index e4edfc290..acd30df36 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/Renders/TableRender.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/Renders/TableRender.cs @@ -1,5 +1,5 @@ -using Util.Ui.Builders; -using Util.Ui.Configs; +using Util.Ui.Angular.Extensions; +using Util.Ui.Builders; using Util.Ui.NgZorro.Components.Tables.Builders; using Util.Ui.NgZorro.Components.Tables.Configs; using Util.Ui.Renders; @@ -40,6 +40,7 @@ private TableShareConfig GetShareConfig() { public override void WriteTo( TextWriter writer, HtmlEncoder encoder ) { base.WriteTo( writer, encoder ); RenderTotalTemplate( writer, encoder ); + RenderTableSettings( writer, encoder ); } /// @@ -62,8 +63,21 @@ protected void RenderTotalTemplate( TextWriter writer, HtmlEncoder encoder ) { builder.WriteTo( writer, encoder ); } + /// + /// 渲染表格设置组件 + /// + protected void RenderTableSettings( TextWriter writer, HtmlEncoder encoder ) { + if ( _shareConfig.IsEnableCustomColumn == false ) + return; + if ( _shareConfig.ColumnNumber == 0 ) + return; + var builder = new TableSettingsBuilder( _config ); + builder.Config(); + builder.WriteTo( writer, encoder ); + } + /// public override IHtmlContent Clone() { - return new TableRender( _config.Copy(), _shareConfig.MapTo() ); + return new TableRender( _config.CopyRemoveAttributes(), _shareConfig.MapTo() ); } } \ No newline at end of file diff --git a/src/Util.Ui.NgZorro/Components/Tables/TableColumnTagHelper.cs b/src/Util.Ui.NgZorro/Components/Tables/TableColumnTagHelper.cs index e49770099..4e6ebb0cd 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/TableColumnTagHelper.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/TableColumnTagHelper.cs @@ -166,6 +166,14 @@ public class TableColumnTagHelper : AngularTagHelperBase { /// public string BindIndentSize { get; set; } /// + /// nzCellControl,设置列的位置,该值为 NzCustomColumn 类型中 value 字段的值 + /// + public string CellControl { get; set; } + /// + /// [nzCellControl],设置列的位置,该值为 NzCustomColumn 类型中 value 字段的值 + /// + public string BindCellControl { get; set; } + /// /// (nzCheckedChange),复选框选中状态变化事件,类型: EventEmitter<boolean> /// public string OnCheckedChange { get; set; } diff --git a/src/Util.Ui.NgZorro/Components/Tables/TableHeadColumnTagHelper.cs b/src/Util.Ui.NgZorro/Components/Tables/TableHeadColumnTagHelper.cs index 764d1e10c..811daa458 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/TableHeadColumnTagHelper.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/TableHeadColumnTagHelper.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Razor.TagHelpers; using Util.Ui.Angular.TagHelpers; -using Util.Ui.Configs; using Util.Ui.NgZorro.Components.Tables.Helpers; using Util.Ui.NgZorro.Components.Tables.Renders; using Util.Ui.NgZorro.Enums; @@ -203,6 +202,14 @@ public class TableHeadColumnTagHelper : AngularTagHelperBase { /// public string BindColumnKey { get; set; } /// + /// nzCellControl,设置列的位置,该值为 NzCustomColumn 类型中 value 字段的值 + /// + public string CellControl { get; set; } + /// + /// [nzCellControl],设置列的位置,该值为 NzCustomColumn 类型中 value 字段的值 + /// + public string BindCellControl { get; set; } + /// /// (nzCheckedChange),复选框选中状态变化事件,类型: EventEmitter<boolean> /// public string OnCheckedChange { get; set; } diff --git a/src/Util.Ui.NgZorro/Components/Tables/TableTagHelper.cs b/src/Util.Ui.NgZorro/Components/Tables/TableTagHelper.cs index c00e53827..728c97725 100644 --- a/src/Util.Ui.NgZorro/Components/Tables/TableTagHelper.cs +++ b/src/Util.Ui.NgZorro/Components/Tables/TableTagHelper.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore.Razor.TagHelpers; using Util.Ui.Angular.TagHelpers; -using Util.Ui.Configs; using Util.Ui.NgZorro.Components.Tables.Helpers; using Util.Ui.NgZorro.Components.Tables.Renders; using Util.Ui.NgZorro.Enums; @@ -326,6 +325,14 @@ public class TableTagHelper : AngularTagHelperBase { /// public string BindLayout { get; set; } /// + /// [nzCustomColumn],自定义列, 控制表格列的展示与排序, 类型: NzCustomColumn[], 注意: 开启后 nzWidthConfig 和 th 的 nzWidth 将不生效 + /// + public string CustomColumn { get; set; } + /// + /// 扩展属性,启用自定义列, 参数值为自定义列标识 Key,用于将自定义列数据存储到浏览器本地, 必须全局唯一 + /// + public string EnableCustomColumn { get; set; } + /// /// (nzPageIndexChange),页码变化事件,类型: EventEmitter<number> /// public string OnPageIndexChange { get; set; } diff --git a/src/Util.Ui.NgZorro/Components/Templates/Builders/TemplateBuilder.cs b/src/Util.Ui.NgZorro/Components/Templates/Builders/TemplateBuilder.cs index be6ac638e..8d6087cc6 100644 --- a/src/Util.Ui.NgZorro/Components/Templates/Builders/TemplateBuilder.cs +++ b/src/Util.Ui.NgZorro/Components/Templates/Builders/TemplateBuilder.cs @@ -1,5 +1,4 @@ using Util.Ui.Angular.Builders; -using Util.Ui.Configs; namespace Util.Ui.NgZorro.Components.Templates.Builders; diff --git a/src/Util.Ui.NgZorro/NgZorroOptions.cs b/src/Util.Ui.NgZorro/NgZorroOptions.cs index 37a39ede9..6e8adaaa5 100644 --- a/src/Util.Ui.NgZorro/NgZorroOptions.cs +++ b/src/Util.Ui.NgZorro/NgZorroOptions.cs @@ -44,4 +44,8 @@ public class NgZorroOptions { /// 获取表格布尔列内容操作 /// public Func GetTableColumnBoolContentAction { get; set; } + /// + /// 表格列默认宽度,单位: px, 默认值:180, 自定义列使用 + /// + public double TableColumnDefaultWidth { get; set; } = 180; } \ No newline at end of file diff --git a/src/Util.Ui/Configs/UiConst.cs b/src/Util.Ui/Configs/UiConst.cs index 19f3672e0..df331b152 100644 --- a/src/Util.Ui/Configs/UiConst.cs +++ b/src/Util.Ui/Configs/UiConst.cs @@ -25,6 +25,14 @@ public static class UiConst { /// public const string Color = "color"; /// + /// 单元格控件 + /// + public const string CellControl = "cell-control"; + /// + /// 是否启用自定义列 + /// + public const string EnableCustomColumn = "enable-custom-column"; + /// /// 背景色 /// public const string BackgroundColor = "background-color"; @@ -273,6 +281,10 @@ public static class UiConst { /// public const string IsSearch = "is-search"; /// + /// 显示表格设置 + /// + public const string ShowTableSettings = "show-table-settings"; + /// /// 显示数量 /// public const string ShowNumber = "show-number"; @@ -705,6 +717,10 @@ public static class UiConst { /// public const string Title = "title"; /// + /// 错误收集 + /// + public const string ErrorCollect = "error-collect"; + /// /// operation标题 /// public const string TitleOperation = "title-operation"; @@ -1281,6 +1297,10 @@ public static class UiConst { /// public const string Layout = "layout"; /// + /// 自定义列 + /// + public const string CustomColumn = "custom-column"; + /// /// 显示冒号 /// public const string ShowColon = "show-colon"; diff --git a/test/Util.Data.EntityFrameworkCore.SqlServer.Tests.Integration/Tests/ProductRepositoryTest.cs b/test/Util.Data.EntityFrameworkCore.SqlServer.Tests.Integration/Tests/ProductRepositoryTest.cs index af6fe36ed..96a725c07 100644 --- a/test/Util.Data.EntityFrameworkCore.SqlServer.Tests.Integration/Tests/ProductRepositoryTest.cs +++ b/test/Util.Data.EntityFrameworkCore.SqlServer.Tests.Integration/Tests/ProductRepositoryTest.cs @@ -811,6 +811,32 @@ public async Task TestUpdate_4() { Assert.Equal( code, result[2].Code ); } + /// + /// 测试更新实体 - 先添加,不提交,查找修改, 跳过并发检测 + /// + [Fact] + public async Task TestUpdate_5() { + //常量 + var code = "TestUpdate_5_Code"; + + //添加实体 + var entity = ProductFakeService.GetProduct(); + entity.Init(); + await _repository.AddAsync( entity ); + + //查找实体,赋值,调用Update方法 + var product = await _repository.FindByIdAsync( entity.Id ); + product.Code = code; + await _repository.UpdateAsync( product ); + + //提交工作单元 + await UnitOfWork.CommitAsync(); + + //验证 + var result = await _repository.FindByIdAsync( entity.Id ); + Assert.Equal( code, result.Code ); + } + #endregion #region Remove diff --git a/test/Util.TestShare/Fakes/ProductFakeService.cs b/test/Util.TestShare/Fakes/ProductFakeService.cs index c334737ff..a640a7250 100644 --- a/test/Util.TestShare/Fakes/ProductFakeService.cs +++ b/test/Util.TestShare/Fakes/ProductFakeService.cs @@ -31,6 +31,7 @@ public static List GetProducts( int count ) { .Ignore( t => t.LastModifierId ) .Ignore( t => t.TenantId ) .Ignore( t => t.TestProperty1 ) + .Ignore( t => t.Version ) .RuleFor( t => t.IsDeleted, false ) .Generate( count ); } diff --git a/test/Util.Ui.NgAlain.Tests/Ellipsis/EllipsisTagHelperTest.Expression.cs b/test/Util.Ui.NgAlain.Tests/Ellipsis/EllipsisTagHelperTest.Expression.cs index 529ef6c94..88b590d67 100644 --- a/test/Util.Ui.NgAlain.Tests/Ellipsis/EllipsisTagHelperTest.Expression.cs +++ b/test/Util.Ui.NgAlain.Tests/Ellipsis/EllipsisTagHelperTest.Expression.cs @@ -1,16 +1,17 @@ using System.Text; using Xunit; -namespace Util.Ui.NgAlain.Tests.Ellipsis { +namespace Util.Ui.NgAlain.Tests.Ellipsis; + +/// +/// 文本省略组件测试 +/// +public partial class EllipsisTagHelperTest { /// - /// 文本省略组件测试 + /// 测试解析表达式属性for /// - public partial class EllipsisTagHelperTest { - /// - /// 测试解析表达式属性for - /// - [Fact] - public void TestFor_1() { + [Fact] + public void TestFor_1() { _wrapper.SetExpression( t => t.Code ); var result = new StringBuilder(); result.Append( "" ); @@ -18,5 +19,4 @@ public void TestFor_1() { result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - } } \ No newline at end of file diff --git a/test/Util.Ui.NgAlain.Tests/Ellipsis/EllipsisTagHelperTest.cs b/test/Util.Ui.NgAlain.Tests/Ellipsis/EllipsisTagHelperTest.cs index c3aae3d84..b20c475ab 100644 --- a/test/Util.Ui.NgAlain.Tests/Ellipsis/EllipsisTagHelperTest.cs +++ b/test/Util.Ui.NgAlain.Tests/Ellipsis/EllipsisTagHelperTest.cs @@ -7,166 +7,166 @@ using Xunit; using Xunit.Abstractions; -namespace Util.Ui.NgAlain.Tests.Ellipsis { - /// - /// 文本省略组件测试 - /// - public partial class EllipsisTagHelperTest { - /// - /// 输出工具 - /// - private readonly ITestOutputHelper _output; - /// - /// TagHelper包装器 - /// - private readonly TagHelperWrapper _wrapper; - - /// - /// 测试初始化 - /// - public EllipsisTagHelperTest( ITestOutputHelper output ) { +namespace Util.Ui.NgAlain.Tests.Ellipsis; + +/// +/// 文本省略组件测试 +/// +public partial class EllipsisTagHelperTest { + /// + /// 输出工具 + /// + private readonly ITestOutputHelper _output; + /// + /// TagHelper包装器 + /// + private readonly TagHelperWrapper _wrapper; + + /// + /// 测试初始化 + /// + public EllipsisTagHelperTest( ITestOutputHelper output ) { _output = output; _wrapper = new EllipsisTagHelper().ToWrapper(); } - /// - /// 获取结果 - /// - private string GetResult() { + /// + /// 获取结果 + /// + private string GetResult() { var result = _wrapper.GetResult(); _output.WriteLine( result ); return result; } - /// - /// 测试默认输出 - /// - [Fact] - public void TestDefault() { + /// + /// 测试默认输出 + /// + [Fact] + public void TestDefault() { var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试工具提示 - /// - [Fact] - public void TestTooltip() { + /// + /// 测试工具提示 + /// + [Fact] + public void TestTooltip() { _wrapper.SetContextAttribute( UiConst.Tooltip, true ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试工具提示 - /// - [Fact] - public void TestBindTooltip() { + /// + /// 测试工具提示 + /// + [Fact] + public void TestBindTooltip() { _wrapper.SetContextAttribute( AngularConst.BindTooltip, "true" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试文本最大长度 - /// - [Fact] - public void TestLength() { + /// + /// 测试文本最大长度 + /// + [Fact] + public void TestLength() { _wrapper.SetContextAttribute( UiConst.Length, 2 ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试文本最大长度 - /// - [Fact] - public void TestBindLength() { + /// + /// 测试文本最大长度 + /// + [Fact] + public void TestBindLength() { _wrapper.SetContextAttribute( AngularConst.BindLength, "2" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试文本最大行数 - /// - [Fact] - public void TestLines() { + /// + /// 测试文本最大行数 + /// + [Fact] + public void TestLines() { _wrapper.SetContextAttribute( UiConst.Lines, 2 ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试文本最大行数 - /// - [Fact] - public void TestBindLines() { + /// + /// 测试文本最大行数 + /// + [Fact] + public void TestBindLines() { _wrapper.SetContextAttribute( AngularConst.BindLines, "2" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试是否将全角字符的长度视为2来计算字符串长度 - /// - [Fact] - public void TestFullWidthRecognition() { + /// + /// 测试是否将全角字符的长度视为2来计算字符串长度 + /// + [Fact] + public void TestFullWidthRecognition() { _wrapper.SetContextAttribute( UiConst.FullWidthRecognition, true ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试是否将全角字符的长度视为2来计算字符串长度 - /// - [Fact] - public void TestBindFullWidthRecognition() { + /// + /// 测试是否将全角字符的长度视为2来计算字符串长度 + /// + [Fact] + public void TestBindFullWidthRecognition() { _wrapper.SetContextAttribute( AngularConst.BindFullWidthRecognition, "true" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试溢出尾巴 - /// - [Fact] - public void TestTail() { + /// + /// 测试溢出尾巴 + /// + [Fact] + public void TestTail() { _wrapper.SetContextAttribute( UiConst.Tail, "a" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试溢出尾巴 - /// - [Fact] - public void TestBindTail() { + /// + /// 测试溢出尾巴 + /// + [Fact] + public void TestBindTail() { _wrapper.SetContextAttribute( AngularConst.BindTail, "a" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试内容 - /// - [Fact] - public void TestAppendContent() { + /// + /// 测试内容 + /// + [Fact] + public void TestAppendContent() { _wrapper.AppendContent( "a" ); var result = new StringBuilder(); result.Append( "a" ); Assert.Equal( result.ToString(), GetResult() ); } - } } \ No newline at end of file diff --git a/test/Util.Ui.NgAlain.Tests/FooterToolbars/FooterToolbarTagHelperTest.cs b/test/Util.Ui.NgAlain.Tests/FooterToolbars/FooterToolbarTagHelperTest.cs new file mode 100644 index 000000000..3515cfd9c --- /dev/null +++ b/test/Util.Ui.NgAlain.Tests/FooterToolbars/FooterToolbarTagHelperTest.cs @@ -0,0 +1,94 @@ +using System.Text; +using Util.Ui.Angular.Configs; +using Util.Ui.Configs; +using Util.Ui.NgAlain.Components.FooterToolbars; +using Util.Ui.TagHelpers; +using Xunit; +using Xunit.Abstractions; + +namespace Util.Ui.NgAlain.Tests.FooterToolbars; + +/// +/// 底部工具栏测试 +/// +public class FooterToolbarTagHelperTest { + /// + /// 输出工具 + /// + private readonly ITestOutputHelper _output; + /// + /// TagHelper包装器 + /// + private readonly TagHelperWrapper _wrapper; + + /// + /// 测试初始化 + /// + public FooterToolbarTagHelperTest( ITestOutputHelper output ) { + _output = output; + _wrapper = new FooterToolbarTagHelper().ToWrapper(); + } + + /// + /// 获取结果 + /// + private string GetResult() { + var result = _wrapper.GetResult(); + _output.WriteLine( result ); + return result; + } + + /// + /// 测试默认输出 + /// + [Fact] + public void TestDefault() { + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试错误收集 + /// + [Fact] + public void TestErrorCollect() { + _wrapper.SetContextAttribute( UiConst.ErrorCollect, "true" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试额外信息 + /// + [Fact] + public void TestExtra() { + _wrapper.SetContextAttribute( UiConst.Extra, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试额外信息 + /// + [Fact] + public void TestBindExtra() { + _wrapper.SetContextAttribute( AngularConst.BindExtra, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试内容 + /// + [Fact] + public void TestAppendContent() { + _wrapper.AppendContent( "a" ); + var result = new StringBuilder(); + result.Append( "a" ); + Assert.Equal( result.ToString(), GetResult() ); + } +} \ No newline at end of file diff --git a/test/Util.Ui.NgAlain.Tests/I18n/I18nTagHelperTest.cs b/test/Util.Ui.NgAlain.Tests/I18n/I18nTagHelperTest.cs index 5916d5a4b..da76ac451 100644 --- a/test/Util.Ui.NgAlain.Tests/I18n/I18nTagHelperTest.cs +++ b/test/Util.Ui.NgAlain.Tests/I18n/I18nTagHelperTest.cs @@ -5,80 +5,80 @@ using Xunit; using Xunit.Abstractions; -namespace Util.Ui.NgAlain.Tests.I18n { +namespace Util.Ui.NgAlain.Tests.I18n; + +/// +/// i18n多语言显示组件测试 +/// +public class I18nTagHelperTest { + /// + /// 输出工具 + /// + private readonly ITestOutputHelper _output; /// - /// i18n多语言显示组件测试 + /// TagHelper包装器 /// - public class I18nTagHelperTest { - /// - /// 输出工具 - /// - private readonly ITestOutputHelper _output; - /// - /// TagHelper包装器 - /// - private readonly TagHelperWrapper _wrapper; + private readonly TagHelperWrapper _wrapper; - /// - /// 测试初始化 - /// - public I18nTagHelperTest( ITestOutputHelper output ) { - _output = output; - _wrapper = new I18nTagHelper().ToWrapper(); - } + /// + /// 测试初始化 + /// + public I18nTagHelperTest( ITestOutputHelper output ) { + _output = output; + _wrapper = new I18nTagHelper().ToWrapper(); + } - /// - /// 获取结果 - /// - private string GetResult() { - var result = _wrapper.GetResult(); - _output.WriteLine( result ); - return result; - } + /// + /// 获取结果 + /// + private string GetResult() { + var result = _wrapper.GetResult(); + _output.WriteLine( result ); + return result; + } - /// - /// 测试默认输出 - /// - [Fact] - public void TestDefault() { - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } + /// + /// 测试默认输出 + /// + [Fact] + public void TestDefault() { + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } - /// - /// 测试键 - /// - [Fact] - public void TestKey() { - _wrapper.SetContextAttribute( UiConst.Key, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } + /// + /// 测试键 + /// + [Fact] + public void TestKey() { + _wrapper.SetContextAttribute( UiConst.Key, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } - /// - /// 测试参数 - 参数有大括号 - /// - [Fact] - public void TestParam_1() { - _wrapper.SetContextAttribute( UiConst.Key, "a" ); - _wrapper.SetContextAttribute( UiConst.Param, " {id:1}" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } + /// + /// 测试参数 - 参数有大括号 + /// + [Fact] + public void TestParam_1() { + _wrapper.SetContextAttribute( UiConst.Key, "a" ); + _wrapper.SetContextAttribute( UiConst.Param, " {id:1}" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } - /// - /// 测试参数 - 参数没有大括号 - /// - [Fact] - public void TestParam_2() { - _wrapper.SetContextAttribute( UiConst.Key, "a" ); - _wrapper.SetContextAttribute( UiConst.Param, " id:1,name:'a' " ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } + /// + /// 测试参数 - 参数没有大括号 + /// + [Fact] + public void TestParam_2() { + _wrapper.SetContextAttribute( UiConst.Key, "a" ); + _wrapper.SetContextAttribute( UiConst.Param, " id:1,name:'a' " ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); } } \ No newline at end of file diff --git a/test/Util.Ui.NgAlain.Tests/PageHeaders/PageHeaderTagHelperTest.cs b/test/Util.Ui.NgAlain.Tests/PageHeaders/PageHeaderTagHelperTest.cs index b097205fe..94ddbc65c 100644 --- a/test/Util.Ui.NgAlain.Tests/PageHeaders/PageHeaderTagHelperTest.cs +++ b/test/Util.Ui.NgAlain.Tests/PageHeaders/PageHeaderTagHelperTest.cs @@ -8,447 +8,447 @@ using Xunit; using Xunit.Abstractions; -namespace Util.Ui.NgAlain.Tests.PageHeaders { - /// - /// 页头测试 - /// - public class PageHeaderTagHelperTest { - /// - /// 输出工具 - /// - private readonly ITestOutputHelper _output; - /// - /// TagHelper包装器 - /// - private readonly TagHelperWrapper _wrapper; - - /// - /// 测试初始化 - /// - public PageHeaderTagHelperTest( ITestOutputHelper output ) { - _output = output; - _wrapper = new PageHeaderTagHelper().ToWrapper(); - } - - /// - /// 获取结果 - /// - private string GetResult() { - var result = _wrapper.GetResult(); - _output.WriteLine( result ); - return result; - } - - /// - /// 测试默认输出 - /// - [Fact] - public void TestDefault() { - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试标题 - /// - [Fact] - public void TestTitle() { - _wrapper.SetContextAttribute( UiConst.Title, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试标题 - 支持多语言 - /// - [Fact] - public void TestTitle_I18n() { - NgZorroOptionsService.SetOptions( new NgZorroOptions{EnableI18n = true} ); - _wrapper.SetContextAttribute( UiConst.Title, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试创建标题 - /// - [Fact] - public void TestTitle_Create() { - _wrapper.SetContextAttribute( UiConst.TitleCreate, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试创建标题 - 支持多语言 - /// - [Fact] - public void TestTitle_Create_I18n() { - NgZorroOptionsService.SetOptions( new NgZorroOptions { EnableI18n = true } ); - _wrapper.SetContextAttribute( UiConst.TitleCreate, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试修改标题 - /// - [Fact] - public void TestTitle_Update() { - _wrapper.SetContextAttribute( UiConst.TitleUpdate, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试修改标题 - 支持多语言 - /// - [Fact] - public void TestTitle_Update_I18n() { - NgZorroOptionsService.SetOptions( new NgZorroOptions { EnableI18n = true } ); - _wrapper.SetContextAttribute( UiConst.TitleUpdate, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试标题 - 同时设置创建和修改标题 - /// - [Fact] - public void TestTitle_Create_Update() { - _wrapper.SetContextAttribute( UiConst.TitleCreate, "a" ); - _wrapper.SetContextAttribute( UiConst.TitleUpdate, "b" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试标题 - 同时设置创建和修改标题 - 支持多语言 - /// - [Fact] - public void TestTitle_Create_Update_I18n() { - NgZorroOptionsService.SetOptions( new NgZorroOptions { EnableI18n = true } ); - _wrapper.SetContextAttribute( UiConst.TitleCreate, "a" ); - _wrapper.SetContextAttribute( UiConst.TitleUpdate, "b" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试标题 - /// - [Fact] - public void TestBindTitle() { - _wrapper.SetContextAttribute( AngularConst.BindTitle, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试自动设置标题 - /// - [Fact] - public void TestAutoTitle() { - _wrapper.SetContextAttribute( UiConst.AutoTitle, true ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试自动设置标题 - /// - [Fact] - public void TestBindAutoTitle() { - _wrapper.SetContextAttribute( AngularConst.BindAutoTitle, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试同步标题 - /// - [Fact] - public void TestSyncTitle() { - _wrapper.SetContextAttribute( UiConst.SyncTitle, true ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试同步标题 - /// - [Fact] - public void TestBindSyncTitle() { - _wrapper.SetContextAttribute( AngularConst.BindSyncTitle, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试首页文本 - /// - [Fact] - public void TestHome() { - _wrapper.SetContextAttribute( UiConst.Home, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试首页文本 - /// - [Fact] - public void TestBindHome() { - _wrapper.SetContextAttribute( AngularConst.BindHome, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试首页链接 - /// - [Fact] - public void TestHomeLink() { - _wrapper.SetContextAttribute( UiConst.HomeLink, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试首页链接 - /// - [Fact] - public void TestBindHomeLink() { - _wrapper.SetContextAttribute( AngularConst.BindHomeLink, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试首页国际化 - /// - [Fact] - public void TestHomeI18n() { - _wrapper.SetContextAttribute( UiConst.HomeI18n, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试首页国际化 - /// - [Fact] - public void TestBindHomeI18n() { - _wrapper.SetContextAttribute( AngularConst.BindHomeI18n, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试自动生成导航 - /// - [Fact] - public void TestAutoBreadcrumb() { - _wrapper.SetContextAttribute( UiConst.AutoBreadcrumb, true ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试自动生成导航 - /// - [Fact] - public void TestBindAutoBreadcrumb() { - _wrapper.SetContextAttribute( AngularConst.BindAutoBreadcrumb, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试递归查找导航 - /// - [Fact] - public void TestRecursiveBreadcrumb() { - _wrapper.SetContextAttribute( UiConst.RecursiveBreadcrumb, true ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试递归查找导航 - /// - [Fact] - public void TestBindRecursiveBreadcrumb() { - _wrapper.SetContextAttribute( AngularConst.BindRecursiveBreadcrumb, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试加载状态 - /// - [Fact] - public void TestLoading() { - _wrapper.SetContextAttribute( UiConst.Loading, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试是否定宽 - /// - [Fact] - public void TestWide() { - _wrapper.SetContextAttribute( UiConst.Wide, true ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试是否定宽 - /// - [Fact] - public void TestBindWide() { - _wrapper.SetContextAttribute( AngularConst.BindWide, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试是否固定模式 - /// - [Fact] - public void TestFixed() { - _wrapper.SetContextAttribute( UiConst.Fixed, true ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试是否固定模式 - /// - [Fact] - public void TestBindFixed() { - _wrapper.SetContextAttribute( AngularConst.BindFixed, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试固定偏移值 - /// - [Fact] - public void TestFixedOffsetTop() { - _wrapper.SetContextAttribute( UiConst.FixedOffsetTop, "6" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试自定义导航区域 - /// - [Fact] - public void TestBreadcrumb() { - _wrapper.SetContextAttribute( UiConst.Breadcrumb, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试自定义Logo区域 - /// - [Fact] - public void TestLogo() { - _wrapper.SetContextAttribute( UiConst.Logo, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试自定义操作区域 - /// - [Fact] - public void TestAction() { - _wrapper.SetContextAttribute( UiConst.Action, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试自定义内容区域 - /// - [Fact] - public void TestContent() { - _wrapper.SetContextAttribute( UiConst.Content, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试自定义额外信息区域 - /// - [Fact] - public void TestExtra() { - _wrapper.SetContextAttribute( UiConst.Extra, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试自定义标签区域 - /// - [Fact] - public void TestTab() { - _wrapper.SetContextAttribute( UiConst.Tab, "a" ); - var result = new StringBuilder(); - result.Append( "" ); - Assert.Equal( result.ToString(), GetResult() ); - } - - /// - /// 测试内容 - /// - [Fact] - public void TestAppendContent() { - _wrapper.AppendContent( "a" ); - var result = new StringBuilder(); - result.Append( "a" ); - Assert.Equal( result.ToString(), GetResult() ); - } +namespace Util.Ui.NgAlain.Tests.PageHeaders; + +/// +/// 页头测试 +/// +public class PageHeaderTagHelperTest { + /// + /// 输出工具 + /// + private readonly ITestOutputHelper _output; + /// + /// TagHelper包装器 + /// + private readonly TagHelperWrapper _wrapper; + + /// + /// 测试初始化 + /// + public PageHeaderTagHelperTest( ITestOutputHelper output ) { + _output = output; + _wrapper = new PageHeaderTagHelper().ToWrapper(); + } + + /// + /// 获取结果 + /// + private string GetResult() { + var result = _wrapper.GetResult(); + _output.WriteLine( result ); + return result; + } + + /// + /// 测试默认输出 + /// + [Fact] + public void TestDefault() { + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试标题 + /// + [Fact] + public void TestTitle() { + _wrapper.SetContextAttribute( UiConst.Title, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试标题 - 支持多语言 + /// + [Fact] + public void TestTitle_I18n() { + NgZorroOptionsService.SetOptions( new NgZorroOptions{EnableI18n = true} ); + _wrapper.SetContextAttribute( UiConst.Title, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试创建标题 + /// + [Fact] + public void TestTitle_Create() { + _wrapper.SetContextAttribute( UiConst.TitleCreate, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试创建标题 - 支持多语言 + /// + [Fact] + public void TestTitle_Create_I18n() { + NgZorroOptionsService.SetOptions( new NgZorroOptions { EnableI18n = true } ); + _wrapper.SetContextAttribute( UiConst.TitleCreate, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试修改标题 + /// + [Fact] + public void TestTitle_Update() { + _wrapper.SetContextAttribute( UiConst.TitleUpdate, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试修改标题 - 支持多语言 + /// + [Fact] + public void TestTitle_Update_I18n() { + NgZorroOptionsService.SetOptions( new NgZorroOptions { EnableI18n = true } ); + _wrapper.SetContextAttribute( UiConst.TitleUpdate, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试标题 - 同时设置创建和修改标题 + /// + [Fact] + public void TestTitle_Create_Update() { + _wrapper.SetContextAttribute( UiConst.TitleCreate, "a" ); + _wrapper.SetContextAttribute( UiConst.TitleUpdate, "b" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试标题 - 同时设置创建和修改标题 - 支持多语言 + /// + [Fact] + public void TestTitle_Create_Update_I18n() { + NgZorroOptionsService.SetOptions( new NgZorroOptions { EnableI18n = true } ); + _wrapper.SetContextAttribute( UiConst.TitleCreate, "a" ); + _wrapper.SetContextAttribute( UiConst.TitleUpdate, "b" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试标题 + /// + [Fact] + public void TestBindTitle() { + _wrapper.SetContextAttribute( AngularConst.BindTitle, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试自动设置标题 + /// + [Fact] + public void TestAutoTitle() { + _wrapper.SetContextAttribute( UiConst.AutoTitle, true ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试自动设置标题 + /// + [Fact] + public void TestBindAutoTitle() { + _wrapper.SetContextAttribute( AngularConst.BindAutoTitle, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试同步标题 + /// + [Fact] + public void TestSyncTitle() { + _wrapper.SetContextAttribute( UiConst.SyncTitle, true ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试同步标题 + /// + [Fact] + public void TestBindSyncTitle() { + _wrapper.SetContextAttribute( AngularConst.BindSyncTitle, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试首页文本 + /// + [Fact] + public void TestHome() { + _wrapper.SetContextAttribute( UiConst.Home, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试首页文本 + /// + [Fact] + public void TestBindHome() { + _wrapper.SetContextAttribute( AngularConst.BindHome, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试首页链接 + /// + [Fact] + public void TestHomeLink() { + _wrapper.SetContextAttribute( UiConst.HomeLink, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试首页链接 + /// + [Fact] + public void TestBindHomeLink() { + _wrapper.SetContextAttribute( AngularConst.BindHomeLink, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试首页国际化 + /// + [Fact] + public void TestHomeI18n() { + _wrapper.SetContextAttribute( UiConst.HomeI18n, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试首页国际化 + /// + [Fact] + public void TestBindHomeI18n() { + _wrapper.SetContextAttribute( AngularConst.BindHomeI18n, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试自动生成导航 + /// + [Fact] + public void TestAutoBreadcrumb() { + _wrapper.SetContextAttribute( UiConst.AutoBreadcrumb, true ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试自动生成导航 + /// + [Fact] + public void TestBindAutoBreadcrumb() { + _wrapper.SetContextAttribute( AngularConst.BindAutoBreadcrumb, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试递归查找导航 + /// + [Fact] + public void TestRecursiveBreadcrumb() { + _wrapper.SetContextAttribute( UiConst.RecursiveBreadcrumb, true ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试递归查找导航 + /// + [Fact] + public void TestBindRecursiveBreadcrumb() { + _wrapper.SetContextAttribute( AngularConst.BindRecursiveBreadcrumb, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试加载状态 + /// + [Fact] + public void TestLoading() { + _wrapper.SetContextAttribute( UiConst.Loading, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试是否定宽 + /// + [Fact] + public void TestWide() { + _wrapper.SetContextAttribute( UiConst.Wide, true ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试是否定宽 + /// + [Fact] + public void TestBindWide() { + _wrapper.SetContextAttribute( AngularConst.BindWide, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试是否固定模式 + /// + [Fact] + public void TestFixed() { + _wrapper.SetContextAttribute( UiConst.Fixed, true ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试是否固定模式 + /// + [Fact] + public void TestBindFixed() { + _wrapper.SetContextAttribute( AngularConst.BindFixed, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试固定偏移值 + /// + [Fact] + public void TestFixedOffsetTop() { + _wrapper.SetContextAttribute( UiConst.FixedOffsetTop, "6" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试自定义导航区域 + /// + [Fact] + public void TestBreadcrumb() { + _wrapper.SetContextAttribute( UiConst.Breadcrumb, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试自定义Logo区域 + /// + [Fact] + public void TestLogo() { + _wrapper.SetContextAttribute( UiConst.Logo, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试自定义操作区域 + /// + [Fact] + public void TestAction() { + _wrapper.SetContextAttribute( UiConst.Action, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试自定义内容区域 + /// + [Fact] + public void TestContent() { + _wrapper.SetContextAttribute( UiConst.Content, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试自定义额外信息区域 + /// + [Fact] + public void TestExtra() { + _wrapper.SetContextAttribute( UiConst.Extra, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试自定义标签区域 + /// + [Fact] + public void TestTab() { + _wrapper.SetContextAttribute( UiConst.Tab, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试内容 + /// + [Fact] + public void TestAppendContent() { + _wrapper.AppendContent( "a" ); + var result = new StringBuilder(); + result.Append( "a" ); + Assert.Equal( result.ToString(), GetResult() ); } } \ No newline at end of file diff --git a/test/Util.Ui.NgAlain.Tests/Samples/Customer.cs b/test/Util.Ui.NgAlain.Tests/Samples/Customer.cs index a64907f76..83461fe6a 100644 --- a/test/Util.Ui.NgAlain.Tests/Samples/Customer.cs +++ b/test/Util.Ui.NgAlain.Tests/Samples/Customer.cs @@ -3,82 +3,82 @@ using System.ComponentModel.DataAnnotations; using Util.Domain.Biz.Enums; -namespace Util.Ui.NgAlain.Tests.Samples { +namespace Util.Ui.NgAlain.Tests.Samples; + +/// +/// 客户 +/// +public class Customer { + /// + /// 编码 + /// + [Description( "编码" )] + [MaxLength( 100 )] + [MinLength( 10, ErrorMessage = "编码最小为10位" )] + [Required(ErrorMessage = "编码不能是空值" )] + public string Code { get; set; } + /// + /// 姓名 + /// + [Description( "姓名" )] + [MaxLength( 200 )] + public string Name { get; set; } + /// + /// 昵称 + /// + [Description( "昵称" )] + [MaxLength( 50 )] + public string Nickname { get; set; } + /// + /// 密码 + /// + [Description( "密码" )] + [DataType(DataType.Password)] + public string Password { get; set; } + /// + /// 性别 + /// + [Description( "性别" )] + public Gender? Gender { get; set; } + /// + /// 出生日期 + /// + [Description( "出生日期" )] + [Required] + public DateTime? Birthday { get; set; } + /// + /// 民族 + /// + [Description( "民族" )] + public Nation? Nation { get; set; } + /// + /// 手机号 + /// + [Description( "手机号" )] + [Phone( ErrorMessage = "手机号错误" )] + public int Phone { get; set; } + /// + /// 身份证 + /// + [Description( "身份证" )] + [IdCard( ErrorMessage = "身份证错误" )] + public int IdCard { get; set; } + /// + /// 年龄 + /// + [Description( "年龄" )] + [Required] + [Range( 5.5,8.8 )] + public double Age { get; set; } + /// + /// 电子邮件 + /// + [Description( "电子邮件" )] + [EmailAddress(ErrorMessage = "email错误")] + public string Email { get; set; } /// - /// 客户 - /// - public class Customer { - /// - /// 编码 - /// - [Description( "编码" )] - [MaxLength( 100 )] - [MinLength( 10, ErrorMessage = "编码最小为10位" )] - [Required(ErrorMessage = "编码不能是空值" )] - public string Code { get; set; } - /// - /// 姓名 - /// - [Description( "姓名" )] - [MaxLength( 200 )] - public string Name { get; set; } - /// - /// 昵称 - /// - [Description( "昵称" )] - [MaxLength( 50 )] - public string Nickname { get; set; } - /// - /// 密码 - /// - [Description( "密码" )] - [DataType(DataType.Password)] - public string Password { get; set; } - /// - /// 性别 - /// - [Description( "性别" )] - public Gender? Gender { get; set; } - /// - /// 出生日期 - /// - [Description( "出生日期" )] - [Required] - public DateTime? Birthday { get; set; } - /// - /// 民族 - /// - [Description( "民族" )] - public Nation? Nation { get; set; } - /// - /// 手机号 - /// - [Description( "手机号" )] - [Phone( ErrorMessage = "手机号错误" )] - public int Phone { get; set; } - /// - /// 身份证 - /// - [Description( "身份证" )] - [IdCard( ErrorMessage = "身份证错误" )] - public int IdCard { get; set; } - /// - /// 年龄 - /// - [Description( "年龄" )] - [Required] - [Range( 5.5,8.8 )] - public double Age { get; set; } - /// - /// 电子邮件 - /// - [Description( "电子邮件" )] - [EmailAddress(ErrorMessage = "email错误")] - public string Email { get; set; } - /// - /// 启用 - /// - [Description( "启用" )] - public bool Enabled { get; set; } - } + /// 启用 + /// + [Description( "启用" )] + public bool Enabled { get; set; } } \ No newline at end of file diff --git a/test/Util.Ui.NgAlain.Tests/Startup.cs b/test/Util.Ui.NgAlain.Tests/Startup.cs index ddf3410a9..e3502122e 100644 --- a/test/Util.Ui.NgAlain.Tests/Startup.cs +++ b/test/Util.Ui.NgAlain.Tests/Startup.cs @@ -2,23 +2,23 @@ using Microsoft.Extensions.Hosting; using Xunit.DependencyInjection.Logging; -namespace Util.Ui.NgAlain.Tests { +namespace Util.Ui.NgAlain.Tests; + +/// +/// +/// +public class Startup { /// - /// + /// /// - public class Startup { - /// - /// - /// - public void ConfigureHost( IHostBuilder hostBuilder ) { + public void ConfigureHost( IHostBuilder hostBuilder ) { hostBuilder.ConfigureDefaults( null ).AddUtil(); } - /// - /// ÷ - /// - public void ConfigureServices( IServiceCollection services ) { + /// + /// ÷ + /// + public void ConfigureServices( IServiceCollection services ) { services.AddLogging( logBuilder => logBuilder.AddXunitOutput() ); } - } -} +} \ No newline at end of file diff --git a/test/Util.Ui.NgAlain.Tests/Tinymce/TinymceTagHelperTest.Expression.cs b/test/Util.Ui.NgAlain.Tests/Tinymce/TinymceTagHelperTest.Expression.cs index 17c8c5b85..55b8736d4 100644 --- a/test/Util.Ui.NgAlain.Tests/Tinymce/TinymceTagHelperTest.Expression.cs +++ b/test/Util.Ui.NgAlain.Tests/Tinymce/TinymceTagHelperTest.Expression.cs @@ -1,16 +1,17 @@ using System.Text; using Xunit; -namespace Util.Ui.NgAlain.Tests.Tinymce { +namespace Util.Ui.NgAlain.Tests.Tinymce; + +/// +/// Tinymce富文本编辑器测试 - 表达式解析测试 +/// +public partial class TinymceTagHelperTest { /// - /// Tinymce富文本编辑器测试 - 表达式解析测试 + /// 测试解析表达式属性for /// - public partial class TinymceTagHelperTest { - /// - /// 测试解析表达式属性for - /// - [Fact] - public void TestFor_1() { + [Fact] + public void TestFor_1() { _wrapper.SetExpression( t => t.Code ); var result = new StringBuilder(); result.Append( "" ); @@ -27,6 +28,4 @@ public void TestFor_1() { result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - } -} - +} \ No newline at end of file diff --git a/test/Util.Ui.NgAlain.Tests/Tinymce/TinymceTagHelperTest.cs b/test/Util.Ui.NgAlain.Tests/Tinymce/TinymceTagHelperTest.cs index 77186b41f..27f35d557 100644 --- a/test/Util.Ui.NgAlain.Tests/Tinymce/TinymceTagHelperTest.cs +++ b/test/Util.Ui.NgAlain.Tests/Tinymce/TinymceTagHelperTest.cs @@ -9,207 +9,208 @@ using Xunit; using Xunit.Abstractions; -namespace Util.Ui.NgAlain.Tests.Tinymce { - /// - /// Tinymce富文本编辑器测试 - /// - public partial class TinymceTagHelperTest { - /// - /// 输出工具 - /// - private readonly ITestOutputHelper _output; - /// - /// TagHelper包装器 - /// - private readonly TagHelperWrapper _wrapper; - - /// - /// 测试初始化 - /// - public TinymceTagHelperTest( ITestOutputHelper output ) { +namespace Util.Ui.NgAlain.Tests.Tinymce; + +/// +/// Tinymce富文本编辑器测试 +/// +public partial class TinymceTagHelperTest { + /// + /// 输出工具 + /// + private readonly ITestOutputHelper _output; + /// + /// TagHelper包装器 + /// + private readonly TagHelperWrapper _wrapper; + + /// + /// 测试初始化 + /// + public TinymceTagHelperTest( ITestOutputHelper output ) { _output = output; _wrapper = new TinymceTagHelper().ToWrapper(); Id.SetId( "id" ); } - /// - /// 获取结果 - /// - private string GetResult() { + /// + /// 获取结果 + /// + private string GetResult() { var result = _wrapper.GetResult(); _output.WriteLine( result ); return result; } - /// - /// 测试默认输出 - /// - [Fact] - public void TestDefault() { + /// + /// 测试默认输出 + /// + [Fact] + public void TestDefault() { var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试品牌 - /// - [Fact] - public void TestBranding() { + /// + /// 测试品牌 + /// + [Fact] + public void TestBranding() { _wrapper.SetContextAttribute( UiConst.Branding, true ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试是否允许粘贴图片 - /// - [Fact] - public void TestPasteDataImages() { + /// + /// 测试是否允许粘贴图片 + /// + [Fact] + public void TestPasteDataImages() { _wrapper.SetContextAttribute( UiConst.PasteDataImages, false ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试菜单栏 - /// - [Fact] - public void TestMenubar() { + /// + /// 测试菜单栏 + /// + [Fact] + public void TestMenubar() { _wrapper.SetContextAttribute( UiConst.Menubar, "a" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试工具栏模式 - /// - [Fact] - public void TestToolbarMode() { + /// + /// 测试工具栏模式 + /// + [Fact] + public void TestToolbarMode() { _wrapper.SetContextAttribute( UiConst.ToolbarMode, TinymceToolbarMode.Scrolling ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试插件列表 - /// - [Fact] - public void TestPlugins() { + /// + /// 测试插件列表 + /// + [Fact] + public void TestPlugins() { _wrapper.SetContextAttribute( UiConst.Plugins, "a" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试工具栏 - /// - [Fact] - public void TestToolbar() { + /// + /// 测试工具栏 + /// + [Fact] + public void TestToolbar() { _wrapper.SetContextAttribute( UiConst.Toolbar, "a" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试禁用 - /// - [Fact] - public void TestDisabled() { + /// + /// 测试禁用 + /// + [Fact] + public void TestDisabled() { _wrapper.SetContextAttribute( UiConst.Disabled, false ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试禁用 - /// - [Fact] - public void TestBindDisabled() { + /// + /// 测试禁用 + /// + [Fact] + public void TestBindDisabled() { _wrapper.SetContextAttribute( AngularConst.BindDisabled, "a" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试必填项验证 - /// - [Fact] - public void TestRequired() { + /// + /// 测试必填项验证 + /// + [Fact] + public void TestRequired() { _wrapper.SetContextAttribute( UiConst.Required, "a" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试占位文本 - /// - [Fact] - public void TestPlaceholder() { + /// + /// 测试占位文本 + /// + [Fact] + public void TestPlaceholder() { _wrapper.SetContextAttribute( UiConst.Placeholder, "a" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试占位文本 - /// - [Fact] - public void TestBindPlaceholder() { + /// + /// 测试占位文本 + /// + [Fact] + public void TestBindPlaceholder() { _wrapper.SetContextAttribute( AngularConst.BindPlaceholder, "a" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试配置 - /// - [Fact] - public void TestConfig() { + /// + /// 测试配置 + /// + [Fact] + public void TestConfig() { _wrapper.SetContextAttribute( UiConst.Config, "a" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试模型绑定 - /// - [Fact] - public void TestNgModel() { + /// + /// 测试模型绑定 + /// + [Fact] + public void TestNgModel() { _wrapper.SetContextAttribute( AngularConst.NgModel, "a" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试模型绑定 - /// - [Fact] - public void TestBindNgModel() { + /// + /// 测试模型绑定 + /// + [Fact] + public void TestBindNgModel() { _wrapper.SetContextAttribute( AngularConst.BindNgModel, "a" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试标签文本 - /// - [Fact] - public void TestLabelText() { + /// + /// 测试标签文本 + /// + [Fact] + public void TestLabelText() { _wrapper.SetContextAttribute( UiConst.LabelText, "a" ); var result = new StringBuilder(); result.Append( "" ); @@ -221,26 +222,25 @@ public void TestLabelText() { Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试内容 - /// - [Fact] - public void TestAppendContent() { + /// + /// 测试内容 + /// + [Fact] + public void TestAppendContent() { _wrapper.AppendContent( "a" ); var result = new StringBuilder(); result.Append( "a" ); Assert.Equal( result.ToString(), GetResult() ); } - /// - /// 测试内容变更事件 - /// - [Fact] - public void TestOnChange() { + /// + /// 测试内容变更事件 + /// + [Fact] + public void TestOnChange() { _wrapper.SetContextAttribute( UiConst.OnChange, "a" ); var result = new StringBuilder(); result.Append( "" ); Assert.Equal( result.ToString(), GetResult() ); } - } } \ No newline at end of file diff --git a/test/Util.Ui.NgZorro.Tests/Forms/SearchFormTagHelperTest.cs b/test/Util.Ui.NgZorro.Tests/Forms/SearchFormTagHelperTest.cs index ed399e696..fddb02fc2 100644 --- a/test/Util.Ui.NgZorro.Tests/Forms/SearchFormTagHelperTest.cs +++ b/test/Util.Ui.NgZorro.Tests/Forms/SearchFormTagHelperTest.cs @@ -167,7 +167,7 @@ public void Test_4() { } /// - /// 测试查询表单 - 8个栅格列 - 初始显示2个条件,每行显示6个条件 + /// 测试查询表单 - 初始显示2个条件,每行显示6个条件 /// [Fact] public void Test_5() { diff --git a/test/Util.Ui.NgZorro.Tests/Links/ATagHelperTest.cs b/test/Util.Ui.NgZorro.Tests/Links/ATagHelperTest.cs index e39170c12..d061ca8c3 100644 --- a/test/Util.Ui.NgZorro.Tests/Links/ATagHelperTest.cs +++ b/test/Util.Ui.NgZorro.Tests/Links/ATagHelperTest.cs @@ -354,6 +354,33 @@ public void TestIsSearch_i18n() { Assert.Equal( result.ToString(), GetResult() ); } + /// + /// 测试显示表格设置 + /// + [Fact] + public void TestShowTableSettings() { + _wrapper.SetContextAttribute( UiConst.ShowTableSettings, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试显示表格设置 - 多语言 + /// + [Fact] + public void TestShowTableSettings_i18n() { + NgZorroOptionsService.SetOptions( new NgZorroOptions { EnableI18n = true } ); + _wrapper.SetContextAttribute( UiConst.ShowTableSettings, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + /// /// 测试内容 /// diff --git a/test/Util.Ui.NgZorro.Tests/Tables/TableColumnTagHelperTest.cs b/test/Util.Ui.NgZorro.Tests/Tables/TableColumnTagHelperTest.cs index ef8f7ff35..cbfc4e30f 100644 --- a/test/Util.Ui.NgZorro.Tests/Tables/TableColumnTagHelperTest.cs +++ b/test/Util.Ui.NgZorro.Tests/Tables/TableColumnTagHelperTest.cs @@ -362,6 +362,28 @@ public void TestBindIndentSize() { Assert.Equal( result.ToString(), GetResult() ); } + /// + /// 测试单元格控件 + /// + [Fact] + public void TestCellControl() { + _wrapper.SetContextAttribute( UiConst.CellControl, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试单元格控件 + /// + [Fact] + public void TestBindCellControl() { + _wrapper.SetContextAttribute( AngularConst.BindCellControl, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + /// /// 测试内容 /// diff --git a/test/Util.Ui.NgZorro.Tests/Tables/TableHeadColumnTagHelperTest.cs b/test/Util.Ui.NgZorro.Tests/Tables/TableHeadColumnTagHelperTest.cs index 5a67c9d5b..a6eaa3aa1 100644 --- a/test/Util.Ui.NgZorro.Tests/Tables/TableHeadColumnTagHelperTest.cs +++ b/test/Util.Ui.NgZorro.Tests/Tables/TableHeadColumnTagHelperTest.cs @@ -525,6 +525,28 @@ public void TestBindColumnKey() { Assert.Equal( result.ToString(), GetResult() ); } + /// + /// 测试单元格控件 + /// + [Fact] + public void TestCellControl() { + _wrapper.SetContextAttribute( UiConst.CellControl, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试单元格控件 + /// + [Fact] + public void TestBindCellControl() { + _wrapper.SetContextAttribute( AngularConst.BindCellControl, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + /// /// 测试内容 /// diff --git a/test/Util.Ui.NgZorro.Tests/Tables/TableTagHelperTest.CustomColumn.cs b/test/Util.Ui.NgZorro.Tests/Tables/TableTagHelperTest.CustomColumn.cs new file mode 100644 index 000000000..67fa02da9 --- /dev/null +++ b/test/Util.Ui.NgZorro.Tests/Tables/TableTagHelperTest.CustomColumn.cs @@ -0,0 +1,492 @@ +using System.Text; +using Util.Ui.Configs; +using Util.Ui.NgZorro.Components.Tables; +using Xunit; + +namespace Util.Ui.NgZorro.Tests.Tables; + +/// +/// 表格测试 - 自定义列扩展 +/// +public partial class TableTagHelperTest { + /// + /// 测试启用自定义列 + /// + [Fact] + public void TestEnableCustomColumn_1() { + _wrapper.SetContextAttribute( UiConst.EnableCustomColumn, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试启用自定义列 - 添加1列,自动创建表头 + /// + [Fact] + public void TestEnableCustomColumn_2() { + //启用自定义列 + _wrapper.SetContextAttribute( UiConst.EnableCustomColumn, "a" ); + + //创建列 + var column = new TableColumnTagHelper().ToWrapper(); + column.SetContextAttribute( UiConst.Title, "a" ); + column.SetContextAttribute( UiConst.Column, "b" ); + _wrapper.AppendContent( column ); + + //结果 + var result = new StringBuilder(); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "a" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "{{row.b}}" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试启用自定义列 - 添加1列,自动创建表头 - 设置CellControl + /// + [Fact] + public void TestEnableCustomColumn_3() { + //启用自定义列 + _wrapper.SetContextAttribute( UiConst.EnableCustomColumn, "a" ); + + //创建列 + var column = new TableColumnTagHelper().ToWrapper(); + column.SetContextAttribute( UiConst.Title, "a" ); + column.SetContextAttribute( UiConst.Column, "b" ); + column.SetContextAttribute( UiConst.CellControl, "c" ); + _wrapper.AppendContent( column ); + + //结果 + var result = new StringBuilder(); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "a" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "{{row.b}}" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试启用自定义列 - 添加1列,自动创建表头 - 设置宽度 + /// + [Fact] + public void TestEnableCustomColumn_4() { + //启用自定义列 + _wrapper.SetContextAttribute( UiConst.EnableCustomColumn, "a" ); + + //创建列 + var column = new TableColumnTagHelper().ToWrapper(); + column.SetContextAttribute( UiConst.Title, "a" ); + column.SetContextAttribute( UiConst.Column, "b" ); + column.SetContextAttribute( UiConst.Width, "100" ); + _wrapper.AppendContent( column ); + + //结果 + var result = new StringBuilder(); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "a" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "{{row.b}}" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试启用自定义列 - 添加1列,自动创建表头 - 设置宽度 - px + /// + [Fact] + public void TestEnableCustomColumn_5() { + //启用自定义列 + _wrapper.SetContextAttribute( UiConst.EnableCustomColumn, "a" ); + + //创建列 + var column = new TableColumnTagHelper().ToWrapper(); + column.SetContextAttribute( UiConst.Title, "a" ); + column.SetContextAttribute( UiConst.Column, "b" ); + column.SetContextAttribute( UiConst.Width, "100px" ); + _wrapper.AppendContent( column ); + + //结果 + var result = new StringBuilder(); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "a" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "{{row.b}}" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试启用自定义列 - 添加1列,自动创建表头 - 设置宽度 - % + /// + [Fact] + public void TestEnableCustomColumn_6() { + //启用自定义列 + _wrapper.SetContextAttribute( UiConst.EnableCustomColumn, "a" ); + + //创建列 + var column = new TableColumnTagHelper().ToWrapper(); + column.SetContextAttribute( UiConst.Title, "a" ); + column.SetContextAttribute( UiConst.Column, "b" ); + column.SetContextAttribute( UiConst.Width, "10%" ); + _wrapper.AppendContent( column ); + + //结果 + var result = new StringBuilder(); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "a" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "{{row.b}}" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试启用自定义列 - 添加1列,设置完整结构 + /// + [Fact] + public void TestEnableCustomColumn_7() { + //启用自定义列 + _wrapper.SetContextAttribute( UiConst.EnableCustomColumn, "a" ); + + //创建表头 + var head = new TableHeadTagHelper().ToWrapper(); + _wrapper.AppendContent( head ); + + //创建表头行 + var headRow = new TableRowTagHelper().ToWrapper(); + head.AppendContent( headRow ); + + //创建表头单元格 + var th = new TableHeadColumnTagHelper().ToWrapper(); + th.SetContextAttribute( UiConst.Title, "a" ); + headRow.AppendContent( th ); + + //创建表格主体 + var body = new TableBodyTagHelper().ToWrapper(); + _wrapper.AppendContent( body ); + + //创建表格主体行 + var row = new TableRowTagHelper().ToWrapper(); + body.AppendContent( row ); + + //创建列 + var column = new TableColumnTagHelper().ToWrapper(); + column.SetContextAttribute( UiConst.Column, "b" ); + row.AppendContent( column ); + + //结果 + var result = new StringBuilder(); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "a" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "{{row.b}}" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试启用自定义列 - 添加1列,设置完整结构 - th设置CellControl + /// + [Fact] + public void TestEnableCustomColumn_8() { + //启用自定义列 + _wrapper.SetContextAttribute( UiConst.EnableCustomColumn, "a" ); + + //创建表头 + var head = new TableHeadTagHelper().ToWrapper(); + _wrapper.AppendContent( head ); + + //创建表头行 + var headRow = new TableRowTagHelper().ToWrapper(); + head.AppendContent( headRow ); + + //创建表头单元格 + var th = new TableHeadColumnTagHelper().ToWrapper(); + th.SetContextAttribute( UiConst.Title, "a" ); + th.SetContextAttribute( UiConst.CellControl, "c" ); + headRow.AppendContent( th ); + + //创建表格主体 + var body = new TableBodyTagHelper().ToWrapper(); + _wrapper.AppendContent( body ); + + //创建表格主体行 + var row = new TableRowTagHelper().ToWrapper(); + body.AppendContent( row ); + + //创建列 + var column = new TableColumnTagHelper().ToWrapper(); + column.SetContextAttribute( UiConst.Column, "b" ); + row.AppendContent( column ); + + //结果 + var result = new StringBuilder(); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "a" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "{{row.b}}" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试启用自定义列 - 添加1列,设置完整结构 - td设置宽度 + /// + [Fact] + public void TestEnableCustomColumn_9() { + //启用自定义列 + _wrapper.SetContextAttribute( UiConst.EnableCustomColumn, "a" ); + + //创建表头 + var head = new TableHeadTagHelper().ToWrapper(); + _wrapper.AppendContent( head ); + + //创建表头行 + var headRow = new TableRowTagHelper().ToWrapper(); + head.AppendContent( headRow ); + + //创建表头单元格 + var th = new TableHeadColumnTagHelper().ToWrapper(); + th.SetContextAttribute( UiConst.Title, "a" ); + headRow.AppendContent( th ); + + //创建表格主体 + var body = new TableBodyTagHelper().ToWrapper(); + _wrapper.AppendContent( body ); + + //创建表格主体行 + var row = new TableRowTagHelper().ToWrapper(); + body.AppendContent( row ); + + //创建列 + var column = new TableColumnTagHelper().ToWrapper(); + column.SetContextAttribute( UiConst.Column, "b" ); + column.SetContextAttribute( UiConst.Width, "100" ); + row.AppendContent( column ); + + //结果 + var result = new StringBuilder(); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "a" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "{{row.b}}" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试启用自定义列 - 添加1列,设置完整结构 - th设置宽度 + /// + [Fact] + public void TestEnableCustomColumn_10() { + //启用自定义列 + _wrapper.SetContextAttribute( UiConst.EnableCustomColumn, "a" ); + + //创建表头 + var head = new TableHeadTagHelper().ToWrapper(); + _wrapper.AppendContent( head ); + + //创建表头行 + var headRow = new TableRowTagHelper().ToWrapper(); + head.AppendContent( headRow ); + + //创建表头单元格 + var th = new TableHeadColumnTagHelper().ToWrapper(); + th.SetContextAttribute( UiConst.Width, "100" ); + th.SetContextAttribute( UiConst.Title, "a" ); + headRow.AppendContent( th ); + + //创建表格主体 + var body = new TableBodyTagHelper().ToWrapper(); + _wrapper.AppendContent( body ); + + //创建表格主体行 + var row = new TableRowTagHelper().ToWrapper(); + body.AppendContent( row ); + + //创建列 + var column = new TableColumnTagHelper().ToWrapper(); + column.SetContextAttribute( UiConst.Column, "b" ); + row.AppendContent( column ); + + //结果 + var result = new StringBuilder(); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "a" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "{{row.b}}" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试启用自定义列 - 添加2列,自动创建表头 + /// + [Fact] + public void TestEnableCustomColumn_11() { + //启用自定义列 + _wrapper.SetContextAttribute( UiConst.EnableCustomColumn, "a" ); + + //创建列1 + var column = new TableColumnTagHelper().ToWrapper(); + column.SetContextAttribute( UiConst.Title, "a" ); + column.SetContextAttribute( UiConst.Column, "b" ); + _wrapper.AppendContent( column ); + + //创建列2 + var column2 = new TableColumnTagHelper().ToWrapper(); + column2.SetContextAttribute( UiConst.Title, "c" ); + column2.SetContextAttribute( UiConst.Column, "d" ); + _wrapper.AppendContent( column2 ); + + //结果 + var result = new StringBuilder(); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "a" ); + result.Append( "c" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "{{row.b}}" ); + result.Append( "{{row.d}}" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + + /// + /// 测试启用自定义列 - 添加1列,自动创建表头 - 设置acl + /// + [Fact] + public void TestEnableCustomColumn_12() { + //启用自定义列 + _wrapper.SetContextAttribute( UiConst.EnableCustomColumn, "a" ); + + //创建列 + var column = new TableColumnTagHelper().ToWrapper(); + column.SetContextAttribute( UiConst.Title, "a" ); + column.SetContextAttribute( UiConst.Column, "b" ); + column.SetContextAttribute( UiConst.Acl, "c" ); + _wrapper.AppendContent( column ); + + //结果 + var result = new StringBuilder(); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "a" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "{{row.b}}" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } +} \ No newline at end of file diff --git a/test/Util.Ui.NgZorro.Tests/Tables/TableTagHelperTest.cs b/test/Util.Ui.NgZorro.Tests/Tables/TableTagHelperTest.cs index 2eaec40ab..d6a283e08 100644 --- a/test/Util.Ui.NgZorro.Tests/Tables/TableTagHelperTest.cs +++ b/test/Util.Ui.NgZorro.Tests/Tables/TableTagHelperTest.cs @@ -700,6 +700,17 @@ public void TestBindLayout() { Assert.Equal( result.ToString(), GetResult() ); } + /// + /// 测试自定义列 + /// + [Fact] + public void TestCustomColumn() { + _wrapper.SetContextAttribute( UiConst.CustomColumn, "a" ); + var result = new StringBuilder(); + result.Append( "" ); + Assert.Equal( result.ToString(), GetResult() ); + } + /// /// 测试内容 ///