Skip to content

Commit 9fc6bdf

Browse files
committed
Optimize admin schema
1 parent 3763804 commit 9fc6bdf

File tree

17 files changed

+302
-208
lines changed

17 files changed

+302
-208
lines changed

backend/app/admin/conf.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,27 @@
88

99

1010
class AdminSettings(BaseSettings):
11-
"""Admin Settings"""
11+
"""Admin 配置"""
1212

1313
model_config = SettingsConfigDict(env_file=f'{BASE_PATH}/.env', env_file_encoding='utf-8', extra='ignore')
1414

15-
# OAuth2:https://github.com/fastapi-practices/fastapi_oauth20
16-
# GitHub
15+
# .env OAuth2 配置
1716
OAUTH2_GITHUB_CLIENT_ID: str
1817
OAUTH2_GITHUB_CLIENT_SECRET: str
19-
OAUTH2_GITHUB_REDIRECT_URI: str = 'http://127.0.0.1:8000/api/v1/oauth2/github/callback'
20-
21-
# Linux Do
2218
OAUTH2_LINUX_DO_CLIENT_ID: str
2319
OAUTH2_LINUX_DO_CLIENT_SECRET: str
24-
OAUTH2_LINUX_DO_REDIRECT_URI: str = 'http://127.0.0.1:8000/api/v1/oauth2/linux-do/callback'
2520

26-
# Front-end redirect address
21+
# OAuth2 配置
22+
OAUTH2_GITHUB_REDIRECT_URI: str = 'http://127.0.0.1:8000/api/v1/oauth2/github/callback'
23+
OAUTH2_LINUX_DO_REDIRECT_URI: str = 'http://127.0.0.1:8000/api/v1/oauth2/linux-do/callback'
2724
OAUTH2_FRONTEND_REDIRECT_URI: str = 'http://localhost:5173/oauth2/callback'
2825

29-
# Captcha
26+
# 验证码配置
3027
CAPTCHA_LOGIN_REDIS_PREFIX: str = 'fba:login:captcha'
31-
CAPTCHA_LOGIN_EXPIRE_SECONDS: int = 60 * 5 # 过期时间,单位:秒
28+
CAPTCHA_LOGIN_EXPIRE_SECONDS: int = 60 * 5 # 3 分钟
3229

33-
# Config
34-
CONFIG_BUILT_IN_TYPES: list = ['website', 'protocol', 'policy']
30+
# 系统配置
31+
CONFIG_BUILT_IN_TYPES: list[str] = ['website', 'protocol', 'policy']
3532

3633

3734
@lru_cache

backend/app/admin/schema/captcha.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66

77

88
class GetCaptchaDetail(SchemaBase):
9+
"""验证码详情"""
10+
911
image_type: str = Field(description='图片类型')
1012
image: str = Field(description='图片内容')

backend/app/admin/schema/config.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,43 @@
22
# -*- coding: utf-8 -*-
33
from datetime import datetime
44

5-
from pydantic import ConfigDict
5+
from pydantic import ConfigDict, Field
66

77
from backend.common.schema import SchemaBase
88

99

1010
class SaveBuiltInConfigParam(SchemaBase):
11-
name: str
12-
key: str
13-
value: str
11+
"""保存内置配置参数"""
12+
13+
name: str = Field(description='配置名称')
14+
key: str = Field(description='配置键名')
15+
value: str = Field(description='配置值')
1416

1517

1618
class ConfigSchemaBase(SchemaBase):
17-
name: str
18-
type: str | None
19-
key: str
20-
value: str
21-
is_frontend: bool
22-
remark: str | None
19+
"""配置基础模型"""
20+
21+
name: str = Field(description='配置名称')
22+
type: str | None = Field(default=None, description='配置类型')
23+
key: str = Field(description='配置键名')
24+
value: str = Field(description='配置值')
25+
is_frontend: bool = Field(description='是否前端配置')
26+
remark: str | None = Field(default=None, description='备注')
2327

2428

2529
class CreateConfigParam(ConfigSchemaBase):
26-
pass
30+
"""创建配置参数"""
2731

2832

2933
class UpdateConfigParam(ConfigSchemaBase):
30-
pass
34+
"""更新配置参数"""
3135

3236

3337
class GetConfigDetail(ConfigSchemaBase):
38+
"""配置详情"""
39+
3440
model_config = ConfigDict(from_attributes=True)
3541

36-
id: int
37-
created_time: datetime
38-
updated_time: datetime | None = None
42+
id: int = Field(description='配置 ID')
43+
created_time: datetime = Field(description='创建时间')
44+
updated_time: datetime | None = Field(default=None, description='更新时间')

backend/app/admin/schema/data_rule.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,33 @@
99

1010

