287 lines
7.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# _*_ coding : UTF-8 _*_
# @Time : 2025/01/18 03:40
# @UpdateTime : 2025/01/18 03:40
# @Author : sonder
# @File : permission.py
# @Software : PyCharm
# @Comment : 本程序
from tortoise import fields
from models.common import BaseModel
class Permission(BaseModel):
"""
权限表模型。
"""
menu_type = fields.SmallIntField(
description="菜单类型0菜单、1iframe、2外链、3按钮",
source_field="menu_type" # 映射到数据库字段 menu_type
)
"""
菜单类型。
- 0菜单
- 1iframe
- 2外链
- 3按钮
- 映射到数据库字段 menu_type。
"""
parent_id = fields.CharField(
max_length=36,
default="",
description="父权限ID",
source_field="parent_id" # 映射到数据库字段 parent_id
)
"""
父权限ID。
- 用于表示权限的层级关系。
- 默认为空字符串,表示顶级权限。
- 映射到数据库字段 parent_id。
"""
title = fields.CharField(
max_length=255,
description="菜单名称",
source_field="title" # 映射到数据库字段 title
)
"""
菜单名称。
- 兼容国际化、非国际化。
- 最大长度为 255 个字符。
- 映射到数据库字段 title。
"""
name = fields.CharField(
max_length=255,
null=True,
description="路由名称",
source_field="name" # 映射到数据库字段 name
)
"""
路由名称。
- 必须唯一,并且与前端路由组件的 `name` 保持一致。
- 最大长度为 255 个字符。
- 映射到数据库字段 name。
"""
path = fields.CharField(
max_length=255,
description="路由路径",
source_field="path" # 映射到数据库字段 path
)
"""
路由路径。
- 最大长度为 255 个字符。
- 映射到数据库字段 path。
"""
component = fields.CharField(
max_length=255,
null=True,
description="组件路径",
source_field="component" # 映射到数据库字段 component
)
"""
组件路径。
- 最大长度为 255 个字符。
- 允许为空。
- 映射到数据库字段 component。
"""
rank = fields.IntField(
default=1,
description="菜单排序",
source_field="rank" # 映射到数据库字段 rank
)
"""
菜单排序。
- 平台规定只有 `home` 路由的 `rank` 才能为 0。
- 默认为 1。
- 映射到数据库字段 rank。
"""
redirect = fields.CharField(
max_length=255,
null=True,
description="路由重定向",
source_field="redirect" # 映射到数据库字段 redirect
)
"""
路由重定向。
- 最大长度为 255 个字符。
- 允许为空。
- 映射到数据库字段 redirect。
"""
icon = fields.CharField(
max_length=255,
null=True,
description="菜单图标",
source_field="icon" # 映射到数据库字段 icon
)
"""
菜单图标。
- 最大长度为 255 个字符。
- 允许为空。
- 映射到数据库字段 icon。
"""
extra_icon = fields.CharField(
max_length=255,
null=True,
description="右侧图标",
source_field="extra_icon" # 映射到数据库字段 extra_icon
)
"""
右侧图标。
- 最大长度为 255 个字符。
- 允许为空。
- 映射到数据库字段 extra_icon。
"""
enter_transition = fields.CharField(
max_length=255,
null=True,
description="进场动画",
source_field="enter_transition" # 映射到数据库字段 enter_transition
)
"""
进场动画。
- 最大长度为 255 个字符。
- 允许为空。
- 映射到数据库字段 enter_transition。
"""
leave_transition = fields.CharField(
max_length=255,
null=True,
description="离场动画",
source_field="leave_transition" # 映射到数据库字段 leave_transition
)
"""
离场动画。
- 最大长度为 255 个字符。
- 允许为空。
- 映射到数据库字段 leave_transition。
"""
active_path = fields.CharField(
max_length=255,
null=True,
description="菜单激活路径",
source_field="active_path" # 映射到数据库字段 active_path
)
"""
菜单激活路径。
- 用于指定激活菜单的路径。
- 最大长度为 255 个字符。
- 允许为空。
- 映射到数据库字段 active_path。
"""
auths = fields.CharField(
max_length=255,
null=True,
description="权限标识",
source_field="auths" # 映射到数据库字段 auths
)
"""
权限标识。
- 用于按钮级别权限设置。
- 最大长度为 255 个字符。
- 允许为空。
- 映射到数据库字段 auths。
"""
frame_src = fields.CharField(
max_length=255,
null=True,
description="iframe链接地址",
source_field="frame_src" # 映射到数据库字段 frame_src
)
"""
iframe 链接地址。
- 最大长度为 255 个字符。
- 允许为空。
- 映射到数据库字段 frame_src。
"""
frame_loading = fields.BooleanField(
default=True,
description="iframe加载动画",
source_field="frame_loading" # 映射到数据库字段 frame_loading
)
"""
iframe 加载动画。
- 是否开启首次加载动画。
- 默认为 True。
- 映射到数据库字段 frame_loading。
"""
keep_alive = fields.BooleanField(
default=False,
description="缓存页面",
source_field="keep_alive" # 映射到数据库字段 keep_alive
)
"""
缓存页面。
- 是否缓存该路由页面。
- 默认为 False。
- 映射到数据库字段 keep_alive。
"""
hidden_tag = fields.BooleanField(
default=False,
description="隐藏标签页",
source_field="hidden_tag" # 映射到数据库字段 hidden_tag
)
"""
隐藏标签页。
- 是否禁止将当前菜单名称添加到标签页。
- 默认为 False。
- 映射到数据库字段 hidden_tag。
"""
fixed_tag = fields.BooleanField(
default=False,
description="固定标签页",
source_field="fixed_tag" # 映射到数据库字段 fixed_tag
)
"""
固定标签页。
- 是否固定显示在标签页且不可关闭。
- 默认为 False。
- 映射到数据库字段 fixed_tag。
"""
show_link = fields.BooleanField(
default=True,
description="显示菜单",
source_field="show_link" # 映射到数据库字段 show_link
)
"""
显示菜单。
- 是否显示该菜单。
- 默认为 True。
- 映射到数据库字段 show_link。
"""
show_parent = fields.BooleanField(
default=True,
description="显示父级菜单",
source_field="show_parent" # 映射到数据库字段 show_parent
)
"""
显示父级菜单。
- 是否显示父级菜单。
- 默认为 True。
- 映射到数据库字段 show_parent。
"""
class Meta:
table = "permission" # 数据库表名
table_description = "权限表" # 表描述
ordering = ["rank", "-create_time"] # 默认按排序权重和创建时间排序