YAPI中模拟生成时间序列数据

784 阅读1分钟

YAPI接口编辑中的返回数据设置中先使用mockjs模拟出返回的基本数组

{
 "data|1000": [
   [
     null,
     "@float(10,60)"
   ]
 ]
}

然后在高级mock-脚本中添加如下脚本


const interval =10
const startDate=new Date('2019-04-11 10:20:30')
Date.prototype.stringify = function(){ return  JSON.stringify(new Date(this -1000*60*this.getTimezoneOffset() )).replace(/T|"|\..*/g," ").trim()}
mockJson.data.map((x,i)=> x[0]= new Date(startDate - 1000*i*-Random.integer(5, 10) ).stringify() )