1111
class DataRuleSchemaBase(SchemaBase):
12-
name: str
13-
model: str
14-
column: str
15-
operator: RoleDataRuleOperatorType = Field(RoleDataRuleOperatorType.OR)
16-
expression: RoleDataRuleExpressionType = Field(RoleDataRuleExpressionType.eq)
17-
value: str
12+
"""数据规则基础模型"""
13+
14+
name: str = Field(description='规则名称')
15+
model: str = Field(description='模型名称')
16+
column: str = Field(description='字段名称')
17+
operator: RoleDataRuleOperatorType = Field(default=RoleDataRuleOperatorType.OR, description='操作符(AND/OR)')
18+
expression: RoleDataRuleExpressionType = Field(default=RoleDataRuleExpressionType.eq, description='表达式类型')
19+
value: str = Field(description='规则值')
1820

1921

2022
class CreateDataRuleParam(DataRuleSchemaBase):
21-
pass
23+
"""创建数据规则参数"""
2224

2325

2426
class UpdateDataRuleParam(DataRuleSchemaBase):
25-
pass
27+
"""更新数据规则参数"""
2628

2729

2830
class GetDataRuleDetail(DataRuleSchemaBase):
31+
"""数据规则详情"""
32+
2933
model_config = ConfigDict(from_attributes=True)
3034

31-
id: int
32-
created_time: datetime
33-
updated_time: datetime | None = None
35+
id: int = Field(description='规则 ID')
36+
created_time: datetime = Field(description='创建时间')
37+
updated_time: datetime | None = Field(default=None, description='更新时间')
3438

35-
def __hash__(self):
39+
def __hash__(self) -> int:
40+
"""计算哈希值"""
3641
return hash(self.name)

backend/app/admin/schema/dept.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,31 @@
99

1010

1111
class DeptSchemaBase(SchemaBase):
12-
name: str
13-
parent_id: int | None = Field(default=None, description='部门父级ID')
12+
"""部门基础模型"""
13+
14+
name: str = Field(description='部门名称')
15+
parent_id: int | None = Field(default=None, description='部门父级 ID')
1416
sort: int = Field(default=0, ge=0, description='排序')
15-
leader: str | None = None
16-
phone: CustomPhoneNumber | None = None
17-
email: CustomEmailStr | None = None
18-
status: StatusType = Field(default=StatusType.enable)
17+
leader: str | None = Field(default=None, description='负责人')
18+
phone: CustomPhoneNumber | None = Field(default=None, description='联系电话')
19+
email: CustomEmailStr | None = Field(default=None, description='邮箱')
20+
status: StatusType = Field(default=StatusType.enable, description='状态')
1921

2022

2123
class CreateDeptParam(DeptSchemaBase):
22-
pass
24+
"""创建部门参数"""
2325

2426

2527
class UpdateDeptParam(DeptSchemaBase):
26-
pass
28+
"""更新部门参数"""
2729

2830

2931
class GetDeptDetail(DeptSchemaBase):
32+
"""部门详情"""
33+
3034
model_config = ConfigDict(from_attributes=True)
3135

32-
id: int
33-
del_flag: bool
34-
created_time: datetime
35-
updated_time: datetime | None = None
36+
id: int = Field(description='部门 ID')
37+
del_flag: bool = Field(description='是否删除')
38+
created_time: datetime = Field(description='创建时间')
39+
updated_time: datetime | None = Field(default=None, description='更新时间')

backend/app/admin/schema/dict_data.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,35 @@
1010

1111

1212
class DictDataSchemaBase(SchemaBase):
13-
type_id: int
14-
label: str
15-
value: str
16-
sort: int
17-
status: StatusType = Field(default=StatusType.enable)
18-
remark: str | None = None
13+
"""字典数据基础模型"""
14+
15+
type_id: int = Field(description='字典类型 ID')
16+
label: str = Field(description='字典标签')
17+
value: str = Field(description='字典值')
18+
sort: int = Field(description='排序')
19+
status: StatusType = Field(default=StatusType.enable, description='状态')
20+
remark: str | None = Field(default=None, description='备注')
1921

2022

2123
class CreateDictDataParam(DictDataSchemaBase):
22-
pass
24+
"""创建字典数据参数"""
2325

2426

2527
class UpdateDictDataParam(DictDataSchemaBase):
26-
pass
28+
"""更新字典数据参数"""
2729

2830

2931
class GetDictDataDetail(DictDataSchemaBase):
32+
"""字典数据详情"""
33+
3034
model_config = ConfigDict(from_attributes=True)
3135

32-
id: int
33-
created_time: datetime
34-
updated_time: datetime | None = None
36+
id: int = Field(description='字典数据 ID')
37+
created_time: datetime = Field(description='创建时间')
38+
updated_time: datetime | None = Field(default=None, description='更新时间')
3539

3640

3741
class GetDictDataWithRelation(DictDataSchemaBase):
38-
type: GetDictTypeDetail | None = None
42+
"""字典数据关联详情"""
43+
44+
type: GetDictTypeDetail | None = Field(default=None, description='字典类型信息')

backend/app/admin/schema/dict_type.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,31 @@
99

1010

1111
class DictTypeSchemaBase(SchemaBase):
12-
name: str
13-
code: str
14-
status: StatusType = Field(default=StatusType.enable)
15-
remark: str | None = None
12+
"""字典类型基础模型"""
13+
14+
name: str = Field(description='字典名称')
15+
code: str = Field(description='字典编码')
16+
status: StatusType = Field(default=StatusType.enable, description='状态')
17+
remark: str | None = Field(default=None, description='备注')
1618

