mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
feat(tenant): 添加租户编码字段及相关功能
- 在后端模型、schema和前端接口中添加code字段 - 在前端表格和表单中显示和编辑code字段 - 修改租户名称长度限制从50到64字符 - 添加编码字段的验证逻辑 - 更新WangEditor组件返回纯文本格式
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from typing import Optional
|
||||
from typing import Optional, List, TYPE_CHECKING
|
||||
from sqlalchemy import Boolean, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, validates
|
||||
from sqlalchemy.orm import Mapped, mapped_column, validates, relationship
|
||||
|
||||
from app.core.base_model import ModelMixin
|
||||
|
||||
@@ -15,6 +15,7 @@ class TenantModel(ModelMixin):
|
||||
__table_args__ = ({'comment': '租户表'})
|
||||
|
||||
name: Mapped[Optional[str]] = mapped_column(String(64), nullable=True, default='', comment='租户名称')
|
||||
code: Mapped[Optional[str]] = mapped_column(String(20), nullable=True, default='', comment='租户编码')
|
||||
status: Mapped[bool] = mapped_column(Boolean(), default=True, nullable=False, comment="是否启用(True:启用 False:禁用)")
|
||||
|
||||
@validates('name')
|
||||
@@ -23,3 +24,13 @@ class TenantModel(ModelMixin):
|
||||
if not name or not name.strip():
|
||||
raise ValueError('名称不能为空')
|
||||
return name
|
||||
|
||||
@validates('code')
|
||||
def validate_code(self, key: str, code: str) -> str:
|
||||
"""验证编码格式校验"""
|
||||
if not code or not code.strip():
|
||||
raise ValueError('编码不能为空')
|
||||
if not code.isalnum():
|
||||
raise ValueError('编码只能包含字母和数字')
|
||||
return code
|
||||
|
||||
|
||||
@@ -8,11 +8,12 @@ from app.core.base_schema import BaseSchema
|
||||
|
||||
class TenantCreateSchema(BaseModel):
|
||||
"""新增模型"""
|
||||
name: str = Field(..., max_length=50, description='租户名称')
|
||||
name: str = Field(..., max_length=64, description='租户名称')
|
||||
code: Optional[str] = Field(default=None, max_length=20, description='租户编码')
|
||||
status: bool = Field(True, description="是否启用(True:启用 False:禁用)")
|
||||
description: Optional[str] = Field(default=None, max_length=255, description="描述")
|
||||
|
||||
@field_validator('name')
|
||||
@field_validator('name')
|
||||
@classmethod
|
||||
def _validate_name(cls, v: str) -> str:
|
||||
v = v.strip()
|
||||
@@ -26,7 +27,7 @@ class TenantCreateSchema(BaseModel):
|
||||
核心业务规则校验
|
||||
"""
|
||||
# 长度校验:名称最小长度
|
||||
if len(self.name) < 2 or len(self.name) > 50:
|
||||
if len(self.name) < 2 or len(self.name) > 64:
|
||||
raise ValueError('名称长度必须在2-50个字符之间')
|
||||
# 格式校验:名称只能包含字母、数字、下划线和中划线
|
||||
if not self.name.isalnum() and not all(c in '-_' for c in self.name):
|
||||
|
||||
Reference in New Issue
Block a user