From 2f122d0a96e658d2250196d3115f009da214b14a Mon Sep 17 00:00:00 2001 From: wangxiaogang <1433729587@qq.com> Date: Mon, 8 Jun 2026 11:30:58 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=20DEV.md=20=E2=80=94?= =?UTF-8?q?=20=E5=90=8E=E7=AB=AF=20API=20=E5=93=8D=E5=BA=94=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 统一响应格式 { code: 0, data: ... } - 错误码规范说明 --- DEV.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/DEV.md b/DEV.md index 85d190d..8c6ebd3 100644 --- a/DEV.md +++ b/DEV.md @@ -52,6 +52,29 @@ request('/config', { method: 'PUT', data }) **原因**:`request` 函数签名是 `request(options: RequestOptions): Promise`,第一个参数是 options 对象,不支持分开传 url 和 options。 +### 后端 API 响应格式 + +**所有后端路由必须返回统一格式**: + +```typescript +// 成功 +res.json({ code: 0, data: ... }) + +// 失败 +res.status(400).json({ code: 40001, message: '错误信息' }) +res.status(403).json({ code: 40300, message: '无权限' }) +res.status(500).json({ code: 50000, message: '服务器错误' }) +``` + +**错误码规范**: +- `0` — 成功 +- `40001` — 参数错误 +- `40300` — 权限不足 +- `40400` — 资源不存在 +- `50000` — 服务器错误 + +**原因**:前端 `request` 函数检查 `data.code === 0` 判断成功,不返回标准格式会导致前端误判为失败。 + ### 页面数据加载模式 ```typescript