feat: enforce required department and role codes with validation

- Updated DeptModel and RoleModel to make the `code` field mandatory and unique.
- Enhanced DeptCreateSchema and RoleCreateSchema to require a valid `code` format, ensuring it starts with a letter and is 2-16 characters long.
- Implemented validation logic in the backend to check for existing codes during updates, preventing duplicates.
- Adjusted frontend forms to reflect the required `code` field and added validation messages for user guidance.
This commit is contained in:
zhangtao
2026-04-04 02:16:53 +08:00
parent 8397c305bd
commit 1255729cd4
13 changed files with 103 additions and 43 deletions
@@ -74,8 +74,8 @@ class RoleModel(ModelMixin):
__permission_strategy__: PermissionFilterStrategy = PermissionFilterStrategy.USER_ROLE
name: Mapped[str] = mapped_column(String(64), nullable=False, comment="角色名称")
code: Mapped[str | None] = mapped_column(
String(16), nullable=True, index=True, comment="角色编码"
code: Mapped[str] = mapped_column(
String(16), nullable=False, unique=True, comment="角色编码"
)
order: Mapped[int] = mapped_column(Integer, nullable=False, default=999, comment="显示排序")
data_scope: Mapped[int] = mapped_column(