mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
refactor(validator): 优化日期验证器并修复序列化问题 refactor(controller): 移除未使用的导入和接口 refactor(service): 优化类型提示和错误处理 fix(model): 修复JobLogModel字段定义 style(param): 移除未使用的导入和优化时间处理逻辑 fix(service): 修复服务器监控信息返回格式 fix(auth): 增强登录验证和错误处理 fix(dict): 修复字典数据状态更新逻辑 refactor(job): 优化任务服务和日志查询逻辑
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from typing import Optional, List, Dict
|
|
from fastapi import Query
|
|
|
|
|
|
class PaginationQueryParam:
|
|
"""分页查询参数基类"""
|
|
|
|
def __init__(
|
|
self,
|
|
page_no: Optional[int] = Query(default=None, description="当前页码", ge=1),
|
|
page_size: Optional[int] = Query(default=None, description="每页数量", ge=1, le=100),
|
|
order_by: Optional[str] = Query(default=None, description="排序字段,格式:field1,asc;field2,desc"),
|
|
) -> None:
|
|
"""
|
|
初始化分页查询参数
|
|
|
|
:param page_no: 当前页码,默认None
|
|
:param page_size: 每页数量,默认None,最大100
|
|
:param order_by: 排序字段
|
|
"""
|
|
self.page_no = page_no
|
|
self.page_size = page_size
|
|
# 将字符串格式的order_by转换为服务层需要的List[Dict[str, str]]格式
|
|
if order_by:
|
|
try:
|
|
self.order_by = []
|
|
for item in order_by.split(';'):
|
|
if item.strip():
|
|
field, direction = item.split(',', 1)
|
|
self.order_by.append({field.strip(): direction.strip().lower()})
|
|
except ValueError:
|
|
# 如果解析失败,使用默认排序
|
|
self.order_by = [{'id': 'asc'}]
|
|
else:
|
|
self.order_by = [{'id': 'asc'}]
|
|
|