nex_docus/backend/app/models/menu.py

45 lines
2.0 KiB
Python
Raw Normal View History

2025-12-20 11:18:59 +00:00
"""
菜单模型
"""
from sqlalchemy import Column, BigInteger, String, Integer, DateTime, SmallInteger
from sqlalchemy.sql import func
from app.core.database import Base
class SystemMenu(Base):
"""系统菜单表模型"""
__tablename__ = "system_menus"
id = Column(BigInteger, primary_key=True, autoincrement=True, comment="菜单ID")
parent_id = Column(BigInteger, default=0, comment="父菜单ID0表示根菜单")
menu_name = Column(String(50), nullable=False, comment="菜单名称")
menu_code = Column(String(50), nullable=False, unique=True, index=True, comment="菜单编码")
menu_type = Column(SmallInteger, nullable=False, comment="菜单类型1-目录 2-菜单 3-按钮/权限点")
path = Column(String(255), comment="路由路径")
component = Column(String(255), comment="组件路径")
icon = Column(String(100), comment="图标")
sort_order = Column(Integer, default=0, comment="排序号")
visible = Column(SmallInteger, default=1, comment="是否可见0-隐藏 1-显示")
status = Column(SmallInteger, default=1, index=True, comment="状态0-禁用 1-启用")
permission = Column(String(100), comment="权限字符串")
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间")
def __repr__(self):
return f"<SystemMenu(id={self.id}, menu_name='{self.menu_name}')>"
class RoleMenu(Base):
"""角色菜单授权表模型"""
__tablename__ = "role_menus"
id = Column(BigInteger, primary_key=True, autoincrement=True, comment="关联ID")
role_id = Column(BigInteger, nullable=False, index=True, comment="角色ID")
menu_id = Column(BigInteger, nullable=False, index=True, comment="菜单ID")
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
def __repr__(self):
return f"<RoleMenu(role_id={self.role_id}, menu_id={self.menu_id})>"