1719

1820
class CreateDictTypeParam(DictTypeSchemaBase):
21+
"""创建字典类型参数"""
22+
1923
pass
2024

2125

2226
class UpdateDictTypeParam(DictTypeSchemaBase):
27+
"""更新字典类型参数"""
28+
2329
pass
2430

2531

2632
class GetDictTypeDetail(DictTypeSchemaBase):
33+
"""字典类型详情"""
34+
2735
model_config = ConfigDict(from_attributes=True)
2836

29-
id: int
30-
created_time: datetime
31-
updated_time: datetime | None = None
37+
id: int = Field(description='字典类型 ID')
38+
created_time: datetime = Field(description='创建时间')
39+
updated_time: datetime | None = Field(default=None, description='更新时间')

backend/app/admin/schema/login_log.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,41 @@
22
# -*- coding: utf-8 -*-
33
from datetime import datetime
44

5-
from pydantic import ConfigDict
5+
from pydantic import ConfigDict, Field
66

77
from backend.common.schema import SchemaBase
88

99

1010
class LoginLogSchemaBase(SchemaBase):
11-
user_uuid: str
12-
username: str
13-
status: int
14-
ip: str
15-
country: str | None
16-
region: str | None
17-
city: str | None
18-
user_agent: str
19-
browser: str | None
20-
os: str | None
21-
device: str | None
22-
msg: str
23-
login_time: datetime
11+
"""登录日志基础模型"""
12+
13+
user_uuid: str = Field(description='用户 UUID')
14+
username: str = Field(description='用户名')
15+
status: int = Field(description='登录状态')
16+
ip: str = Field(description='IP 地址')
17+
country: str | None = Field(default=None, description='国家')
18+
region: str | None = Field(default=None, description='地区')
19+
city: str | None = Field(default=None, description='城市')
20+
user_agent: str = Field(description='用户代理')
21+
browser: str | None = Field(default=None, description='浏览器')
22+
os: str | None = Field(default=None, description='操作系统')
23+
device: str | None = Field(default=None, description='设备')
24+
msg: str = Field(description='消息')
25+
login_time: datetime = Field(description='登录时间')
2426

2527

2628
class CreateLoginLogParam(LoginLogSchemaBase):
27-
pass
29+
"""创建登录日志参数"""
2830

2931

3032
class UpdateLoginLogParam(LoginLogSchemaBase):
31-
pass
33+
"""更新登录日志参数"""
3234

3335

3436
class GetLoginLogDetail(LoginLogSchemaBase):
37+
"""登录日志详情"""
38+
3539
model_config = ConfigDict(from_attributes=True)
3640

37-
id: int
38-
created_time: datetime
41+
id: int = Field(description='日志 ID')
42+
created_time: datetime = Field(description='创建时间')

backend/app/admin/schema/menu.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,36 @@
99

1010

1111
class MenuSchemaBase(SchemaBase):
12-
title: str
13-
name: str
14-
parent_id: int | None = Field(default=None, description='菜单父级ID')
12+
"""菜单基础模型"""
13+
14+
title: str = Field(description='菜单标题')
15+
name: str = Field(description='菜单名称')
16+
parent_id: int | None = Field(default=None, description='菜单父级 ID')
1517
sort: int = Field(default=0, ge=0, description='排序')
16-
icon: str | None = None
17-
path: str | None = None
18+
icon: str | None = Field(default=None, description='图标')
19+
path: str | None = Field(default=None, description='路由路径')
1820
menu_type: MenuType = Field(default=MenuType.directory, description='菜单类型(0目录 1菜单 2按钮)')
19-
component: str | None = None
20-
perms: str | None = None
21-
status: StatusType = Field(default=StatusType.enable)
22-
display: StatusType = Field(default=StatusType.enable)
23-
cache: StatusType = Field(default=StatusType.enable)
24-
remark: str | None = None
21+
component: str | None = Field(default=None, description='组件路径')
22+
perms: str | None = Field(default=None, description='权限标识')
23+
status: StatusType = Field(default=StatusType.enable, description='状态')
24+
display: StatusType = Field(default=StatusType.enable, description='是否显示')
25+
cache: StatusType = Field(default=StatusType.enable, description='是否缓存')
26+
remark: str | None = Field(default=None, description='备注')
2527

2628

2729
class CreateMenuParam(MenuSchemaBase):
28-
pass
30+
"""创建菜单参数"""
2931

3032

3133
class UpdateMenuParam(MenuSchemaBase):
32-
pass
34+
"""更新菜单参数"""
3335

3436

3537
class GetMenuDetail(MenuSchemaBase):
38+
"""菜单详情"""
39+
3640
model_config = ConfigDict(from_attributes=True)
3741

38-
id: int
39-
created_time: datetime
40-
updated_time: datetime | None = None
42+
id: int = Field(description='菜单 ID')
43+
created_time: datetime = Field(description='创建时间')
44+
updated_time: datetime | None = Field(default=None, description='更新时间')

0 commit comments

Comments
 (0)