diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 491274ccf04..18c20cc24fa 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@  - 10.1.5-beta05 + 10.2.0 diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs b/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs index f17a817dc23..6e11bfc295f 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs @@ -1086,9 +1086,9 @@ async Task DeleteItemsAsync() // 由于数据删除导致页码会改变,尤其是最后一页 // 重新计算页码 // https://gitee.com/LongbowEnterprise/BootstrapBlazor/issues/I1UJSL - PageIndex = Math.Max(1, Math.Min(PageIndex, int.Parse(Math.Ceiling((TotalCount - SelectedRows.Count) * 1d / _pageItems).ToString()))); - var items = PageItemsSource.Where(item => item >= (TotalCount - SelectedRows.Count)); - if (items.Any()) + PageIndex = GetSafePageIndex(); + var items = PageItemsSource.Where(item => item >= (TotalCount - SelectedRows.Count)).ToList(); + if (items.Count > 0) { _pageItems = Math.Min(_pageItems, items.Min()); } @@ -1150,16 +1150,18 @@ private void QueryDynamicItems(QueryPageOptions queryOption, IDynamicObjectConte { TotalCount = items.Count(); PageCount = (int)Math.Ceiling(TotalCount * 1.0 / Math.Max(1, _pageItems)); - PageIndex = Math.Max(1, Math.Min(PageIndex, int.Parse(Math.Ceiling((TotalCount - SelectedRows.Count) * 1d / _pageItems).ToString()))); + PageIndex = GetSafePageIndex(); items = items.Skip((PageIndex - 1) * _pageItems).Take(_pageItems); } - QueryItems = items.Cast(); + QueryItems = items.Cast().ToList(); // 重置选中行 ResetSelectedRows(QueryItems); } } + private int GetSafePageIndex() => Math.Max(1, Math.Min(PageIndex, (int)Math.Ceiling((TotalCount - SelectedRows.Count) * 1.0 / _pageItems))); + private async Task ExecuteExportAsync(Func> callback) { if (BeforeExportCallback != null) diff --git a/src/BootstrapBlazor/Components/Validate/ValidateBase.cs b/src/BootstrapBlazor/Components/Validate/ValidateBase.cs index b3d5dc7f8a6..b07d93e77a4 100644 --- a/src/BootstrapBlazor/Components/Validate/ValidateBase.cs +++ b/src/BootstrapBlazor/Components/Validate/ValidateBase.cs @@ -251,7 +251,7 @@ protected virtual bool IsRequired() => ShowRequired ?? FieldIdentifier .Build(); /// - /// SetParametersAsync 方法 + /// /// /// /// @@ -274,7 +274,7 @@ public override Task SetParametersAsync(ParameterView parameters) } /// - /// OnInitialized 方法 + /// /// protected override void OnInitialized() { @@ -291,7 +291,7 @@ protected override void OnInitialized() } /// - /// OnParametersSet 方法 + /// /// protected override void OnParametersSet() { @@ -326,6 +326,26 @@ protected override void OnParametersSet() } } + /// + /// + /// + /// + protected override bool ShouldRender() + { + if (ValidateForm == null) + { + return true; + } + + if (_shouldRender is true) + { + _shouldRender = false; + return true; + } + + return _shouldRender ?? true; + } + /// /// /// @@ -346,6 +366,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender) await ShowValidResult(); } } + + if (_shouldRender == false) + { + _shouldRender = null; + } } private string? _defaultRequiredErrorMessage; @@ -456,6 +481,8 @@ private void ValidateType(ValidationContext context, List resu } } + private bool? _shouldRender = null; + /// /// 显示/隐藏验证结果方法 /// @@ -480,6 +507,7 @@ public virtual Task ToggleMessage(IReadOnlyCollection results) } // 必须刷新一次 UI 保证状态正确 + _shouldRender = true; StateHasChanged(); return Task.CompletedTask; } diff --git a/test/UnitTest/Components/ValidateFormTest.cs b/test/UnitTest/Components/ValidateFormTest.cs index f76aaafa966..8e62eac4d50 100644 --- a/test/UnitTest/Components/ValidateFormTest.cs +++ b/test/UnitTest/Components/ValidateFormTest.cs @@ -542,9 +542,9 @@ public async Task ValidateFromCode_Ok() }); Assert.Contains("form-control valid", cut.Markup); - var form = cut.Instance; - await cut.InvokeAsync(() => form.Validate()); - Assert.Contains("form-control valid is-invalid", cut.Markup); + var form = cut.Find("form"); + await cut.InvokeAsync(() => form.Submit()); + Assert.Contains("form-control invalid is-invalid", cut.Markup); } [Fact] @@ -566,7 +566,7 @@ public async Task Validate_Service_Ok() var msg = cut.FindComponent>().Instance.GetErrorMessage(); Assert.Equal(HasServiceAttribute.Success, msg); } - + [Fact] public async Task TestService_Ok() { @@ -771,7 +771,7 @@ private class HasService { [HasService] public string? Tag { get; set; } - + [TestValidateRule] public string? Tag2 { get; set; } }