12345678910111213141516171819 |
- /**
- * 包裹 api 的返回值
- * @param {*} param0
- * @param {object} param0.data - 原始数据
- * @param {number|string} [param0.code=200] - http状态码
- * @returns
- */
- function wrapApiData({data, code = 200}) {
- code = String(code)
- return {
- code,
- success: Boolean(code.match(/^[2]/)), // 如果状态码以2开头则为 true
- data,
- }
- }
- module.exports = {
- wrapApiData,
- }
|