Skip to content

Commit 69e782d

Browse files
committed
增加触底加载LoadMore
1 parent 235f38a commit 69e782d

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,3 +384,5 @@ src/**/wwwroot/**/uploader
384384

385385
# Bootstrap
386386
**/BootstrapBlazor/wwwroot/js/bootstrap.blazor.bundle.min.js
387+
/src/BootstrapBlazor/compilerconfig.json
388+
/src/BootstrapBlazor/compilerconfig.json.defaults

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
</ItemGroup>
1111

1212
<ItemGroup>
13+
<Content Remove="compilerconfig.json" />
1314
<Content Remove="sasscompiler.json" />
1415
<Content Remove="wwwroot\core\**\*.*" />
1516
<Content Remove="wwwroot\lib\**\*.css" />
1617
<Content Remove="wwwroot\scss\**\*.*" />
1718
<Content Remove="wwwroot\src\**\*.*" />
19+
<None Include="compilerconfig.json" />
1820
<None Include="sasscompiler.json" />
1921
<None Include="wwwroot\core\**\*.*" />
2022
<None Include="wwwroot\lib\**\*.css" />
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<IntersectionObserver OnIntersecting="OnIntersecting" Threshold="1" AutoUnobserveWhenIntersection="false" UseElementViewport="true">
2+
<IntersectionObserverItem>
3+
@if(NumOfCurrentPage < PageSize)
4+
{
5+
<div class="nomore">@NoMoreText</div>
6+
}
7+
else
8+
{
9+
<div class="loading">
10+
<Spinner></Spinner>
11+
</div>
12+
}
13+
</IntersectionObserverItem>
14+
</IntersectionObserver>
15+
16+
@code {
17+
/// <summary>
18+
/// 触底时加载的调用
19+
/// </summary>
20+
[Parameter] public Func<Task>? OnLoadMore { get; set; }
21+
/// <summary>
22+
/// 当前页加载的记录数
23+
/// </summary>
24+
[Parameter] public int NumOfCurrentPage{ get; set; }
25+
/// <summary>
26+
/// 分页大小
27+
/// </summary>
28+
[Parameter] public int PageSize { get; set; }
29+
/// <summary>
30+
/// 没有更多时显示的文字
31+
/// </summary>
32+
[Parameter] public string NoMoreText { get; set; } = "没有更多了";
33+
/// <summary>
34+
/// 触底时加载的调用
35+
/// </summary>
36+
async Task OnIntersecting( IntersectionObserverEntry entry )
37+
{
38+
if(entry.IsIntersecting)
39+
{
40+
if(OnLoadMore != null) await OnLoadMore.Invoke();
41+
}
42+
}
43+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.nomore {
2+
display: flex;
3+
justify-content: center;
4+
padding: 0.5rem 0.5rem 1rem;
5+
color: #aaa;
6+
font-size: 0.875rem;
7+
}
8+
9+
.loading {
10+
display: flex;
11+
justify-content: center;
12+
padding: 0.5rem 0.5rem 1rem;
13+
color: #aaa;
14+
}

src/BootstrapBlazor/Components/LoadMore/LoadMore.razor.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.nomore {
2+
display: flex;
3+
justify-content: center;
4+
padding: .5rem .5rem 1rem;
5+
color: #aaa;
6+
font-size: .875rem;
7+
}
8+
9+
.loading {
10+
display: flex;
11+
justify-content: center;
12+
padding: .5rem .5rem 1rem;
13+
color: #aaa;
14+
}

0 commit comments

Comments
 (0)