Skip to content

Commit b9c67f8

Browse files
committed
Angular UI下拉组件分组项文本支持多语言
1 parent bc5b515 commit b9c67f8

File tree

10 files changed

+57
-9
lines changed

10 files changed

+57
-9
lines changed

build/version.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<VersionMajor>7</VersionMajor>
44
<VersionMinor>1</VersionMinor>
5-
<VersionPatch>102</VersionPatch>
5+
<VersionPatch>106</VersionPatch>
66
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
77
<VersionSuffix></VersionSuffix>
88
</PropertyGroup>

src/Util.Scheduling.Hangfire/HangfireExecutionContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public T GetService<T>() {
3737
/// </summary>
3838
/// <typeparam name="T">参数类型</typeparam>
3939
public T GetData<T>() {
40-
return Util.Helpers.Convert.To<T>( _data );
40+
var result = Util.Helpers.Convert.To<T>( _data );
41+
return result ?? Util.Helpers.Json.ToObject<T>( _data.SafeString() );
4142
}
4243
}

src/Util.Ui.NgZorro/Components/Descriptions/Builders/DescriptionItemBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected override void ConfigContent( Config config ) {
7979
/// 配置值
8080
/// </summary>
8181
private void ConfigValue() {
82-
var dataType = _config.GetValue<DataType?>( UiConst.DataType );
82+
var dataType = _config.GetValue<DataType?>( UiConst.Type );
8383
var value = _config.GetValue( UiConst.Value );
8484
if ( value.IsEmpty() )
8585
return;

src/Util.Ui.NgZorro/Components/Display/Builders/DisplayBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public DisplayBuilder( Config config ) : base( config, "span" ) {
2828
/// 配置值
2929
/// </summary>
3030
public DisplayBuilder Value() {
31-
var dataType = _config.GetValue<DataType?>( UiConst.DataType );
31+
var dataType = _config.GetValue<DataType?>( UiConst.Type );
3232
var value = _config.GetValue( UiConst.Value );
3333
if ( value.IsEmpty() )
3434
return this;

src/Util.Ui.NgZorro/Components/Display/DisplayTagHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Util.Ui.NgZorro.Components.Display.Helpers;
66
using Util.Ui.NgZorro.Components.Display.Renders;
77
using Util.Ui.NgZorro.Components.Forms.Helpers;
8+
using Util.Ui.NgZorro.Enums;
89
using Util.Ui.Renders;
910

1011
namespace Util.Ui.NgZorro.Components.Display;
@@ -27,6 +28,10 @@ public class DisplayTagHelper : FormContainerTagHelperBase {
2728
/// </summary>
2829
public string Value { get; set; }
2930
/// <summary>
31+
/// 数据类型
32+
/// </summary>
33+
public DataType Type { get; set; }
34+
/// <summary>
3035
/// 是否显示左侧的标签,默认不显示,注意:设置For属性时生效
3136
/// </summary>
3237
public bool ShowLabel { get; set; }

src/Util.Ui.NgZorro/Components/Display/Helpers/DisplayExpressionLoader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ private bool IsEnabledFormLabel( Config config ) {
4646
protected virtual void LoadValue( Config config, ModelExpressionInfo info ) {
4747
config.SetAttribute( UiConst.Value, info.SafePropertyName, false );
4848
if ( info.IsBool ) {
49-
config.SetAttribute( UiConst.DataType, DataType.Bool );
49+
config.SetAttribute( UiConst.Type, DataType.Bool );
5050
return;
5151
}
5252
if ( info.IsDate ) {
53-
config.SetAttribute( UiConst.DataType, DataType.Date );
53+
config.SetAttribute( UiConst.Type, DataType.Date );
5454
return;
5555
}
5656
}

src/Util.Ui.NgZorro/Components/Selects/Builders/SelectBuilder.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ private void ConfigOptionGroup() {
629629
var groupBuilder = new OptionGroupBuilder( _config );
630630
containerBuilder.AppendContent( groupBuilder );
631631
groupBuilder.NgFor( $"let group of {ExtendId}.optionGroups" );
632-
groupBuilder.BindLabel( "group.text" );
632+
ConfigGroupBindLabel( groupBuilder );
633633
var optionBuilder = new OptionBuilder( _config );
634634
groupBuilder.AppendContent( optionBuilder );
635635
optionBuilder.NgFor( "let item of group.value" );
@@ -638,4 +638,16 @@ private void ConfigOptionGroup() {
638638
optionBuilder.Disabled( "item.disabled" );
639639
AppendContent( containerBuilder );
640640
}
641+
642+
/// <summary>
643+
/// 配置选项组标签文本
644+
/// </summary>
645+
private void ConfigGroupBindLabel( OptionGroupBuilder groupBuilder ) {
646+
var options = NgZorroOptionsService.GetOptions();
647+
if( options.EnableI18n ) {
648+
groupBuilder.BindLabel( "group.text|i18n" );
649+
return;
650+
}
651+
groupBuilder.BindLabel( "group.text" );
652+
}
641653
}

test/Util.Ui.NgZorro.Tests/Display/DisplayTagHelperTest.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Util.Ui.NgZorro.Components.Display;
44
using Util.Ui.NgZorro.Components.Forms.Configs;
55
using Util.Ui.NgZorro.Configs;
6+
using Util.Ui.NgZorro.Enums;
67
using Util.Ui.NgZorro.Tests.Samples;
78
using Util.Ui.TagHelpers;
89
using Xunit;
@@ -62,6 +63,35 @@ public void TestValue() {
6263
Assert.Equal( result.ToString(), GetResult() );
6364
}
6465

66+
/// <summary>
67+
/// 测试值 - 布尔类型
68+
/// </summary>
69+
[Fact]
70+
public void TestValue_Bool() {
71+
_wrapper.SetContextAttribute( UiConst.Value, "a" );
72+
_wrapper.SetContextAttribute( UiConst.Type,DataType.Bool );
73+
var result = new StringBuilder();
74+
result.Append( "<span>" );
75+
result.Append( "{{a?'是':'否'}}" );
76+
result.Append( "</span>" );
77+
Assert.Equal( result.ToString(), GetResult() );
78+
}
79+
80+
/// <summary>
81+
/// 测试值 - 布尔类型 - 多语言
82+
/// </summary>
83+
[Fact]
84+
public void TestValue_Bool_I18n() {
85+
NgZorroOptionsService.SetOptions( new NgZorroOptions { EnableI18n = true } );
86+
_wrapper.SetContextAttribute( UiConst.Value, "a" );
87+
_wrapper.SetContextAttribute( UiConst.Type, DataType.Bool );
88+
var result = new StringBuilder();
89+
result.Append( "<span>" );
90+
result.Append( "{{(a?'util.yes':'util.no')|i18n}}" );
91+
result.Append( "</span>" );
92+
Assert.Equal( result.ToString(), GetResult() );
93+
}
94+
6595
/// <summary>
6696
/// 测试设置内容
6797
/// </summary>

test/Util.Ui.NgZorro.Tests/Selects/SelectTagHelperTest.Expression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void TestFor_Bool_I18n() {
5555
result.Append( "</nz-option>" );
5656
result.Append( "</ng-container>" );
5757
result.Append( "<ng-container *ngIf=\"x_id.isGroup\">" );
58-
result.Append( "<nz-option-group *ngFor=\"let group of x_id.optionGroups\" [nzLabel]=\"group.text\">" );
58+
result.Append( "<nz-option-group *ngFor=\"let group of x_id.optionGroups\" [nzLabel]=\"group.text|i18n\">" );
5959
result.Append( "<nz-option *ngFor=\"let item of group.value\" [nzDisabled]=\"item.disabled\" [nzLabel]=\"item.text|i18n\" [nzValue]=\"item.value\">" );
6060
result.Append( "</nz-option>" );
6161
result.Append( "</nz-option-group>" );

test/Util.Ui.NgZorro.Tests/Selects/SelectTagHelperTest.Extend.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void TestData_I18n() {
181181
result.Append( "</nz-option>" );
182182
result.Append( "</ng-container>" );
183183
result.Append( "<ng-container *ngIf=\"x_id.isGroup\">" );
184-
result.Append( "<nz-option-group *ngFor=\"let group of x_id.optionGroups\" [nzLabel]=\"group.text\">" );
184+
result.Append( "<nz-option-group *ngFor=\"let group of x_id.optionGroups\" [nzLabel]=\"group.text|i18n\">" );
185185
result.Append( "<nz-option *ngFor=\"let item of group.value\" [nzDisabled]=\"item.disabled\" [nzLabel]=\"item.text|i18n\" [nzValue]=\"item.value\">" );
186186
result.Append( "</nz-option>" );
187187
result.Append( "</nz-option-group>" );

0 commit comments

Comments
 (0)