Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
fix(TPagination): 修复总页数小于2页时的分页条显示错误 (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
teacher-zhou authored Jun 5, 2023
2 parents 6ab3b17 + 0758d13 commit 15c2116
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 42 deletions.
12 changes: 10 additions & 2 deletions doc/TDesign.Docs.Shared/Pages/TestPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
@using Test = TDesign.Docs.Shared.Pages.Components.Data.TablePage
@layout EmptyLayout

<TPagination @bind-PageIndex="Page" @bind-PageSize=Size @bind-Total=Total/>

@code{
int Page { get; set; } = 1;
int Size { get; set; } = 3;
int Total { get; set; } = 12;
}

@*<TPopup Content="弹出一个层">
<TButton>悬浮</TButton>
</TPopup>*@
Expand Down Expand Up @@ -40,7 +48,7 @@
@code{
TDialog? _dialog;
}*@

@*
@inject IDialogService DialogService
<TButton OnClick="Open">
Expand All @@ -54,4 +62,4 @@
var dialog = await DialogService.OpenInfo("第一个提示");
}
}
@inject IJSRuntime JS
@inject IJSRuntime JS*@
89 changes: 49 additions & 40 deletions src/TDesign/Components/TPagination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ void BuildTotal(RenderTreeBuilder builder)
=> builder.Div("t-pagination__total", ShowTotal).Content(TotalContent?.Invoke(Total)).Close();

/// <summary>
/// 构建每页数据量的下拉菜单。//TODO,等待 Select 组件完成
/// 构建每页数据量的下拉菜单。
/// TODO,等待 Select 组件完成
/// </summary>
/// <param name="builder"></param>
void BuildPageSizeSelect(RenderTreeBuilder builder)
Expand Down Expand Up @@ -272,61 +273,69 @@ void BuildPageNumbers(RenderTreeBuilder builder)
=> builder.Element("ul","t-pagination__pager", ShowPageNumber)
.Content(content =>
{
if (EllipsisMode == PageEllipsisMode.Middle)
//总页数不足2页,就显示1页的分页条
if ( TotalPages < 2 )
{
#region 第一页
BuildPageNumerItem(content, 100, 1);
}
else
{
if ( EllipsisMode == PageEllipsisMode.Middle )
{
#region 第一页

//第一页永远显示
BuildPageNumerItem(content, 0, 1);
//第一页永远显示
BuildPageNumerItem(content, 0, 1);

#endregion
#endregion

#region 前5页
if (PageIndex > PageNumber / 2)
{
var backTo = PageNumber - 5;
if (backTo <= 1)
#region 前5页
if ( PageIndex > PageNumber / 2 )
{
backTo = 1;
var backTo = PageNumber - 5;
if ( backTo <= 1 )
{
backTo = 1;
}
BuildPageItem(content, 1, text => text.CreateComponent<TIcon>(0, attributes: new { Name = IconName.Ellipsis }), () => NavigateToPage(backTo));
}
BuildPageItem(content, 1, text => text.CreateComponent<TIcon>(0, attributes: new { Name = IconName.Ellipsis }), () => NavigateToPage(backTo));
#endregion
}
#endregion
}

#region 页码条
#region 页码条

var (start, end) = ComputePageNumber();
var (start, end) = ComputePageNumber();

//页码1 永远显示,所有从2开始
//最后一页永远显示,所以结束要少一个索引
var offset = (EllipsisMode == PageEllipsisMode.Middle ? 1 : 0);
for (var i = start + offset; i <= end - offset; i++)
{
var current = i;
var contentSequence = (int)i + 30;
//页码1 永远显示,所有从2开始
//最后一页永远显示,所以结束要少一个索引
var offset = (EllipsisMode == PageEllipsisMode.Middle ? 1 : 0);
for ( var i = start + offset; i <= end - offset; i++ )
{
var current = i;
var contentSequence = (int)i + 30;

BuildPageNumerItem(content, contentSequence, current);
}
#endregion
BuildPageNumerItem(content, contentSequence, current);
}
#endregion

if (EllipsisMode == PageEllipsisMode.Middle)
{
#region 后5页
if (PageIndex < TotalPages - PageNumber / 2)
if ( EllipsisMode == PageEllipsisMode.Middle )
{
var nextTo = PageIndex + 5;
if (nextTo >= TotalPages)
#region 后5页
if ( PageIndex < TotalPages - PageNumber / 2 )
{
nextTo = TotalPages;
var nextTo = PageIndex + 5;
if ( nextTo >= TotalPages )
{
nextTo = TotalPages;
}
BuildPageItem(content, 90, text => text.CreateComponent<TIcon>(0, attributes: new { Name = IconName.Ellipsis }), () => NavigateToPage(nextTo));
}
BuildPageItem(content, 90, text => text.CreateComponent<TIcon>(0, attributes: new { Name = IconName.Ellipsis }), () => NavigateToPage(nextTo));
}
#endregion
#endregion

#region 末页
BuildPageNumerItem(content, 100, TotalPages);
#endregion
#region 末页
BuildPageNumerItem(content, 100, TotalPages);
#endregion
}
}
})
.Close();
Expand Down

0 comments on commit 15c2116

Please sign in to comment.