diff --git a/backend/app/api/v1/module_system/tenant/model.py b/backend/app/api/v1/module_system/tenant/model.py index fa0681de..bc28d3fd 100644 --- a/backend/app/api/v1/module_system/tenant/model.py +++ b/backend/app/api/v1/module_system/tenant/model.py @@ -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 + diff --git a/backend/app/api/v1/module_system/tenant/schema.py b/backend/app/api/v1/module_system/tenant/schema.py index d2f5bb47..2a253099 100644 --- a/backend/app/api/v1/module_system/tenant/schema.py +++ b/backend/app/api/v1/module_system/tenant/schema.py @@ -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): diff --git a/backend/templates/python/model.py.j2 b/backend/templates/python/model.py.j2 index 5693eeed..f0d9d7d3 100644 --- a/backend/templates/python/model.py.j2 +++ b/backend/templates/python/model.py.j2 @@ -6,6 +6,7 @@ {% if table.sub %} from sqlalchemy.orm import relationship {% endif %} +from typing import Optional from sqlalchemy.orm import Mapped, mapped_column from app.core.base_model import CreatorMixin diff --git a/frontend/src/api/module_system/tenant.ts b/frontend/src/api/module_system/tenant.ts index dc716525..043d22f7 100644 --- a/frontend/src/api/module_system/tenant.ts +++ b/frontend/src/api/module_system/tenant.ts @@ -98,6 +98,7 @@ export interface ObjTable { index?: number; id?: number; name?: string; + code?: string; status?: boolean; description?: string; created_at?: string; @@ -108,6 +109,7 @@ export interface ObjTable { export interface ObjForm { id?: number; name?: string; + code?: string; status?: boolean; description?: string; } diff --git a/frontend/src/components/WangEditor/index.vue b/frontend/src/components/WangEditor/index.vue index 40433540..1eaadc5f 100644 --- a/frontend/src/components/WangEditor/index.vue +++ b/frontend/src/components/WangEditor/index.vue @@ -6,6 +6,8 @@ * 项目地址:https://gitee.com/youlaiorg/vue3-element-admin * * 在使用时,请保留此注释,感谢您对开源的支持! + * + * 修改:此版本返回纯文本格式,使用 editor.getText() 获取内容 --> @@ -92,6 +95,15 @@ const handleCreated = (editor: any) => { editorRef.value = editor; }; +// 处理内容变化 - 获取纯文本而不是HTML +const handleChange = (editor: any) => { + editorRef.value = editor; + if (editorRef.value) { + const text = editorRef.value.getText(); + modelValue.value = text; + } +}; + // 组件销毁时,也及时销毁编辑器,重要! onBeforeUnmount(() => { const editor = editorRef.value; diff --git a/frontend/src/views/module_system/tenant/index.vue b/frontend/src/views/module_system/tenant/index.vue index be26699a..c68300fd 100644 --- a/frontend/src/views/module_system/tenant/index.vue +++ b/frontend/src/views/module_system/tenant/index.vue @@ -154,6 +154,7 @@ +