37 lines
672 B
JavaScript
37 lines
672 B
JavaScript
// 统一响应格式
|
|
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;
|