PagedApiResult.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Ant.Core.WebApi.Enum;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Ant.Core.WebApi.Model
  8. {
  9. public class PagedApiResult<T>: ApiResult<List<T>>
  10. {
  11. public PagedApiResult(ApiStatusCode code, string message = null) : base(code, message)
  12. {
  13. }
  14. /// <summary>
  15. /// 兼容使用skiplimit查询的方式,自动计算pageindex
  16. /// </summary>
  17. /// <param name="datas"></param>
  18. /// <param name="total"></param>
  19. /// <param name="skip"></param>
  20. /// <param name="limit"></param>
  21. public PagedApiResult(List<T> datas, int total, int skip, int limit) : base(datas)
  22. {
  23. this.Pager = new Pager
  24. {
  25. Total = total,
  26. PageSize = limit,
  27. PageIndex = limit == 0 ? 1 : (skip / limit) + 1
  28. };
  29. }
  30. /// <summary>
  31. /// 分页信息
  32. /// </summary>
  33. public Pager Pager { set; get; } = new Pager();
  34. }
  35. public class Pager
  36. {
  37. public int PageIndex { set; get; }
  38. public int PageSize { set; get; }
  39. public int Total { set; get; }
  40. }
  41. }