feat: general:list方法支持withCount参数,带上这个参数的时候分页查询时一并返回总数
This commit is contained in:
@@ -43,6 +43,7 @@ async def list(session: AsyncSessionDep, query_config, module_config, debug_data
|
||||
n_page = get_value(query_config, 'page', 0)
|
||||
n_size = get_value(query_config, 'size', 5)
|
||||
n_only_count = get_value(query_config, 'onlyCount', False)
|
||||
n_with_count = get_value(query_config, 'withCount', False)
|
||||
|
||||
offset = n_page * n_size
|
||||
# 多查一条数据,方便判断是否有下一页数据
|
||||
@@ -77,8 +78,17 @@ async def list(session: AsyncSessionDep, query_config, module_config, debug_data
|
||||
has_next = False if get_value(query_config, 'all', False) else len(result) == n_size + 1
|
||||
if has_next:
|
||||
result.pop()
|
||||
|
||||
count_result = await list(
|
||||
session,
|
||||
query_config={**query_config, "onlyCount": True},
|
||||
module_config=module_config,
|
||||
debug_data=debug_data,
|
||||
user=user
|
||||
) if n_with_count else {}
|
||||
return {
|
||||
"hasNext": has_next,
|
||||
**count_result,
|
||||
"list": result,
|
||||
}
|
||||
except Exception as err:
|
||||
|
||||
Reference in New Issue
Block a user