2021-03-11 23:26:49 +08:00
|
|
|
|
// Licensed to the .NET Foundation under one or more agreements.
|
|
|
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2020-05-19 17:54:16 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
2021-03-11 23:26:49 +08:00
|
|
|
|
using OneOf;
|
2020-05-19 17:54:16 +08:00
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-05-19 17:54:16 +08:00
|
|
|
|
{
|
2021-03-11 23:26:49 +08:00
|
|
|
|
public partial class PaginationOptions
|
2020-05-19 17:54:16 +08:00
|
|
|
|
{
|
2021-03-11 23:26:49 +08:00
|
|
|
|
internal static readonly int[] DefaultPageSizeOptions = {10, 20, 50, 100};
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool IsSmall { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Disabled { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string RootPrefixCls { get; set; }
|
2020-05-19 17:54:16 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<int> ChangeSize { get; set; }
|
2020-05-19 17:54:16 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public int Current { get; set; }
|
2020-05-19 17:54:16 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public int PageSize { get; set; }
|
2020-05-19 17:54:16 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public int[] PageSizeOptions { get; set; }
|
2020-05-19 17:54:16 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<int> QuickGo { get; set; }
|
2020-05-19 17:54:16 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public OneOf<bool, RenderFragment>? GoButton { get; set; }
|
2020-05-19 17:54:16 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
private string _goInputText = string.Empty;
|
2020-05-19 17:54:16 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
private PaginationLocale Locale = LocaleProvider.CurrentLocale.Pagination;
|
|
|
|
|
|
|
|
|
|
private int GetValidValue()
|
|
|
|
|
{
|
|
|
|
|
return string.IsNullOrWhiteSpace(_goInputText) ? 0 :
|
|
|
|
|
int.TryParse(_goInputText, out var value) ? value : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string BuildOptionText(int value) => $"{value} {Locale.ItemsPerPage}";
|
|
|
|
|
|
|
|
|
|
private async void ChangePaginationSize(int value)
|
|
|
|
|
{
|
|
|
|
|
if (ChangeSize.HasDelegate)
|
|
|
|
|
{
|
|
|
|
|
await ChangeSize.InvokeAsync(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-19 17:54:16 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
private void HandleChange(ChangeEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_goInputText = e.Value as string;
|
|
|
|
|
}
|
2020-05-19 17:54:16 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
private void HandleBlur(FocusEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (GoButton != null || string.IsNullOrEmpty(_goInputText))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-05-19 17:54:16 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
_goInputText = string.Empty;
|
2020-09-07 22:46:50 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
// relatedTarget not implemented
|
|
|
|
|
// if (e.RelatedTarget && (e.relatedTarget.className.indexOf($"{rootPrefixCls}-item-link") >= 0 || e.relatedTarget.className.indexOf($"{rootPrefixCls}-item") >= 0))
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
2020-05-19 17:54:16 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
if (QuickGo.HasDelegate)
|
|
|
|
|
{
|
|
|
|
|
QuickGo.InvokeAsync(this.GetValidValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-19 17:54:16 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
private void Go(EventArgs e)
|
2020-05-19 17:54:16 +08:00
|
|
|
|
{
|
2021-03-11 23:26:49 +08:00
|
|
|
|
if (string.IsNullOrWhiteSpace(_goInputText))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e is KeyboardEventArgs {Code: "Enter"} || e is MouseEventArgs {Type: "Click"})
|
2020-05-19 17:54:16 +08:00
|
|
|
|
{
|
2021-03-11 23:26:49 +08:00
|
|
|
|
if (QuickGo.HasDelegate)
|
|
|
|
|
{
|
|
|
|
|
QuickGo.InvokeAsync(this.GetValidValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_goInputText = string.Empty;
|
2020-05-19 17:54:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
private int[] GetPageSizeOptions()
|
2020-05-19 17:54:16 +08:00
|
|
|
|
{
|
2021-03-11 23:26:49 +08:00
|
|
|
|
PageSizeOptions ??= DefaultPageSizeOptions;
|
|
|
|
|
if (PageSizeOptions.Any(option => option == PageSize))
|
2020-05-19 17:54:16 +08:00
|
|
|
|
{
|
2021-03-11 23:26:49 +08:00
|
|
|
|
return PageSizeOptions;
|
2020-05-19 17:54:16 +08:00
|
|
|
|
}
|
2021-03-11 23:26:49 +08:00
|
|
|
|
|
|
|
|
|
return PageSizeOptions.Concat(new[] {PageSize}).OrderBy(e => e).ToArray();
|
2020-05-19 17:54:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|