You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.7 KiB
C#

using Mapster;
using MapsterMapper;
using System.Collections.Generic;
namespace EntrustSettle.Model
{
/// <summary>
/// 通用分页信息类
/// </summary>
public class PageModel<T>
{
/// <summary>
9 months ago
/// 返回数据
/// </summary>
9 months ago
public List<T> data { get; set; }
/// <summary>
9 months ago
/// 数据总数
/// </summary>
9 months ago
public int dataCount { get; set; }
/// <summary>
9 months ago
/// 当前页标
/// </summary>
9 months ago
public int pageIndex { get; set; } = 1;
/// <summary>
9 months ago
/// 总页数
/// </summary>
9 months ago
public int pageCount => (int)System.Math.Ceiling((decimal)dataCount / pageSize);
/// <summary>
9 months ago
/// 每页大小
/// </summary>
9 months ago
public int pageSize { set; get; }
public PageModel() { }
public PageModel(int page, int dataCount, int pageSize, List<T> data)
{
9 months ago
this.pageIndex = page;
this.dataCount = dataCount;
9 months ago
this.pageSize = pageSize;
this.data = data;
}
public PageModel<TOut> ConvertTo<TOut>(bool isAdapt)
{
9 months ago
var model = new PageModel<TOut>(pageIndex, dataCount, pageSize, default);
if (isAdapt)
{
model.data = data.Adapt<List<TOut>>();
}
return model;
}
public PageModel<TOut> ConvertTo<TOut>(TypeAdapterConfig adapterConfig)
{
9 months ago
var model = new PageModel<TOut>(pageIndex, dataCount, pageSize, default);
var mapper = new Mapper(adapterConfig);
model.data = mapper.Map<List<TOut>>(data);
return model;
}
}
}