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;