util.js 394 B

12345678910111213141516171819
  1. /**
  2. * 包裹 api 的返回值
  3. * @param {*} param0
  4. * @param {object} param0.data - 原始数据
  5. * @param {number|string} [param0.code=200] - http状态码
  6. * @returns
  7. */
  8. function wrapApiData({data, code = 200}) {
  9. code = String(code)
  10. return {
  11. code,
  12. success: Boolean(code.match(/^[2]/)), // 如果状态码以2开头则为 true
  13. data,
  14. }
  15. }
  16. module.exports = {
  17. wrapApiData,
  18. }