调整部分前端布局和后端增删改逻辑

This commit is contained in:
焦龙言
2026-09-28 18:29:10 +08:00
parent 17d991a74a
commit a539b4eb71
57 changed files with 87382 additions and 895 deletions
@@ -117,6 +117,7 @@ class Log:
log_type: Literal['login', 'operation'] | None = 'operation',
request_log_mode: Literal['full', 'none', 'summary', 'include', 'exclude'] = 'full',
response_log_mode: Literal['full', 'none', 'summary', 'include', 'exclude'] = 'full',
oper_url_mode: Literal['full', 'route'] = 'full',
request_include_fields: tuple[str, ...] | None = None,
response_include_fields: tuple[str, ...] | None = None,
request_exclude_fields: tuple[str, ...] | None = None,
@@ -130,6 +131,7 @@ class Log:
:param log_type: 日志类型;`login`表示登录日志,仅落登录信息,`operation`表示操作日志,会落请求/响应摘要与操作人信息
:param request_log_mode: 请求日志记录模式;`full`记录脱敏后的完整请求,`none`不记录请求体,`summary`记录请求摘要,`include`仅记录request_include_fields指定的字段,`exclude`记录完整请求后排除request_exclude_fields指定的字段
:param response_log_mode: 响应日志记录模式;`full`记录脱敏后的完整响应,`none`不记录响应体,`summary`记录响应摘要,`include`仅记录response_include_fields指定的字段,`exclude`记录完整响应后排除response_exclude_fields指定的字段
:param oper_url_mode: 操作URL记录模式;`full`记录实际请求路径,`route`记录路由模板,适合路径中包含敏感标识的接口
:param request_include_fields: 请求日志白名单字段路径,仅在request_log_mode='include'时生效;推荐从path_params/query_params/json_body/form_data/files/raw_body开始,字段名支持 snake_case 与 camelCase 自动兼容
:param response_include_fields: 响应日志白名单字段路径,仅在response_log_mode='include'时生效;推荐从code/msg/data/rows/success/time开始,字段名支持 snake_case 与 camelCase 自动兼容
:param request_exclude_fields: 请求日志排除字段路径,仅在request_log_mode='exclude'时生效;推荐从path_params/query_params/json_body/form_data/files/raw_body开始,字段名支持 snake_case 与 camelCase 自动兼容
@@ -141,6 +143,7 @@ class Log:
self.log_type = log_type
self.request_log_mode = request_log_mode
self.response_log_mode = response_log_mode
self.oper_url_mode = oper_url_mode
self.request_include_fields = request_include_fields or ()
self.response_include_fields = response_include_fields or ()
self.request_exclude_fields = request_exclude_fields or ()
@@ -166,7 +169,7 @@ class Log:
# 获取操作类型
operator_type = self._get_oper_type(user_agent)
# 获取请求的url
oper_url = request.url.path
oper_url = self._get_oper_url(request)
# 获取请求ip
oper_ip = ClientIPUtil.get_client_ip(request)
# 获取请求ip归属区域
@@ -281,6 +284,21 @@ class Log:
return func_path
def _get_oper_url(self, request: Request) -> str:
"""
获取操作日志中的请求URL。
路由模板模式只保留路由结构,不把路径参数(例如二维码固定标识)写入日志。
:param request: 当前请求
:return: 用于操作日志的URL
"""
if self.oper_url_mode == 'route':
route_path = getattr(request.scope.get('route'), 'path', None)
if route_path:
return route_path
return request.url.path
@staticmethod
def _limit_log_text(log_text: str, max_length: int, overflow_text: str) -> str:
"""