@@ -151,13 +151,7 @@ public partial class TreeView<TItem> : IModelEqualityComparer<TItem>
151151 /// </summary>
152152 /// <remarks>通过设置 <see cref="ShowSearch"/> 开启</remarks>
153153 [ Parameter ]
154- public Func < string ? , Task > ? OnSearchAsync { get ; set ; }
155-
156- /// <summary>
157- /// 获得/设置 页面刷新是否重置已加载数据 默认 false
158- /// </summary>
159- [ Parameter ]
160- public bool IsReset { get ; set ; }
154+ public Func < string ? , Task < List < TreeViewItem < TItem > > ? > > ? OnSearchAsync { get ; set ; }
161155
162156 /// <summary>
163157 /// 获得/设置 带层次数据集合
@@ -345,11 +339,6 @@ protected override void OnParametersSet()
345339 SearchIcon ??= IconTheme . GetIconByKey ( ComponentIcons . TreeViewSearchIcon ) ;
346340 ClearSearchIcon ??= IconTheme . GetIconByKey ( ComponentIcons . TreeViewResetSearchIcon ) ;
347341 LoadingIcon ??= IconTheme . GetIconByKey ( ComponentIcons . TreeViewLoadingIcon ) ;
348-
349- if ( IsReset )
350- {
351- _rows = null ;
352- }
353342 }
354343
355344 /// <summary>
@@ -358,35 +347,32 @@ protected override void OnParametersSet()
358347 /// <returns></returns>
359348 protected override async Task OnParametersSetAsync ( )
360349 {
361- if ( Items == null )
362- {
363- // 未提供数据显示 loading
364- return ;
365- }
366-
367- if ( Items . Count > 0 )
350+ if ( Items != null )
368351 {
369- await CheckExpand ( Items ) ;
370- }
352+ if ( Items . Count > 0 )
353+ {
354+ await CheckExpand ( Items ) ;
355+ }
371356
372- if ( ShowCheckbox && ( AutoCheckParent || AutoCheckChildren ) )
373- {
374- // 开启 Checkbox 功能时初始化选中节点
375- TreeNodeStateCache . IsChecked ( Items ) ;
376- }
357+ if ( ShowCheckbox && ( AutoCheckParent || AutoCheckChildren ) )
358+ {
359+ // 开启 Checkbox 功能时初始化选中节点
360+ TreeNodeStateCache . IsChecked ( Items ) ;
361+ }
377362
378- // 从数据源中恢复当前 active 节点
379- if ( _activeItem != null )
380- {
381- _activeItem = TreeNodeStateCache . Find ( Items , _activeItem . Value , out _ ) ;
382- }
363+ // 从数据源中恢复当前 active 节点
364+ if ( _activeItem != null )
365+ {
366+ _activeItem = TreeNodeStateCache . Find ( Items , _activeItem . Value , out _ ) ;
367+ }
383368
384- if ( _init == false )
385- {
386- // 设置 ActiveItem 默认值
387- _activeItem ??= Items . FirstOrDefaultActiveItem ( ) ;
388- _activeItem ? . SetParentExpand < TreeViewItem < TItem > , TItem > ( true ) ;
389- _init = true ;
369+ if ( _init == false )
370+ {
371+ // 设置 ActiveItem 默认值
372+ _activeItem ??= Items . FirstOrDefaultActiveItem ( ) ;
373+ _activeItem ? . SetParentExpand < TreeViewItem < TItem > , TItem > ( true ) ;
374+ _init = true ;
375+ }
390376 }
391377 }
392378
@@ -609,21 +595,25 @@ private async Task OnEnterAsync(string? searchText)
609595
610596 private Task OnEscAsync ( string ? searchText ) => OnClickResetSearch ( ) ;
611597
598+ private List < TreeViewItem < TItem > > ? _searchItems ;
599+
612600 private async Task OnClickSearch ( )
613601 {
614602 if ( OnSearchAsync != null )
615603 {
616- await OnSearchAsync ( _searchText ) ;
604+ _searchItems = await OnSearchAsync ( _searchText ) ;
605+ _rows = null ;
606+ StateHasChanged ( ) ;
617607 }
618608 }
619609
620- private async Task OnClickResetSearch ( )
610+ private Task OnClickResetSearch ( )
621611 {
622612 _searchText = null ;
623- if ( OnSearchAsync ! = null )
624- {
625- await OnSearchAsync ( _searchText ) ;
626- }
613+ _searchItems = null ;
614+ _rows = null ;
615+ StateHasChanged ( ) ;
616+ return Task . CompletedTask ;
627617 }
628618
629619 /// <summary>
@@ -862,11 +852,13 @@ private List<TreeViewItem<TItem>> Rows
862852 get
863853 {
864854 // 扁平化数据集合
865- _rows ??= Items . ToFlat < TItem > ( ) . ToList ( ) ;
855+ _rows ??= GetItems ( ) . ToFlat < TItem > ( ) ;
866856 return _rows ;
867857 }
868858 }
869859
860+ private List < TreeViewItem < TItem > > GetItems ( ) => _searchItems ?? Items ;
861+
870862 private static string ? GetTreeRowStyle ( TreeViewItem < TItem > item )
871863 {
872864 var level = 0 ;
0 commit comments