update 删除所有Xn前缀, 规范了所有分页参数和返回值
This commit is contained in:
@@ -5,7 +5,7 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 通用输入扩展参数(带权限)
|
||||
/// </summary>
|
||||
public class XnInputBase : PageInputBase
|
||||
public class InputBase : PageInputBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 授权菜单
|
||||
@@ -40,7 +40,7 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 当前页码
|
||||
/// </summary>
|
||||
public virtual int PageNo { get; set; } = 1;
|
||||
public virtual int PageIndex { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 页码容量
|
||||
38
Api/Ewide.Core/Extension/PageDataResult.cs
Normal file
38
Api/Ewide.Core/Extension/PageDataResult.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 小诺分页列表结果
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public static class PageDataResult<T> where T : new()
|
||||
{
|
||||
public static dynamic PageResult(PagedList<T> page)
|
||||
{
|
||||
return new
|
||||
{
|
||||
PageIndex = page.PageIndex,
|
||||
PageSize = page.PageSize,
|
||||
TotalPage = page.TotalPages,
|
||||
TotalCount = page.TotalCount,
|
||||
Items = page.Items
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class PageDataResult
|
||||
{
|
||||
public static dynamic PageResult(PagedList page)
|
||||
{
|
||||
return new
|
||||
{
|
||||
PageIndex = page.PageIndex,
|
||||
PageSize = page.PageSize,
|
||||
TotalPage = page.TotalPages,
|
||||
TotalCount = page.TotalCount,
|
||||
Items = page.Items
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,12 +43,12 @@ namespace Ewide.Core.Extension
|
||||
|
||||
public static Task<PagedList<T>> ToPageData<T>(this IQueryable<T> source, PageInputBase input) where T : new()
|
||||
{
|
||||
return source.OrderBy(OrderBuilder<T>(input)).ToPagedListAsync(input.PageNo, input.PageSize);
|
||||
return source.OrderBy(OrderBuilder<T>(input)).ToPagedListAsync(input.PageIndex, input.PageSize);
|
||||
}
|
||||
|
||||
public static Task<PagedList<O>> ToPageData<T, O>(this IQueryable<T> source, PageInputBase input) where O : new()
|
||||
{
|
||||
return source.OrderBy(OrderBuilder<T>(input)).Select(u => u.Adapt<O>()).ToPagedListAsync(input.PageNo, input.PageSize);
|
||||
return source.OrderBy(OrderBuilder<T>(input)).Select(u => u.Adapt<O>()).ToPagedListAsync(input.PageIndex, input.PageSize);
|
||||
}
|
||||
|
||||
#region DAPPER
|
||||
@@ -72,7 +72,7 @@ namespace Ewide.Core.Extension
|
||||
|
||||
var page = new PagedList
|
||||
{
|
||||
PageIndex = input.PageNo,
|
||||
PageIndex = input.PageIndex,
|
||||
PageSize = input.PageSize,
|
||||
Items = data,
|
||||
TotalCount = count,
|
||||
@@ -102,7 +102,7 @@ namespace Ewide.Core.Extension
|
||||
|
||||
var page = new PagedList<T>
|
||||
{
|
||||
PageIndex = input.PageNo,
|
||||
PageIndex = input.PageIndex,
|
||||
PageSize = input.PageSize,
|
||||
Items = data,
|
||||
TotalCount = count,
|
||||
@@ -131,7 +131,7 @@ namespace Ewide.Core.Extension
|
||||
var orderStr = OrderBuilder(input);
|
||||
if (!string.IsNullOrEmpty(orderStr)) sqlStrList.Add(" ORDER BY " + orderStr);
|
||||
// input.PageSize = 0表示不分页
|
||||
if (input.PageSize != 0) sqlStrList.Add(" LIMIT " + ((input.PageNo - 1) * input.PageSize).ToString() + "," + input.PageSize.ToString());
|
||||
if (input.PageSize != 0) sqlStrList.Add(" LIMIT " + ((input.PageIndex - 1) * input.PageSize).ToString() + "," + input.PageSize.ToString());
|
||||
sql += String.Join("", sqlStrList);
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 规范化RESTful风格返回值
|
||||
/// </summary>
|
||||
[SkipScan, UnifyModel(typeof(XnRestfulResult<>))]
|
||||
public class XnRestfulResultProvider : IUnifyResultProvider
|
||||
[SkipScan, UnifyModel(typeof(RestfulResult<>))]
|
||||
public class RestfulResultProvider : IUnifyResultProvider
|
||||
{
|
||||
private IActionResult DisplayJson(object data)
|
||||
{
|
||||
@@ -41,7 +41,7 @@ namespace Ewide.Core
|
||||
// 解析异常信息
|
||||
var (StatusCode, ErrorCode, Errors) = UnifyContext.GetExceptionMetadata(context);
|
||||
|
||||
return DisplayJson(new XnRestfulResult<object>
|
||||
return DisplayJson(new RestfulResult<object>
|
||||
{
|
||||
Code = StatusCode,
|
||||
Success = false,
|
||||
@@ -65,7 +65,7 @@ namespace Ewide.Core
|
||||
{
|
||||
// 处理 401 状态码
|
||||
case StatusCodes.Status401Unauthorized:
|
||||
await context.Response.WriteAsJsonAsync(new XnRestfulResult<object>
|
||||
await context.Response.WriteAsJsonAsync(new RestfulResult<object>
|
||||
{
|
||||
Code = StatusCodes.Status401Unauthorized,
|
||||
Success = false,
|
||||
@@ -77,7 +77,7 @@ namespace Ewide.Core
|
||||
break;
|
||||
// 处理 403 状态码
|
||||
case StatusCodes.Status403Forbidden:
|
||||
await context.Response.WriteAsJsonAsync(new XnRestfulResult<object>
|
||||
await context.Response.WriteAsJsonAsync(new RestfulResult<object>
|
||||
{
|
||||
Code = StatusCodes.Status403Forbidden,
|
||||
Success = false,
|
||||
@@ -108,7 +108,7 @@ namespace Ewide.Core
|
||||
else if (context.Result is EmptyResult) data = null;
|
||||
else return null;
|
||||
|
||||
return DisplayJson(new XnRestfulResult<object>
|
||||
return DisplayJson(new RestfulResult<object>
|
||||
{
|
||||
Code = context.Result is EmptyResult ? StatusCodes.Status204NoContent : StatusCodes.Status200OK, // 处理没有返回值情况 204
|
||||
Success = true,
|
||||
@@ -129,7 +129,7 @@ namespace Ewide.Core
|
||||
/// <returns></returns>
|
||||
public IActionResult OnValidateFailed(ActionExecutingContext context, ModelStateDictionary modelStates, IEnumerable<ValidateFailedModel> validationResults, string validateFailedMessage)
|
||||
{
|
||||
return DisplayJson(new XnRestfulResult<object>
|
||||
return DisplayJson(new RestfulResult<object>
|
||||
{
|
||||
Code = StatusCodes.Status400BadRequest,
|
||||
Success = false,
|
||||
@@ -146,7 +146,7 @@ namespace Ewide.Core
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
[SkipScan]
|
||||
public class XnRestfulResult<T>
|
||||
public class RestfulResult<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// 执行成功
|
||||
@@ -1,24 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 小诺分页列表结果
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public static class XnPageResult<T> where T : new()
|
||||
{
|
||||
public static dynamic PageResult(PagedList<T> page)
|
||||
{
|
||||
return new
|
||||
{
|
||||
PageNo = page.PageIndex,
|
||||
PageSize = page.PageSize,
|
||||
TotalPage = page.TotalPages,
|
||||
TotalRows = page.TotalCount,
|
||||
Rows = page.Items //.Adapt<List<T>>(),
|
||||
//Rainbow = PageUtil.Rainbow(page.PageIndex, page.TotalPages, PageUtil.RAINBOW_NUM)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user