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

BasePageInput.cs 1.5 KiB

4 months ago
3 months ago
4 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. 
  2. namespace SafeCampus.Core;
  3. /// <summary>
  4. /// 全局分页查询输入参数
  5. /// </summary>
  6. public class BasePageInput : IValidatableObject
  7. {
  8. /// <summary>
  9. /// 当前页码
  10. /// </summary>
  11. [DataValidation(ValidationTypes.Numeric)]
  12. public virtual int PageNum { get; set; } = 1;
  13. /// <summary>
  14. /// 每页条数
  15. /// </summary>
  16. [Range(1, 1000, ErrorMessage = "页码容量超过最大限制")]
  17. [DataValidation(ValidationTypes.Numeric)]
  18. public virtual int PageSize { get; set; } = 10;
  19. /// <summary>
  20. /// 排序字段
  21. /// </summary>
  22. public virtual string SortField { get; set; }
  23. /// <summary>
  24. /// 排序方式,升序:ascend;降序:descend"
  25. /// </summary>
  26. public virtual string SortOrder { get; set; } = "desc";
  27. /// <summary>
  28. /// 关键字
  29. /// </summary>
  30. public virtual string SearchKey { get; set; }
  31. public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
  32. {
  33. //配合小诺排序参数
  34. if (SortOrder == "descend")
  35. {
  36. SortOrder = "desc";
  37. }
  38. else if (SortOrder == "ascend")
  39. {
  40. SortOrder = "asc";
  41. }
  42. if (!string.IsNullOrEmpty(SortField))
  43. {
  44. //分割排序字段
  45. var fields = SortField.Split(" ");
  46. if (fields.Length > 1)
  47. {
  48. yield return new ValidationResult("排序字段错误", new[]
  49. {
  50. nameof(SortField)
  51. });
  52. }
  53. }
  54. }
  55. }