mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 05:02:57 +00:00
chore: 批量修复优化代码与配置
1. 统一修复多处状态选项值类型从字符串转为数字 2. 优化用户更新逻辑简化代码 3. 新增ORM转Schema工具方法优化数据转换 4. 调整部门与菜单模型加载配置 5. 修复订单详情展示逻辑与样式 6. 移动主题配置到单独文件并更新gitignore
This commit is contained in:
@@ -23,7 +23,7 @@ class MenuModel(ModelMixin):
|
||||
|
||||
__tablename__: str = "platform_menu"
|
||||
__table_args__: dict[str, str] = {"comment": "平台菜单表"}
|
||||
__loader_options__: list[str] = ["roles"]
|
||||
__loader_options__: list[str] = ["roles", "children"]
|
||||
__permission_strategy__: PermissionFilterStrategy = PermissionFilterStrategy.ROLE_BASED
|
||||
|
||||
name: Mapped[str] = mapped_column(String(50), nullable=False, comment="菜单名称")
|
||||
@@ -115,6 +115,7 @@ class MenuModel(ModelMixin):
|
||||
back_populates="parent",
|
||||
foreign_keys="MenuModel.parent_id",
|
||||
order_by="MenuModel.order",
|
||||
lazy="selectin",
|
||||
)
|
||||
roles: Mapped[list["RoleModel"]] = relationship(
|
||||
secondary="sys_role_menus", back_populates="menus", lazy="selectin"
|
||||
|
||||
@@ -77,15 +77,24 @@ class MenuService:
|
||||
返回:
|
||||
- dict: 菜单详情对象。
|
||||
"""
|
||||
menu = await MenuCRUD(auth).get(id=id)
|
||||
# 创建实例后再设置parent_name属性
|
||||
menu_out = MenuOutSchema.model_validate(menu)
|
||||
if menu and menu.parent_id:
|
||||
from app.utils.common_util import SqlalchemyUtil
|
||||
|
||||
menu = await MenuCRUD(auth).get_with_convert(
|
||||
id=id,
|
||||
preload=["roles"],
|
||||
converter=lambda m: SqlalchemyUtil.orm_to_schema(
|
||||
m,
|
||||
MenuOutSchema,
|
||||
{"children": None, "parent_name": None, "roles": m.roles},
|
||||
),
|
||||
)
|
||||
if not menu:
|
||||
raise CustomException(msg="菜单不存在")
|
||||
if menu.parent_id:
|
||||
parent = await MenuCRUD(auth).get(id=menu.parent_id)
|
||||
if parent:
|
||||
menu_out.parent_name = parent.name
|
||||
|
||||
return menu_out
|
||||
menu.parent_name = parent.name
|
||||
return menu
|
||||
|
||||
@classmethod
|
||||
async def get_menu_tree_service(
|
||||
@@ -172,6 +181,8 @@ class MenuService:
|
||||
parent_menu = await MenuCRUD(auth).get(id=data.parent_id)
|
||||
if not parent_menu:
|
||||
raise CustomException(msg="更新失败,父级菜单不存在")
|
||||
from app.utils.common_util import SqlalchemyUtil
|
||||
|
||||
new_menu = await MenuCRUD(auth).update(id=id, data=data)
|
||||
|
||||
if data.status is not None:
|
||||
@@ -179,8 +190,16 @@ class MenuService:
|
||||
auth=auth, data=BatchSetAvailable(ids=[id], status=data.status)
|
||||
)
|
||||
|
||||
new_menu_dict = MenuOutSchema.model_validate(new_menu)
|
||||
return new_menu_dict
|
||||
menu_out = SqlalchemyUtil.orm_to_schema(
|
||||
new_menu,
|
||||
MenuOutSchema,
|
||||
{"children": None, "parent_name": None, "roles": new_menu.roles},
|
||||
)
|
||||
if menu_out.parent_id:
|
||||
parent = await MenuCRUD(auth).get(id=menu_out.parent_id)
|
||||
if parent:
|
||||
menu_out.parent_name = parent.name
|
||||
return menu_out
|
||||
|
||||
@classmethod
|
||||
async def delete_menu_service(cls, auth: AuthSchema, ids: list[int]) -> None:
|
||||
|
||||
Reference in New Issue
Block a user