/* * @Author: helin3 * @Date: 2024-03-25 13:47:19 * @LastEditors: helin3 * @LastEditTime: 2024-03-27 15:43:58 * @Description: mock 工具函数 */ import { RESP_CODE } from '@/config/constant/app.data.respCode.js'; export { defineMock, defineMockData } from 'vite-plugin-mock-dev-server'; export { backend } from '@/config/constant/app.data.service.js'; /** * 生成一个标准的响应对象。 * @param {Object} data - 响应携带的数据。 * @param {number} code - 响应的状态码。 * @param {string} msg - 响应的消息。 * @returns {Object} 返回一个包含数据、状态码和消息的响应对象。 */ export function normalResponse(data, code = RESP_CODE.SUCCESS, msg = 'ok') { // 构建并返回响应对象 const response = { code, message: msg, data, }; return response; } /** * 生成分页响应对象 * @param {Object[]} data - 分页数据中的内容数组 * @param {number} total - 总数据量 * @param {number} code - 响应状态码 * @param {string} msg - 响应信息 * @returns {Object} 返回一个包含数据、总数、状态码和信息的响应对象 */ export function paginationReponse(data, total, code = RESP_CODE.SUCCESS, msg = 'ok') { return { data, total, code, message: msg, }; }