mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-18 17:48:01 +08:00
⚠️feat: 增加排序字段
This commit is contained in:
@@ -13,5 +13,6 @@
|
|||||||
/newdocs/docs/.vuepress/.cache
|
/newdocs/docs/.vuepress/.cache
|
||||||
/newdocs/docs/.vuepress/.temp
|
/newdocs/docs/.vuepress/.temp
|
||||||
/newdocs/docs/.vuepress/dist
|
/newdocs/docs/.vuepress/dist
|
||||||
|
/Vue2/node_modules
|
||||||
|
|
||||||
|
|
||||||
|
@@ -15,6 +15,12 @@
|
|||||||
|
|
||||||
public string key { get; set; }
|
public string key { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 排序字段
|
||||||
|
/// </summary>
|
||||||
|
/// <example>sort=id,asc</example>
|
||||||
|
public string sort { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 自定义sql条件
|
/// 自定义sql条件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@@ -39,7 +39,16 @@ namespace OpenAuth.App
|
|||||||
objs = objs.Where(request.sqlWhere);
|
objs = objs.Where(request.sqlWhere);
|
||||||
}
|
}
|
||||||
var propertyStr = string.Join(',', columns.Select(u => u.ColumnName));
|
var propertyStr = string.Join(',', columns.Select(u => u.ColumnName));
|
||||||
result.Data = objs.OrderBy(u => u.Id)
|
|
||||||
|
if (!string.IsNullOrEmpty(request.sort))
|
||||||
|
{
|
||||||
|
var sortfields = request.sort.Split(',');
|
||||||
|
|
||||||
|
objs = objs.OrderBy($"{sortfields[0]} {sortfields[1]}");
|
||||||
|
}else{
|
||||||
|
objs = objs.OrderBy(u => u.Id);
|
||||||
|
}
|
||||||
|
result.Data = objs
|
||||||
.Skip((request.page - 1) * request.limit)
|
.Skip((request.page - 1) * request.limit)
|
||||||
.Take(request.limit).Select($"{propertyStr}").ToList();
|
.Take(request.limit).Select($"{propertyStr}").ToList();
|
||||||
result.Count = await objs.CountAsync();
|
result.Count = await objs.CountAsync();
|
||||||
|
Reference in New Issue
Block a user