mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 13:05:18 +00:00
这是一次综合性的重构更新,包含以下主要变更: 1. 升级Python版本到3.12,更新依赖配置 2. 替换旧的.j2模板为.jinja2格式,新增代码生成模板 3. 重构权限过滤策略,更新权限枚举与模型配置 4. 移除Prefect依赖,替换为自研拓扑并行执行引擎 5. 重构认证与上下文管理,拆分租户/请求上下文 6. 简化响应模型、CRUD与服务层代码 7. 清理废弃的支付网关模块,重构订单定时任务 8. 更新在线用户、监控等模块的接口与路由 9. 优化邮件模板与工具类,新增邮件模板文件 10. 修复数据库会话配置与类型提示
120 lines
3.5 KiB
Python
120 lines
3.5 KiB
Python
from datetime import datetime
|
|
|
|
from rich import get_console
|
|
from rich.console import Group
|
|
from rich.panel import Panel
|
|
from rich.text import Text
|
|
|
|
from app.config.setting import settings
|
|
|
|
console = get_console()
|
|
|
|
|
|
def console_start(
|
|
host: str,
|
|
port: int,
|
|
reload: bool,
|
|
*,
|
|
database_ready: bool | None = None,
|
|
redis_ready: bool | None = None,
|
|
scheduler_ready: bool | None = None,
|
|
limiter_ready: bool | None = None,
|
|
) -> None:
|
|
"""
|
|
在终端输出 Rich 面板:服务信息、组件就绪状态与文档链接。
|
|
|
|
参数:
|
|
- host (str): 监听主机。
|
|
- port (int): 监听端口。
|
|
- reload (bool): 是否开启热重载。
|
|
- database_ready (bool | None): 数据库是否就绪。
|
|
- redis_ready (bool | None): Redis 是否就绪。
|
|
- scheduler_ready (bool | None): 调度器是否就绪。
|
|
- limiter_ready (bool | None): 限流器是否就绪。
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
|
|
url = f"http://{host}:{port}"
|
|
base_url = f"{url}{settings.ROOT_PATH}"
|
|
docs_url = base_url + settings.DOCS_URL
|
|
redoc_url = base_url + settings.REDOC_URL
|
|
|
|
# 核心服务信息
|
|
service_info = Text()
|
|
service_info.append(f"服务名称 {settings.TITLE} • 优雅 • 简洁 • 高效", style="bold magenta")
|
|
service_info.append(f"\n当前版本 v{settings.VERSION}", style="bold green")
|
|
service_info.append(f"\n服务地址 {url}", style="bold blue")
|
|
service_info.append(
|
|
f"\n运行环境 {settings.ENVIRONMENT.value if hasattr(settings.ENVIRONMENT, 'value') else settings.ENVIRONMENT}",
|
|
style="bold red",
|
|
)
|
|
service_info.append(
|
|
f"\n重载配置: {'✅ 启动' if reload else '❌ 关闭'}",
|
|
style="bold italic",
|
|
)
|
|
service_info.append(
|
|
f"\n调试模式: {'✅ 启动' if settings.DEBUG else '❌ 关闭'}",
|
|
style="bold italic",
|
|
)
|
|
service_info.append(
|
|
f"\n{settings.DATABASE_TYPE}: {'✅ 启动' if database_ready else '❌ 关闭'}",
|
|
style="bold italic",
|
|
)
|
|
service_info.append(
|
|
f"\nRedis: {'✅ 启动' if redis_ready else '❌ 关闭'}",
|
|
style="bold italic",
|
|
)
|
|
service_info.append(
|
|
f"\n调度器: {'✅ 启动' if scheduler_ready else '❌ 关闭'}",
|
|
style="bold italic",
|
|
)
|
|
service_info.append(
|
|
f"\n限流器: {'✅ 启动' if limiter_ready else '❌ 关闭'}",
|
|
style="bold italic",
|
|
)
|
|
|
|
docs_info = Text()
|
|
docs_info.append("📖 文档", style="bold magenta")
|
|
docs_info.append(f"\n🔗 Swagger: {docs_url}", style="blue link")
|
|
docs_info.append(f"\n🔗 ReDoc: {redoc_url}", style="blue link")
|
|
|
|
final_content = Group(
|
|
service_info,
|
|
"\n" + "─" * 40,
|
|
docs_info,
|
|
)
|
|
|
|
result = Panel(
|
|
renderable=final_content,
|
|
title="[bold purple]🚀 服务启动完成[/]",
|
|
border_style="green",
|
|
padding=(1, 2),
|
|
)
|
|
|
|
console.print(result)
|
|
|
|
|
|
def console_end() -> None:
|
|
"""
|
|
在终端输出服务关闭提示面板。
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
shutdown_content = Text()
|
|
shutdown_content.append("🛑 ", style="bold red")
|
|
shutdown_content.append("FastapiAdmin 服务关闭")
|
|
shutdown_content.append(f"\n⏰ {datetime.now().strftime('%H:%M:%S')}")
|
|
shutdown_content.append("\n👋 感谢使用!", style="dim")
|
|
|
|
result = Panel(
|
|
shutdown_content,
|
|
title="[bold red]服务关闭[/]",
|
|
border_style="red",
|
|
padding=(1, 2),
|
|
)
|
|
|
|
console.print(result)
|