feat(module: pagination): support static ssr paging
This commit is contained in:
Родитель
8692221e7b
Коммит
55dd1092be
|
@ -2,7 +2,10 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using AntDesign.Internal;
|
||||
using AntDesign.Locales;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
@ -146,6 +149,8 @@ namespace AntDesign
|
|||
[Parameter(CaptureUnmatchedValues = true)]
|
||||
public Dictionary<string, object>? UnmatchedAttributes { get; set; }
|
||||
|
||||
[Inject]private NavigationManager NavigationManager { get; set; }
|
||||
|
||||
private const string PrefixCls = "ant-pagination";
|
||||
|
||||
private ClassMapper _prevClass = new();
|
||||
|
@ -182,6 +187,7 @@ namespace AntDesign
|
|||
}
|
||||
|
||||
var current = DefaultCurrent;
|
||||
|
||||
if (_current != 0)
|
||||
{
|
||||
current = _current;
|
||||
|
@ -193,7 +199,16 @@ namespace AntDesign
|
|||
pageSize = PageSize;
|
||||
}
|
||||
|
||||
var query = HttpUtility.ParseQueryString(new Uri(NavigationManager.Uri).Query);
|
||||
if (int.TryParse(query["page"], out var p))
|
||||
{
|
||||
current = p;
|
||||
OnChange.InvokeAsync(new PaginationEventArgs(current, pageSize));
|
||||
}
|
||||
else
|
||||
{
|
||||
current = Math.Min(current, CalculatePage(pageSize, PageSize, Total));
|
||||
}
|
||||
|
||||
_current = current;
|
||||
_currentInputValue = current;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
tabIndex="0"
|
||||
@attributes="@UnmatchedAttributes"
|
||||
>
|
||||
@ItemRender(new PaginationItemRenderContext(Page, PaginationItemType.Page, _ => @<a rel="nofollow">@Page</a>, Disabled))
|
||||
@ItemRender(new PaginationItemRenderContext(Page, PaginationItemType.Page, _ => @<a rel="nofollow" href="@url">@Page</a>, Disabled))
|
||||
</li>
|
||||
|
||||
@code {
|
||||
|
@ -41,6 +41,10 @@
|
|||
[Parameter(CaptureUnmatchedValues = true)]
|
||||
public Dictionary<string, object> UnmatchedAttributes { get; set; }
|
||||
|
||||
[Inject] private NavigationManager NavigationManager { get; set; }
|
||||
|
||||
private string url;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
var prefixCls = $"{RootPrefixCls}-item";
|
||||
|
@ -49,6 +53,13 @@
|
|||
.If($"{prefixCls}-disabled", () => Page == 0);
|
||||
|
||||
base.OnInitialized();
|
||||
|
||||
var dic = new Dictionary<string, object>();
|
||||
dic.Add("page", Page);
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
url = NavigationManager.GetUriWithQueryParameters(dic);
|
||||
#endif
|
||||
}
|
||||
|
||||
private async Task HandleClick()
|
||||
|
|
Загрузка…
Ссылка в новой задаче