mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-23 13:13:09 +00:00
refactor: 大规模代码整理与功能优化
1. 重构后端API路由、CRUD与模块结构,整合日志管理,移除废弃demo代码 2. 优化前端组件类型定义、样式与路由配置,修复权限判断逻辑 3. 调整默认排序规则、滚动条样式与工具类函数,更新依赖与配置文件 4. 修复多处类型不匹配与默认值问题,完善表单与菜单验证逻辑
This commit is contained in:
@@ -4,18 +4,16 @@ from fastapi.responses import JSONResponse
|
||||
from app.api.v1.module_monitor.server.schema import ServerMonitorSchema
|
||||
from app.common.response import ResponseSchema, SuccessResponse
|
||||
from app.core.dependencies import AuthPermission
|
||||
from app.core.logger import log
|
||||
from app.core.router_class import OperationLogRoute
|
||||
|
||||
from .service import ServerService
|
||||
|
||||
ServerRouter = APIRouter(route_class=OperationLogRoute, prefix="/server", tags=["服务器监控"])
|
||||
ServerRouter = APIRouter(route_class=OperationLogRoute, prefix="/server", tags=["系统监控/服务器监控"])
|
||||
|
||||
|
||||
@ServerRouter.get(
|
||||
"/info",
|
||||
summary="查询服务器监控信息",
|
||||
description="查询服务器监控信息",
|
||||
dependencies=[Depends(AuthPermission(["module_monitor:server:query"]))],
|
||||
response_model=ResponseSchema[ServerMonitorSchema],
|
||||
)
|
||||
@@ -27,6 +25,5 @@ async def get_monitor_server_info_controller() -> JSONResponse:
|
||||
- JSONResponse: 包含服务器监控信息的JSON响应。
|
||||
"""
|
||||
result_dict = await ServerService.get_server_monitor_info_service()
|
||||
log.info(f"获取服务器监控信息成功: {result_dict}")
|
||||
|
||||
return SuccessResponse(data=result_dict, msg="获取服务器监控信息成功")
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class CpuInfoSchema(BaseModel):
|
||||
"""CPU信息模型"""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
cpu_num: int = Field(description="CPU核心数")
|
||||
used: float = Field(ge=0, le=100, description="CPU用户使用率(%)")
|
||||
sys: float = Field(ge=0, le=100, description="CPU系统使用率(%)")
|
||||
@@ -15,8 +13,6 @@ class CpuInfoSchema(BaseModel):
|
||||
class MemoryInfoSchema(BaseModel):
|
||||
"""内存信息模型"""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
total: str = Field(description="内存总量")
|
||||
used: str = Field(description="已用内存")
|
||||
free: str = Field(description="剩余内存")
|
||||
@@ -26,8 +22,6 @@ class MemoryInfoSchema(BaseModel):
|
||||
class SysInfoSchema(BaseModel):
|
||||
"""系统信息模型"""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
computer_ip: str = Field(description="服务器IP")
|
||||
computer_name: str = Field(description="服务器名称")
|
||||
os_arch: str = Field(description="系统架构")
|
||||
@@ -38,8 +32,6 @@ class SysInfoSchema(BaseModel):
|
||||
class PyInfoSchema(BaseModel):
|
||||
"""Python运行信息模型"""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
name: str = Field(description="Python名称")
|
||||
version: str = Field(description="Python版本")
|
||||
start_time: str = Field(description="启动时间")
|
||||
@@ -54,8 +46,6 @@ class PyInfoSchema(BaseModel):
|
||||
class DiskInfoSchema(BaseModel):
|
||||
"""磁盘信息模型"""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
dir_name: str = Field(description="磁盘路径")
|
||||
sys_type_name: str = Field(description="文件系统类型")
|
||||
type_name: str = Field(description="磁盘类型")
|
||||
@@ -68,8 +58,6 @@ class DiskInfoSchema(BaseModel):
|
||||
class ServerMonitorSchema(BaseModel):
|
||||
"""服务器监控信息模型"""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
cpu: CpuInfoSchema = Field(description="CPU信息")
|
||||
mem: MemoryInfoSchema = Field(description="内存信息")
|
||||
py: PyInfoSchema = Field(description="Python运行信息")
|
||||
|
||||
@@ -21,7 +21,7 @@ class ServerService:
|
||||
"""服务监控模块服务层"""
|
||||
|
||||
@classmethod
|
||||
async def get_server_monitor_info_service(cls) -> dict:
|
||||
async def get_server_monitor_info_service(cls) -> ServerMonitorSchema:
|
||||
"""
|
||||
获取服务器监控信息
|
||||
|
||||
@@ -34,7 +34,7 @@ class ServerService:
|
||||
sys=cls._get_system_info(),
|
||||
py=cls._get_python_info(),
|
||||
disks=cls._get_disk_info(),
|
||||
).model_dump()
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _get_cpu_info(cls) -> CpuInfoSchema:
|
||||
|
||||
Reference in New Issue
Block a user