632891e6e5
v-form 保存前 validate;validation_errors_zh 翻译 Pydantic msg;value 数字 coerce。 Co-authored-by: Cursor <cursoragent@cursor.com>
33 lines
1002 B
Markdown
33 lines
1002 B
Markdown
# 设置页表单校验与 API 422 中文校验
|
||
|
||
**日期**:2026-06-08
|
||
|
||
## 变更摘要
|
||
|
||
1. 设置页「系统设置」包在 `v-form` 内,保存前 `validate()`,连接池范围 1–1000。
|
||
2. 全局 422:`validation_errors_zh.py` 将 Pydantic 默认英文 `msg` 译为中文。
|
||
3. `SettingUpdatePayload.value` 增加 before 校验,数字自动转字符串(双保险)。
|
||
|
||
## 动机
|
||
|
||
- 保存设置不跑前端 rules,空值/超范围仍提交。
|
||
- 用户可见 `Input should be a valid string` 等英文校验。
|
||
|
||
## 涉及文件
|
||
|
||
- `frontend/src/pages/SettingsPage.vue`
|
||
- `server/utils/validation_errors_zh.py`(新)
|
||
- `server/main.py` — 422 handler
|
||
- `server/api/schemas.py` — SettingUpdatePayload
|
||
- `tests/test_validation_errors_zh.py`
|
||
|
||
## 迁移 / 重启
|
||
|
||
后端需重启/部署;前端构建部署。
|
||
|
||
## 验证
|
||
|
||
- 设置页空连接池点保存 → 前端提示,无请求
|
||
- `pytest tests/test_validation_errors_zh.py`
|
||
- PUT settings 传 `{value: 160}` → 200(coerce)
|