Files
zcglxt/verify_phase7.py
Claude e71181f0a3 fix: 修复多个关键问题
- 修复前端路由守卫:未登录时不显示提示,直接跳转登录页
- 修复API拦截器:401错误不显示提示,直接跳转
- 增强验证码显示:图片尺寸从120x40增加到200x80
- 增大验证码字体:从28号增加到48号
- 优化验证码字符:排除易混淆的0和1
- 减少干扰线:从5条减少到3条,添加背景色优化
- 增强登录API日志:添加详细的调试日志
- 增强验证码生成和验证日志
- 优化异常处理和错误追踪

影响文件:
- src/router/index.ts
- src/api/request.ts
- app/services/auth_service.py
- app/api/v1/auth.py
- app/schemas/user.py

测试状态:
- 前端构建通过
- 后端语法检查通过
- 验证码显示效果优化完成

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-25 00:26:21 +08:00

177 lines
5.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
Phase 7 代码质量验证脚本
"""
import os
import re
from pathlib import Path
def check_file_exists(filepath):
"""检查文件是否存在"""
if os.path.exists(filepath):
print(f"[OK] {filepath}")
return True
else:
print(f"[FAIL] {filepath} - 文件不存在")
return False
def check_file_syntax(filepath):
"""检查文件语法"""
try:
with open(filepath, 'r', encoding='utf-8') as f:
code = f.read()
compile(code, filepath, 'exec')
print(f"[OK] {filepath} - 语法检查通过")
return True
except Exception as e:
print(f"[FAIL] {filepath} - 语法错误: {e}")
return False
def check_docstring(filepath):
"""检查文件是否有docstring"""
try:
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# 检查模块docstring
has_module_docstring = '"""' in content[:500]
# 统计函数docstring
function_pattern = r'def\s+\w+\([^)]*\):[^)]*"""'
function_docstrings = len(re.findall(function_pattern, content))
# 统计类docstring
class_pattern = r'class\s+\w+.*?:[^)]*"""'
class_docstrings = len(re.findall(class_pattern, content))
print(f"[OK] {filepath} - 模块文档: {has_module_docstring}, 函数文档: {function_docstrings}, 类文档: {class_docstrings}")
return True
except Exception as e:
print(f"[WARN] {filepath} - 无法检查文档: {e}")
return False
def check_type_hints(filepath):
"""检查类型注解"""
try:
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# 统计函数定义
def_count = len(re.findall(r'def\s+\w+', content))
# 统计类型注解
param_hints = len(re.findall(r'def\s+\w+\([^)]*:\s*\w+', content))
return_hints = len(re.findall(r'->\s*\w+', content))
coverage = (param_hints + return_hints) / (2 * def_count) * 100 if def_count > 0 else 0
print(f"[OK] {filepath} - 类型注解覆盖率: {coverage:.1f}%")
return True
except Exception as e:
print(f"[WARN] {filepath} - 无法检查类型注解: {e}")
return False
def main():
"""主验证函数"""
print("=" * 60)
print("Phase 7 代码质量验证")
print("=" * 60)
base_path = Path("C:/Users/Administrator/asset_management_backend")
# 需要检查的文件列表
files_to_check = [
# 模型层
"app/models/system_config.py",
"app/models/operation_log.py",
"app/models/notification.py",
# Schema层
"app/schemas/system_config.py",
"app/schemas/operation_log.py",
"app/schemas/notification.py",
"app/schemas/statistics.py",
# CRUD层
"app/crud/system_config.py",
"app/crud/operation_log.py",
"app/crud/notification.py",
# 服务层
"app/services/system_config_service.py",
"app/services/operation_log_service.py",
"app/services/notification_service.py",
"app/services/statistics_service.py",
# API层
"app/api/v1/statistics.py",
"app/api/v1/system_config.py",
"app/api/v1/operation_logs.py",
"app/api/v1/notifications.py",
# 中间件
"app/middleware/operation_log.py",
# 工具
"app/utils/redis_client.py",
]
print("\n1. 检查文件是否存在")
print("-" * 60)
exist_results = []
for filepath in files_to_check:
full_path = base_path / filepath
exist_results.append(check_file_exists(str(full_path)))
print("\n2. 检查文件语法")
print("-" * 60)
syntax_results = []
for filepath in files_to_check:
full_path = base_path / filepath
if os.path.exists(str(full_path)):
syntax_results.append(check_file_syntax(str(full_path)))
print("\n3. 检查文档注释")
print("-" * 60)
doc_results = []
for filepath in files_to_check:
full_path = base_path / filepath
if os.path.exists(str(full_path)):
doc_results.append(check_docstring(str(full_path)))
print("\n4. 检查类型注解")
print("-" * 60)
type_results = []
for filepath in files_to_check:
full_path = base_path / filepath
if os.path.exists(str(full_path)):
type_results.append(check_type_hints(str(full_path)))
# 统计结果
print("\n" + "=" * 60)
print("验证结果汇总")
print("=" * 60)
total_files = len(files_to_check)
existing_files = sum(exist_results)
syntax_passed = sum(syntax_results)
print(f"总文件数: {total_files}")
print(f"文件存在: {existing_files}/{total_files} ({existing_files/total_files*100:.1f}%)")
print(f"语法检查: {syntax_passed}/{existing_files} ({syntax_passed/existing_files*100 if existing_files > 0 else 0:.1f}%)")
if existing_files == total_files and syntax_passed == existing_files:
print("\n[SUCCESS] 所有检查通过Phase 7 开发完成!")
return 0
else:
print("\n[FAIL] 部分检查未通过,请查看详情")
return 1
if __name__ == "__main__":
exit(main())