From 22b22e1187ee1a4d0a03a8eeee8e7f0c0d9b403a Mon Sep 17 00:00:00 2001 From: Backend Developer Date: Tue, 10 Mar 2026 09:54:56 +0000 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E7=AB=AF:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=93=8D=E5=BA=94=E6=A0=BC=E5=BC=8F=E5=B7=A5?= =?UTF-8?q?=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/utils/response.js | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 backend/src/utils/response.js diff --git a/backend/src/utils/response.js b/backend/src/utils/response.js new file mode 100644 index 0000000..cb6874f --- /dev/null +++ b/backend/src/utils/response.js @@ -0,0 +1,36 @@ +// 统一响应格式 +class ApiResponse { + static success(data, message = 'success') { + return { + success: true, + message, + data, + timestamp: new Date().toISOString() + }; + } + + static error(message = 'error', code = 500) { + return { + success: false, + message, + code, + timestamp: new Date().toISOString() + }; + } + + static paginate(data, page, pageSize, total) { + return { + success: true, + data, + pagination: { + page, + pageSize, + total, + totalPages: Math.ceil(total / pageSize) + }, + timestamp: new Date().toISOString() + }; + } +} + +module.exports = ApiResponse;