Become a sponsor

系统配置
系统配置模块用于管理动态的键值对配置项,与数据字典类似但更偏向系统级参数。支持分组管理,可通过接口动态修改,无需重启服务。模块位于 src/modules/configuration/,端点位于 src/api/v1/endpoints/config.py 和 config_item.py。
src/modules/configuration/
├── config/ # 配置分组
│ ├── models.py
│ ├── schemas.py
│ ├── repository.py
│ └── service.py
└── config_item/ # 配置项(KV)
├── models.py
├── schemas.py
├── repository.py
└── service.py# src/modules/configuration/config/models.py
# ============================================================
# 配置模型
# ============================================================
class Config(base_model, base_db):
"""配置模型类"""
# ============================================================
# 表名配置
# ============================================================
__tablename__ = DB_PREFIX + "config"
__table_comment__ = "系统配置表"
# ============================================================
# 字段定义
# ============================================================
# 配置名称
name = Column(String(150), nullable=False, index=True, comment="配置名称")
# 配置编码
code = Column(String(150), nullable=False, index=True, comment="配置编码")
# 配置排序
sort = Column(Integer, default=0, server_default=text('0'), comment="配置排序")
# 配置备注
note = Column(String(255), nullable=True, comment="配置备注")
# ============================================================
# 内置方法
# ============================================================
def __str__(self):
"""返回配置ID作为字符串表示"""
return "配置{}".format(self.id)# src/modules/configuration/config_item/models.py
# ============================================================
# 配置项模型
# ============================================================
class ConfigItem(base_model, base_db):
"""配置项模型类"""
# ============================================================
# 表名配置
# ============================================================
__tablename__ = DB_PREFIX + "config_item"
__table_comment__ = "配置项表"
# ============================================================
# 字段定义
# ============================================================
# 配置项名称
name = Column(String(150), nullable=False, index=True, comment="配置项名称")
# 配置项编码
code = Column(String(150), nullable=False, comment="配置项编码")
# 配置项值
value = Column(String(1000), nullable=True, comment="配置项值")
# 配置选项
options = Column(Text, nullable=True, comment="配置选项")
# 配置ID
config_id = Column(Integer, default=0, server_default=text('0'), index=True, comment="配置ID")
# 配置类型
type = Column(String(150), nullable=False, comment="配置类型")
# 配置状态:1-正常 2-停用
status = Column(Integer, default=1, server_default=text('1'), index=True, comment="配置状态:1-正常 2-停用")
# 配置项排序
sort = Column(Integer, default=0, server_default=text('0'), comment="配置项顺序")
# 配置项备注
note = Column(String(255), nullable=True, comment="配置项备注")
# ============================================================
# 内置方法
# ============================================================
def __str__(self):
"""返回配置项ID作为字符串表示"""
return "配置项{}".format(self.id)系统配置适用于以下场景:
1. 网站基本信息(站点名称、Logo、版权信息)
2. 邮件配置(SMTP 服务器、端口、账号)
3. 短信配置(API Key、模板 ID)
4. 存储配置(OSS Bucket、上传限制)
5. 业务参数(默认密码、分页大小等)GET /api/v1/config/item/list?configId=1GET /api/v1/config/item/detail/{id}POST /api/v1/config/item/add
PUT /api/v1/config/item/update| 特性 | 数据字典 | 系统配置 |
|---|---|---|
| 用途 | 枚举值(下拉选项) | 系统参数(配置值) |
| 值类型 | 简单值(字符串) | 可存储较长的配置内容 |
| 典型场景 | 状态、性别、类型 | SMTP配置、站点信息 |
| 前端用法 | el-select 选项 | 配置表单 |
系统配置模块具备以下特点:
1. KV 结构:配置分组 + 配置项,灵活管理各类参数
2. 动态修改:通过接口修改,无需重启服务
3. 分组管理:按功能模块分组,清晰组织配置项
4. 与字典互补:字典管理枚举值,配置管理系统参数