From 086bce3972efe9150a7ad10646769898c8bbaba0 Mon Sep 17 00:00:00 2001
From: zhangtao <9480807882@qq.com>
Date: Thu, 13 Nov 2025 23:47:52 +0800
Subject: [PATCH] =?UTF-8?q?feat(tenant):=20=E6=B7=BB=E5=8A=A0=E7=A7=9F?=
=?UTF-8?q?=E6=88=B7=E7=BC=96=E7=A0=81=E5=AD=97=E6=AE=B5=E5=8F=8A=E7=9B=B8?=
=?UTF-8?q?=E5=85=B3=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 在后端模型、schema和前端接口中添加code字段
- 在前端表格和表单中显示和编辑code字段
- 修改租户名称长度限制从50到64字符
- 添加编码字段的验证逻辑
- 更新WangEditor组件返回纯文本格式
---
backend/app/api/v1/module_system/tenant/model.py | 15 +++++++++++++--
.../app/api/v1/module_system/tenant/schema.py | 7 ++++---
backend/templates/python/model.py.j2 | 1 +
frontend/src/api/module_system/tenant.ts | 2 ++
frontend/src/components/WangEditor/index.vue | 12 ++++++++++++
.../src/views/module_system/tenant/index.vue | 16 ++++++++++++++--
6 files changed, 46 insertions(+), 7 deletions(-)
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() 获取内容
-->
@@ -24,6 +26,7 @@
:default-config="editorConfig"
mode="simple"
@on-created="handleCreated"
+ @on-change="handleChange"
/>
@@ -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 @@
+
@@ -192,6 +193,9 @@
{{ detailFormData.name }}
+
+ {{ detailFormData.code }}
+
{{ detailFormData.status ? '启用' : '停用' }}
@@ -215,7 +219,10 @@
-
+
+
+
+
@@ -259,7 +266,7 @@