mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 12:52:26 +00:00
style: 移除Python文件中的编码声明并优化代码格式
refactor: 重构前端组件和样式,添加AI助手功能 docs: 更新README文档,添加ruff代码检查说明 feat: 新增AI助手相关API和前端组件 chore: 更新.gitignore文件,添加ruff缓存配置 fix: 修复前端布局和设置相关的问题 perf: 优化代码结构和性能,移除冗余代码 test: 更新测试文件,移除编码声明 build: 更新依赖版本,调整requirements.txt
This commit is contained in:
@@ -1,23 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from app.api.v1.module_system.auth.schema import AuthSchema
|
||||
from app.core.base_schema import BatchSetAvailable
|
||||
from app.core.exceptions import CustomException
|
||||
from app.utils.common_util import (
|
||||
get_parent_id_map,
|
||||
get_parent_recursion,
|
||||
get_child_id_map,
|
||||
get_child_recursion,
|
||||
traversal_to_tree
|
||||
get_parent_id_map,
|
||||
get_parent_recursion,
|
||||
traversal_to_tree,
|
||||
)
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .crud import MenuCRUD
|
||||
from .schema import (
|
||||
MenuCreateSchema,
|
||||
MenuUpdateSchema,
|
||||
MenuOutSchema,
|
||||
MenuQueryParam
|
||||
)
|
||||
from .schema import MenuCreateSchema, MenuOutSchema, MenuQueryParam, MenuUpdateSchema
|
||||
|
||||
|
||||
class MenuService:
|
||||
@@ -29,11 +22,11 @@ class MenuService:
|
||||
async def get_menu_detail_service(cls, auth: AuthSchema, id: int) -> dict:
|
||||
"""
|
||||
获取菜单详情。
|
||||
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证对象。
|
||||
- id (int): 菜单ID。
|
||||
|
||||
|
||||
返回:
|
||||
- dict: 菜单详情对象。
|
||||
"""
|
||||
@@ -44,19 +37,19 @@ class MenuService:
|
||||
parent = await MenuCRUD(auth).get_by_id_crud(id=menu.parent_id)
|
||||
if parent:
|
||||
menu_out.parent_name = parent.name
|
||||
|
||||
|
||||
return menu_out.model_dump()
|
||||
|
||||
@classmethod
|
||||
async def get_menu_tree_service(cls, auth: AuthSchema, search: MenuQueryParam | None = None, order_by: list[dict] | None = None) -> list[dict]:
|
||||
"""
|
||||
获取菜单树形列表。
|
||||
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证对象。
|
||||
- search (MenuQueryParam | None): 查询参数对象。
|
||||
- order_by (list[dict] | None): 排序参数列表。
|
||||
|
||||
|
||||
返回:
|
||||
- list[dict]: 菜单树形列表对象。
|
||||
"""
|
||||
@@ -71,11 +64,11 @@ class MenuService:
|
||||
async def create_menu_service(cls, auth: AuthSchema, data: MenuCreateSchema) -> dict:
|
||||
"""
|
||||
创建菜单。
|
||||
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证对象。
|
||||
- data (MenuCreateSchema): 创建参数对象。
|
||||
|
||||
|
||||
返回:
|
||||
- dict: 创建的菜单对象。
|
||||
"""
|
||||
@@ -88,15 +81,15 @@ class MenuService:
|
||||
return new_menu_dict
|
||||
|
||||
@classmethod
|
||||
async def update_menu_service(cls, auth: AuthSchema,id:int, data: MenuUpdateSchema) -> dict:
|
||||
async def update_menu_service(cls, auth: AuthSchema, id: int, data: MenuUpdateSchema) -> dict:
|
||||
"""
|
||||
更新菜单。
|
||||
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证对象。
|
||||
- id (int): 菜单ID。
|
||||
- data (MenuUpdateSchema): 更新参数对象。
|
||||
|
||||
|
||||
返回:
|
||||
- dict: 更新的菜单对象。
|
||||
"""
|
||||
@@ -106,51 +99,51 @@ class MenuService:
|
||||
exist_menu = await MenuCRUD(auth).get(name=data.name)
|
||||
if exist_menu and exist_menu.id != id:
|
||||
raise CustomException(msg='更新失败,菜单名称重复')
|
||||
|
||||
|
||||
if data.parent_id:
|
||||
parent_menu = await MenuCRUD(auth).get_by_id_crud(id=data.parent_id)
|
||||
if not parent_menu:
|
||||
raise CustomException(msg='更新失败,父级菜单不存在')
|
||||
data.parent_name = parent_menu.name
|
||||
new_menu = await MenuCRUD(auth).update(id=id, data=data)
|
||||
|
||||
|
||||
await cls.set_menu_available_service(auth=auth, data=BatchSetAvailable(ids=[id], status=data.status))
|
||||
|
||||
|
||||
new_menu_dict = MenuOutSchema.model_validate(new_menu).model_dump()
|
||||
return new_menu_dict
|
||||
|
||||
|
||||
@classmethod
|
||||
async def delete_menu_service(cls, auth: AuthSchema, ids: list[int]) -> None:
|
||||
"""
|
||||
删除菜单。
|
||||
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证对象。
|
||||
- ids (list[int]): 菜单ID列表。
|
||||
|
||||
|
||||
返回:
|
||||
- None
|
||||
"""
|
||||
if len(ids) < 1:
|
||||
raise CustomException(msg='删除失败,删除对象不能为空')
|
||||
|
||||
|
||||
# 获取所有菜单列表,用于构建树形关系
|
||||
all_menus = await MenuCRUD(auth).get_list_crud()
|
||||
|
||||
|
||||
# 构建子菜单ID映射
|
||||
child_id_map = get_child_id_map(model_list=all_menus)
|
||||
|
||||
|
||||
# 收集所有需要删除的菜单ID,包括直接指定的ID和它们的所有子菜单ID
|
||||
delete_ids_set = set()
|
||||
|
||||
|
||||
for id in ids:
|
||||
# 递归获取该ID的所有子菜单ID
|
||||
all_descendants = get_child_recursion(id=id, id_map=child_id_map)
|
||||
delete_ids_set.update(all_descendants)
|
||||
|
||||
|
||||
# 将集合转换为列表
|
||||
delete_ids = list(delete_ids_set)
|
||||
|
||||
|
||||
# 执行批量删除操作
|
||||
await MenuCRUD(auth).delete(ids=delete_ids)
|
||||
|
||||
@@ -158,17 +151,17 @@ class MenuService:
|
||||
async def set_menu_available_service(cls, auth: AuthSchema, data: BatchSetAvailable) -> None:
|
||||
"""
|
||||
递归获取所有父、子级菜单,然后批量修改菜单可用状态。
|
||||
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证对象。
|
||||
- data (BatchSetAvailable): 批量设置可用参数对象。
|
||||
|
||||
|
||||
返回:
|
||||
- None
|
||||
"""
|
||||
menu_list = await MenuCRUD(auth).get_list_crud()
|
||||
total_ids = []
|
||||
|
||||
|
||||
if data.status == "0":
|
||||
# 激活,则需要把所有父级菜单都激活
|
||||
id_map = get_parent_id_map(model_list=menu_list)
|
||||
@@ -182,4 +175,4 @@ class MenuService:
|
||||
disable_ids = get_child_recursion(id=menu_id, id_map=id_map)
|
||||
total_ids.extend(disable_ids)
|
||||
|
||||
await MenuCRUD(auth).set_available_crud(ids=total_ids, status=data.status)
|
||||
await MenuCRUD(auth).set_available_crud(ids=total_ids, status=data.status)
|
||||
|
||||
Reference in New Issue
Block a user