2020-09-17 10:09:20 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-05-03 21:46:21 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2020-09-17 10:09:20 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
2020-05-03 21:46:21 +08:00
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-05-03 21:46:21 +08:00
|
|
|
|
{
|
2020-05-21 14:49:07 +08:00
|
|
|
|
public class ListGridType
|
2020-05-03 21:46:21 +08:00
|
|
|
|
{
|
2020-05-21 14:49:07 +08:00
|
|
|
|
public int Gutter { get; set; }
|
|
|
|
|
public int Column { get; set; }
|
|
|
|
|
public int Xs { get; set; }
|
|
|
|
|
public int Sm { get; set; }
|
|
|
|
|
public int Md { get; set; }
|
|
|
|
|
public int Lg { get; set; }
|
|
|
|
|
public int Xl { get; set; }
|
|
|
|
|
public int Xxl { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public partial class AntList<TItem> : AntDomComponentBase
|
|
|
|
|
{
|
|
|
|
|
public string PrefixName { get; set; } = "ant-list";
|
|
|
|
|
|
|
|
|
|
[Parameter] public IEnumerable<TItem> DataSource { get; set; }
|
2020-05-03 21:46:21 +08:00
|
|
|
|
|
2020-06-28 12:44:43 +08:00
|
|
|
|
[Parameter] public bool Bordered { get; set; } = false;
|
|
|
|
|
|
2020-05-03 21:46:21 +08:00
|
|
|
|
[Parameter] public RenderFragment Header { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter] public RenderFragment Footer { get; set; }
|
|
|
|
|
|
2020-05-21 14:49:07 +08:00
|
|
|
|
[Parameter] public RenderFragment LoadMore { get; set; }
|
2020-05-03 21:46:21 +08:00
|
|
|
|
|
2020-09-17 10:09:20 +08:00
|
|
|
|
[Parameter] public ListItemLayout ItemLayout { get; set; }
|
2020-05-03 21:46:21 +08:00
|
|
|
|
|
|
|
|
|
[Parameter] public bool Loading { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
[Parameter] public string NoResult { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter] public string Size { get; set; } = AntSizeLDSType.Default;
|
|
|
|
|
|
|
|
|
|
[Parameter] public bool Split { get; set; } = true;
|
|
|
|
|
|
2020-08-10 23:58:17 +08:00
|
|
|
|
[Parameter] public EventCallback<TItem> OnItemClick { get; set; }
|
|
|
|
|
|
2020-05-21 14:49:07 +08:00
|
|
|
|
[Parameter] public ListGridType Grid { get; set; }
|
|
|
|
|
|
2020-06-28 12:44:43 +08:00
|
|
|
|
[Parameter] public PaginationOptions Pagination { get; set; }
|
|
|
|
|
|
2020-09-17 10:09:20 +08:00
|
|
|
|
[Parameter] public RenderFragment<TItem> ChildContent { get; set; }
|
2020-08-10 23:58:17 +08:00
|
|
|
|
|
2020-05-21 14:49:07 +08:00
|
|
|
|
private bool IsSomethingAfterLastItem
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-06-28 12:44:43 +08:00
|
|
|
|
return LoadMore != null || Footer != null || Pagination != null;
|
2020-05-21 14:49:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 00:03:44 +08:00
|
|
|
|
protected override void OnInitialized()
|
2020-05-03 21:46:21 +08:00
|
|
|
|
{
|
|
|
|
|
SetClassMap();
|
|
|
|
|
|
2020-09-18 00:03:44 +08:00
|
|
|
|
base.OnInitialized();
|
2020-05-03 21:46:21 +08:00
|
|
|
|
}
|
|
|
|
|
protected void SetClassMap()
|
|
|
|
|
{
|
|
|
|
|
// large => lg
|
|
|
|
|
// small => sm
|
|
|
|
|
string sizeCls = string.Empty;
|
|
|
|
|
switch (Size)
|
|
|
|
|
{
|
|
|
|
|
case "large":
|
|
|
|
|
sizeCls = "lg";
|
|
|
|
|
break;
|
2020-05-10 15:42:02 +08:00
|
|
|
|
|
2020-05-03 21:46:21 +08:00
|
|
|
|
case "small":
|
|
|
|
|
sizeCls = "sm";
|
|
|
|
|
break;
|
2020-05-10 15:42:02 +08:00
|
|
|
|
|
2020-05-03 21:46:21 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClassMapper.Clear()
|
2020-05-21 14:49:07 +08:00
|
|
|
|
.Add(PrefixName)
|
|
|
|
|
.If($"{PrefixName}-split", () => Split)
|
2020-06-28 12:44:43 +08:00
|
|
|
|
.If($"{PrefixName}-bordered", () => Bordered)
|
2020-09-17 10:09:20 +08:00
|
|
|
|
.GetIf(() => $"{PrefixName}-{sizeCls}", () => !string.IsNullOrEmpty(sizeCls))
|
|
|
|
|
.If($"{PrefixName}-vertical", () => ItemLayout == ListItemLayout.Vertical)
|
2020-05-21 14:49:07 +08:00
|
|
|
|
.If($"{PrefixName}-loading", () => (Loading))
|
|
|
|
|
.If($"{PrefixName}-grid", () => Grid != null)
|
|
|
|
|
.If($"{PrefixName}-something-after-last-item", () => IsSomethingAfterLastItem);
|
2020-05-03 21:46:21 +08:00
|
|
|
|
}
|
2020-05-21 14:49:07 +08:00
|
|
|
|
|
2020-08-10 23:58:17 +08:00
|
|
|
|
private void HandleItemClick(TItem item)
|
|
|
|
|
{
|
|
|
|
|
if (OnItemClick.HasDelegate)
|
|
|
|
|
{
|
|
|
|
|
OnItemClick.InvokeAsync(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-03 21:46:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|