mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-11-29 18:49:08 +08:00
refactor(Select): revert CurrentValueAsString assign (#2039)
* refactor: use Find instead of FirstOrDefault * revert: 撤销代码更改 * refactor: 属性更改为方法 * refactor: 拆解三元运算符提高可读性 * refactor: 拆分三元表达式提高可读性 * chore: 增加语法检查字典配置 * chore: bump version 7.10.2 * chore: 更新 actions 依赖项 * chore: 使用大版本号
This commit is contained in:
parent
0536431f72
commit
5ff15521c5
@ -10,6 +10,7 @@ indent_style = space
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
spelling_exclusion_path = .\exclusion.dic
|
||||
|
||||
# Code files
|
||||
[*.{cs,csx,vb,vbx}]
|
||||
|
@ -14,8 +14,8 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup .NET 7.0
|
||||
uses: actions/setup-dotnet@v1
|
||||
- name: Setup .NET SDK
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 7.0.x
|
||||
|
||||
@ -24,6 +24,6 @@ jobs:
|
||||
dotnet test test/UnitTest -c Release --collect:"XPlat Code Coverage"
|
||||
|
||||
- name: Upload to Codecov
|
||||
uses: codecov/codecov-action@v3.1.1
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
|
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@ -13,8 +13,8 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup .NET Core 7
|
||||
uses: actions/setup-dotnet@v1
|
||||
- name: Setup .NET Core SDK
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 7.0.x
|
||||
|
||||
|
4
.github/workflows/pack.yml
vendored
4
.github/workflows/pack.yml
vendored
@ -13,8 +13,8 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup .NET Core 7
|
||||
uses: actions/setup-dotnet@v1
|
||||
- name: Setup .NET Core SDK
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 7.0.x
|
||||
|
||||
|
6
.github/workflows/publish.yml
vendored
6
.github/workflows/publish.yml
vendored
@ -12,8 +12,8 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup .NET Core 7
|
||||
uses: actions/setup-dotnet@v1
|
||||
- name: Setup .NET Core SDK
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 7.0.x
|
||||
|
||||
@ -22,7 +22,7 @@ jobs:
|
||||
dotnet publish -c Release -o deploy src/Wasm/BootstrapBlazor.WebAssembly.ClientHost
|
||||
|
||||
- name: Deploy to GitHub Pages
|
||||
uses: JamesIves/github-pages-deploy-action@3.7.1
|
||||
uses: JamesIves/github-pages-deploy-action@3
|
||||
with:
|
||||
GITHUB_TOKEN: ${{ secrets.GH_PUSH_TOKEN }}
|
||||
BRANCH: gh-pages
|
||||
|
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
@ -12,8 +12,8 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup .NET Core 7
|
||||
uses: actions/setup-dotnet@v1
|
||||
- name: Setup .NET Core SDK
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 7.0.x
|
||||
|
||||
|
7
exclusion.dic
Normal file
7
exclusion.dic
Normal file
@ -0,0 +1,7 @@
|
||||
argo
|
||||
Blazor
|
||||
swal
|
||||
Overscan
|
||||
|
||||
readonly
|
||||
oninput
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>7.10.1</Version>
|
||||
<Version>7.10.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
|
||||
|
@ -46,7 +46,7 @@
|
||||
<div class="dropdown-virtual">
|
||||
@if (OnQueryAsync == null)
|
||||
{
|
||||
<Virtualize ItemSize="RowHeight" OverscanCount="OverscanCount" Items="@VirtualCollection" ChildContent="RenderRow" />
|
||||
<Virtualize ItemSize="RowHeight" OverscanCount="OverscanCount" Items="@GetVirtualItems()" ChildContent="RenderRow" />
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -207,7 +207,7 @@ public partial class Select<TValue> : ISelect
|
||||
|
||||
private IEnumerable<SelectedItem>? VirtualItems { get; set; }
|
||||
|
||||
private ICollection<SelectedItem> VirtualCollection => (VirtualItems ?? Items).ToList();
|
||||
private ICollection<SelectedItem> GetVirtualItems() => (VirtualItems ?? Items).ToList();
|
||||
|
||||
/// <summary>
|
||||
/// 虚拟滚动数据加载回调方法
|
||||
@ -220,16 +220,14 @@ public partial class Select<TValue> : ISelect
|
||||
{
|
||||
// 有搜索条件时使用原生请求数量
|
||||
// 有总数时请求剩余数量
|
||||
var count = !string.IsNullOrEmpty(SearchText)
|
||||
? request.Count
|
||||
: TotalCount == 0
|
||||
? request.Count
|
||||
: Math.Min(request.Count, TotalCount - request.StartIndex);
|
||||
var count = !string.IsNullOrEmpty(SearchText) ? request.Count : GetCountByTotal();
|
||||
var data = await OnQueryAsync(new() { StartIndex = request.StartIndex, Count = count, SearchText = SearchText });
|
||||
|
||||
TotalCount = data.TotalCount;
|
||||
VirtualItems = data.Items ?? Enumerable.Empty<SelectedItem>();
|
||||
return new ItemsProviderResult<SelectedItem>(VirtualItems, TotalCount);
|
||||
|
||||
int GetCountByTotal() => TotalCount == 0 ? request.Count : Math.Min(request.Count, TotalCount - request.StartIndex);
|
||||
}
|
||||
|
||||
private async Task SearchTextChanged(string val)
|
||||
@ -269,7 +267,14 @@ public partial class Select<TValue> : ISelect
|
||||
return SelectedItem != null;
|
||||
}
|
||||
|
||||
private SelectedItem? GetVirtualizeItem() => OnQueryAsync == null ? null : ValueType == typeof(SelectedItem) ? (SelectedItem)(object)Value : new SelectedItem(CurrentValueAsString, DefaultVirtualizeItemText ?? CurrentValueAsString);
|
||||
private SelectedItem? GetVirtualizeItem()
|
||||
{
|
||||
return OnQueryAsync == null ? null : GetSelectedItem();
|
||||
|
||||
SelectedItem? GetSelectedItem() => ValueType == typeof(SelectedItem)
|
||||
? (SelectedItem)(object)Value
|
||||
: new SelectedItem(CurrentValueAsString, DefaultVirtualizeItemText ?? CurrentValueAsString);
|
||||
}
|
||||
|
||||
private void ResetSelectedItem()
|
||||
{
|
||||
@ -285,8 +290,8 @@ public partial class Select<TValue> : ISelect
|
||||
DataSource.AddRange(VirtualItems);
|
||||
}
|
||||
|
||||
SelectedItem = DataSource.FirstOrDefault(i => i.Value.Equals(CurrentValueAsString, StringComparison))
|
||||
?? DataSource.FirstOrDefault(i => i.Active)
|
||||
SelectedItem = DataSource.Find(i => i.Value.Equals(CurrentValueAsString, StringComparison))
|
||||
?? DataSource.Find(i => i.Active)
|
||||
?? DataSource.FirstOrDefault()
|
||||
?? GetVirtualizeItem();
|
||||
|
||||
@ -376,14 +381,14 @@ public partial class Select<TValue> : ISelect
|
||||
item.Active = true;
|
||||
SelectedItem = item;
|
||||
|
||||
// 触发 StateHasChanged
|
||||
CurrentValueAsString = item.Value;
|
||||
|
||||
// 触发 SelectedItemChanged 事件
|
||||
if (OnSelectedItemChanged != null)
|
||||
{
|
||||
await OnSelectedItemChanged(SelectedItem);
|
||||
}
|
||||
|
||||
// 触发 StateHasChanged
|
||||
CurrentValueAsString = item.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user