utils.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * @Author: helin3
  3. * @Date: 2024-03-25 13:47:19
  4. * @LastEditors: helin3
  5. * @LastEditTime: 2024-03-27 15:43:58
  6. * @Description: mock 工具函数
  7. */
  8. import { RESP_CODE } from '@/config/constant/app.data.respCode.js';
  9. export { defineMock, defineMockData } from 'vite-plugin-mock-dev-server';
  10. export { backend } from '@/config/constant/app.data.service.js';
  11. /**
  12. * 生成一个标准的响应对象。
  13. * @param {Object} data - 响应携带的数据。
  14. * @param {number} code - 响应的状态码。
  15. * @param {string} msg - 响应的消息。
  16. * @returns {Object} 返回一个包含数据、状态码和消息的响应对象。
  17. */
  18. export function normalResponse(data, code = RESP_CODE.SUCCESS, msg = 'ok') {
  19. // 构建并返回响应对象
  20. const response = {
  21. code,
  22. message: msg,
  23. data,
  24. };
  25. return response;
  26. }
  27. /**
  28. * 生成分页响应对象
  29. * @param {Object[]} data - 分页数据中的内容数组
  30. * @param {number} total - 总数据量
  31. * @param {number} code - 响应状态码
  32. * @param {string} msg - 响应信息
  33. * @returns {Object} 返回一个包含数据、总数、状态码和信息的响应对象
  34. */
  35. export function paginationReponse(data, total, code = RESP_CODE.SUCCESS, msg = 'ok') {
  36. return {
  37. data,
  38. total,
  39. code,
  40. message: msg,
  41. };
  42. }