当前位置: 首页 > 工具软件 > Easy Mock > 使用案例 >

easy mock 自定义post请求模拟数据

姬向明
2023-12-01
{
  "code": 0,
  "data": function({
    _req,
    Mock
  }) {
    let i = 0,
      _data = [],
      page = Number(_req.body.page.pageNumber), //当前页数
      pageSize = Number(_req.body.page.pageSize), //每次返回的条数
      len = (1000 - pageSize * (page - 1)) < pageSize ? (1000 - pageSize * (page - 1)) : pageSize;
    let fwzl = _req.body.searchable.xqmc ? _req.body.searchable.xqmc : "丁桥联合新苑";
    for (i; i < len; i++) {
      _data.push(
        Mock.mock({
          "fwzl": fwzl + "@integer(1, 4)" + "-" + "@integer(100, 999)",
          "fwcode": "@integer(8000, 9999)",
          "wxzt": _req.body.searchable.wxzt,
          "syzt": "0",
          "ttsj": "@date(yyyy-MM-dd hh:mm:ss)",
          "gxsj": null
        })
      );
    }
    return _data;
  },
  "message": "成功",
  "ext": null,
  "page": {
    "pageNumber": function({
      _req,
      Mock
    }) {

      return Number(_req.body.page.pageNumber);
    },
    "pageSize": function({
      _req,
      Mock
    }) {

      return Number(_req.body.page.pageSize);
    },
    "totalSize": 2500,
    "totalPageCount": function({
      _req,
      Mock
    }) {

      return Number(_req.body.page.pageNumber);
    }
  }
}

 类似资料: