77
88namespace BootstrapBlazor . Components ;
99
10- internal class LookupContent : ComponentBase
10+ internal class LookupContent : ComponentBase , ILookup
1111{
1212 /// <summary>
13- /// 获得/设置 <see cref="ILookupService"/> 服务实例
13+ /// <inheritdoc/>
1414 /// </summary>
1515 [ Parameter ]
1616 public IEnumerable < SelectedItem > ? Lookup { get ; set ; }
1717
1818 /// <summary>
19- /// 获得/设置 <see cref="ILookupService"/> 服务实例
19+ /// <inheritdoc/>
2020 /// </summary>
2121 [ Parameter ]
2222 public ILookupService ? LookupService { get ; set ; }
2323
2424 /// <summary>
25- /// 获得/设置 <see cref="ILookupService"/> 服务获取 Lookup 数据集合键值 常用于外键自动转换为名称操作,可以通过 <see cref="LookupServiceData"/> 传递自定义数据
25+ /// <inheritdoc/>
2626 /// </summary>
2727 [ Parameter ]
28- [ EditorRequired ]
2928 public string ? LookupServiceKey { get ; set ; }
3029
3130 /// <summary>
32- /// 获得/设置 <see cref="ILookupService"/> 服务获取 Lookup 数据集合键值自定义数据,通过 <see cref="LookupServiceKey"/> 指定键值
31+ /// <inheritdoc/>
3332 /// </summary>
3433 [ Parameter ]
3534 public object ? LookupServiceData { get ; set ; }
3635
3736 /// <summary>
38- /// 获得/设置 字典数据源字符串比较规则 默认 <see cref="StringComparison.OrdinalIgnoreCase" /> 大小写不敏感
37+ /// <inheritdoc/>
3938 /// </summary>
4039 [ Parameter ]
41- public StringComparison LookupStringComparison { get ; set ; }
40+ public StringComparison LookupStringComparison { get ; set ; } = StringComparison . OrdinalIgnoreCase ;
4241
4342 /// <summary>
4443 /// 获得/设置 显示值
@@ -52,7 +51,7 @@ internal class LookupContent : ComponentBase
5251
5352 private string ? _content ;
5453
55- private List < SelectedItem > ? _items ;
54+ private IEnumerable < SelectedItem > ? _items ;
5655
5756 /// <summary>
5857 /// <inheritdoc/>
@@ -62,8 +61,8 @@ protected override async Task OnParametersSetAsync()
6261 {
6362 await base . OnParametersSetAsync ( ) ;
6463
65- _items ??= await GetLookupItemsAsync ( ) ;
66- var item = _items . Find ( i => i . Value . Equals ( Value , LookupStringComparison ) ) ;
64+ _items ??= await this . GetItemsAsync ( InjectLookupService , LookupServiceKey , LookupServiceData ) ?? [ ] ;
65+ var item = _items . FirstOrDefault ( i => i . Value . Equals ( Value , LookupStringComparison ) ) ;
6766 _content = item ? . Text ?? Value ;
6867 }
6968
@@ -78,19 +77,4 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
7877 builder . AddContent ( 0 , _content ) ;
7978 }
8079 }
81-
82- private async Task < List < SelectedItem > > GetLookupItemsAsync ( )
83- {
84- IEnumerable < SelectedItem > ? items ;
85- if ( Lookup != null )
86- {
87- items = Lookup ;
88- }
89- else
90- {
91- var lookupService = LookupService ?? InjectLookupService ;
92- items = await lookupService . GetItemsAsync ( LookupServiceKey , LookupServiceData ) ;
93- }
94- return items ? . ToList ( ) ?? [ ] ;
95- }
9680}
0 commit comments