⚠️feat: 增加排序字段

This commit is contained in:
yubaolee
2025-06-14 11:07:26 +08:00
parent ab027241bf
commit b275847f3b
3 changed files with 17 additions and 1 deletions

View File

@@ -13,5 +13,6 @@
/newdocs/docs/.vuepress/.cache
/newdocs/docs/.vuepress/.temp
/newdocs/docs/.vuepress/dist
/Vue2/node_modules

View File

@@ -15,6 +15,12 @@
public string key { get; set; }
/// <summary>
/// 排序字段
/// </summary>
/// <example>sort=id,asc</example>
public string sort { get; set; }
/// <summary>
/// 自定义sql条件
/// </summary>

View File

@@ -39,7 +39,16 @@ namespace OpenAuth.App
objs = objs.Where(request.sqlWhere);
}
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)
.Take(request.limit).Select($"{propertyStr}").ToList();
result.Count = await objs.CountAsync();