From ca0c07857e04255765ca6296d1342db7c32cb3f8 Mon Sep 17 00:00:00 2001 From: luozhj33 Date: Thu, 19 Mar 2026 01:25:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A0=87=E5=87=86=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/src/utils/standardResponse.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 back/src/utils/standardResponse.js diff --git a/back/src/utils/standardResponse.js b/back/src/utils/standardResponse.js new file mode 100644 index 0000000..1deb381 --- /dev/null +++ b/back/src/utils/standardResponse.js @@ -0,0 +1,21 @@ +const responseCodes = { + 200: '请求成功', + 400: '请求参数错误', + 401: '未授权,请先登录', + 403: '没有访问权限', + 404: '请求的资源不存在', + 500: '服务器内部错误' +}; + +// 标准响应 +function standardResponse(code, message, data) { + return { + code: code, + message: message ?? responseCodes[code], + data: data + }; +} + +module.exports = { + standardResponse +}; \ No newline at end of file