Skip to content

Update menu and add vben5 compatibility #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/app/admin/api/v1/sys/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
router = APIRouter()


@router.get('/sidebar', summary='获取用户侧边栏', dependencies=[DependsJwtAuth])
@router.get('/sidebar', summary='获取用户菜单侧边栏', description='适配 vben5', dependencies=[DependsJwtAuth])
async def get_user_sidebar(request: Request) -> ResponseSchemaModel[list[dict[str, Any]]]:
menu = await menu_service.get_user_menu_tree(request=request)
return response_base.success(data=menu)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/admin/crud/crud_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def get_role_menus(self, db: AsyncSession, superuser: bool, menu_ids: list
:return:
"""
stmt = select(self.model).order_by(asc(self.model.sort))
filters = [self.model.menu_type.in_([0, 1])]
filters = [self.model.type.in_([0, 1])]
if not superuser:
filters.append(self.model.id.in_(menu_ids))
stmt = stmt.where(and_(*filters))
Expand Down
7 changes: 5 additions & 2 deletions backend/app/admin/model/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ class Menu(Base):
id: Mapped[id_key] = mapped_column(init=False)
title: Mapped[str] = mapped_column(String(50), comment='菜单标题')
name: Mapped[str] = mapped_column(String(50), comment='菜单名称')
path: Mapped[str] = mapped_column(String(200), comment='路由地址')
sort: Mapped[int] = mapped_column(default=0, comment='排序')
icon: Mapped[str | None] = mapped_column(String(100), default=None, comment='菜单图标')
path: Mapped[str | None] = mapped_column(String(200), default=None, comment='路由地址')
menu_type: Mapped[int] = mapped_column(default=0, comment='菜单类型(0目录 1菜单 2按钮)')
type: Mapped[int] = mapped_column(default=0, comment='菜单类型(0目录 1菜单 2按钮)')
component: Mapped[str | None] = mapped_column(String(255), default=None, comment='组件路径')
perms: Mapped[str | None] = mapped_column(String(100), default=None, comment='权限标识')
status: Mapped[int] = mapped_column(default=1, comment='菜单状态(0停用 1正常)')
display: Mapped[int] = mapped_column(default=1, comment='是否显示(0否 1是)')
cache: Mapped[int] = mapped_column(default=1, comment='是否缓存(0否 1是)')
link: Mapped[str | None] = mapped_column(
LONGTEXT().with_variant(TEXT, 'postgresql'), default=None, comment='外链地址'
)
remark: Mapped[str | None] = mapped_column(
LONGTEXT().with_variant(TEXT, 'postgresql'), default=None, comment='备注'
)
Expand Down
5 changes: 3 additions & 2 deletions backend/app/admin/schema/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ class MenuSchemaBase(SchemaBase):

title: str = Field(description='菜单标题')
name: str = Field(description='菜单名称')
path: str = Field(description='路由路径')
parent_id: int | None = Field(None, description='菜单父级 ID')
sort: int = Field(0, ge=0, description='排序')
icon: str | None = Field(None, description='图标')
path: str | None = Field(None, description='路由路径')
menu_type: MenuType = Field(MenuType.directory, description='菜单类型(0目录 1菜单 2按钮)')
type: MenuType = Field(MenuType.directory, description='菜单类型(0目录 1菜单 2按钮)')
component: str | None = Field(None, description='组件路径')
perms: str | None = Field(None, description='权限标识')
status: StatusType = Field(StatusType.enable, description='状态')
display: StatusType = Field(StatusType.enable, description='是否显示')
cache: StatusType = Field(StatusType.enable, description='是否缓存')
link: str | None = Field(None, description='外链地址')
remark: str | None = Field(None, description='备注')


Expand Down
4 changes: 2 additions & 2 deletions backend/app/admin/service/menu_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from backend.core.conf import settings
from backend.database.db import async_db_session
from backend.database.redis import redis_client
from backend.utils.build_tree import get_tree_data
from backend.utils.build_tree import get_tree_data, get_vben5_tree_data


class MenuService:
Expand Down Expand Up @@ -79,7 +79,7 @@ async def get_user_menu_tree(*, request: Request) -> list[dict[str, Any]]:
for role in roles:
menu_ids.extend([menu.id for menu in role.menus])
menu_select = await menu_dao.get_role_menus(db, request.user.is_superuser, menu_ids)
menu_tree = get_tree_data(menu_select)
menu_tree = get_vben5_tree_data(menu_select)
return menu_tree

@staticmethod
Expand Down
Loading