Skip to content

Commit d44a549

Browse files
authored
Update menu and add vben5 compatibility (#563)
* Update menu and add vben5 compatibility * Update sidebar api description
1 parent 289cf5b commit d44a549

File tree

10 files changed

+473
-267
lines changed

10 files changed

+473
-267
lines changed

backend/app/admin/api/v1/sys/menu.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
router = APIRouter()
1515

1616

17-
@router.get('/sidebar', summary='获取用户侧边栏', dependencies=[DependsJwtAuth])
17+
@router.get('/sidebar', summary='获取用户菜单侧边栏', description='适配 vben5', dependencies=[DependsJwtAuth])
1818
async def get_user_sidebar(request: Request) -> ResponseSchemaModel[list[dict[str, Any]]]:
1919
menu = await menu_service.get_user_menu_tree(request=request)
2020
return response_base.success(data=menu)

backend/app/admin/crud/crud_menu.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async def get_role_menus(self, db: AsyncSession, superuser: bool, menu_ids: list
6060
:return:
6161
"""
6262
stmt = select(self.model).order_by(asc(self.model.sort))
63-
filters = [self.model.menu_type.in_([0, 1])]
63+
filters = [self.model.type.in_([0, 1])]
6464
if not superuser:
6565
filters.append(self.model.id.in_(menu_ids))
6666
stmt = stmt.where(and_(*filters))

backend/app/admin/model/menu.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@ class Menu(Base):
2424
id: Mapped[id_key] = mapped_column(init=False)
2525
title: Mapped[str] = mapped_column(String(50), comment='菜单标题')
2626
name: Mapped[str] = mapped_column(String(50), comment='菜单名称')
27+
path: Mapped[str] = mapped_column(String(200), comment='路由地址')
2728
sort: Mapped[int] = mapped_column(default=0, comment='排序')
2829
icon: Mapped[str | None] = mapped_column(String(100), default=None, comment='菜单图标')
29-
path: Mapped[str | None] = mapped_column(String(200), default=None, comment='路由地址')
30-
menu_type: Mapped[int] = mapped_column(default=0, comment='菜单类型(0目录 1菜单 2按钮)')
30+
type: Mapped[int] = mapped_column(default=0, comment='菜单类型(0目录 1菜单 2按钮)')
3131
component: Mapped[str | None] = mapped_column(String(255), default=None, comment='组件路径')
3232
perms: Mapped[str | None] = mapped_column(String(100), default=None, comment='权限标识')
3333
status: Mapped[int] = mapped_column(default=1, comment='菜单状态(0停用 1正常)')
3434
display: Mapped[int] = mapped_column(default=1, comment='是否显示(0否 1是)')
3535
cache: Mapped[int] = mapped_column(default=1, comment='是否缓存(0否 1是)')
36+
link: Mapped[str | None] = mapped_column(
37+
LONGTEXT().with_variant(TEXT, 'postgresql'), default=None, comment='外链地址'
38+
)
3639
remark: Mapped[str | None] = mapped_column(
3740
LONGTEXT().with_variant(TEXT, 'postgresql'), default=None, comment='备注'
3841
)

backend/app/admin/schema/menu.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ class MenuSchemaBase(SchemaBase):
1313

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

2829

backend/app/admin/service/menu_service.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from backend.core.conf import settings
1313
from backend.database.db import async_db_session
1414
from backend.database.redis import redis_client
15-
from backend.utils.build_tree import get_tree_data
15+
from backend.utils.build_tree import get_tree_data, get_vben5_tree_data
1616

1717

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

8585
@staticmethod

0 commit comments

Comments
 (0)