How to use mockjs - 10 common examples

To help you get started, we’ve selected a few mockjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tingtingtinghuang / GymBook2.0-frontend / GymBook / mock / server / app.js View on Github external
val.forEach(reqData => {
      if (reqData.regexp) {
        if (!new RegExp(reqData.url).test(req.originalUrl)) {
          return false;
        }
      } else if (req.originalUrl.indexOf(reqData.url) !== 0) {
        return false;
      }

      var apiRes = reqData.res;
      data = reqData.mock ? mock.mock(apiRes) : apiRes;
      delay = reqData.delay || 0;
      // mock.mock(reqData.url,reqData.res);
      return true;

    })
  })
github snowlyg / IrisAdminApi / www / mock / index.js View on Github external
return function(options) {
      let result = null
      if (respond instanceof Function) {
        const { body, type, url } = options
        // https://expressjs.com/en/4x/api.html#req
        result = respond({
          method: type,
          body: JSON.parse(body),
          query: param2Obj(url)
        })
      } else {
        result = respond
      }
      return Mock.mock(result)
    }
  }
github baidu / NoahV / components / visual / demo / service / mock / mdtrend.js View on Github external
/* eslint-disable */
const Mock = require('mockjs');

const trend = function() {
    return {
        "data": {
            configure: '{"title":"趋势图标题Conf","data":[{"namespace":["forDemoNamespace1","forDemoNamespace2"],"product":"noahEE","monitoringType":"instance","metric":"#{metric1}/#{metric2}","statistics":"avg","period":5,"name":"name1","contrast":["1d","1w"]},{"namespace":["forDemoNamespace3","forDemoNamespace4"],"product":"noahEE","monitoringType":"instance","metric":"#{metric3}","statistics":"avg","period":5,"name":"name2","contrast":["1d"]}],"style":{"displayType":"line","unit":"个","nullPointMode":"zero","threshold":99},"link":"http://www.baidu.com","timeType":"relative","time":"before(2h)"}'
        },
        success: true
    };
}
 
Mock.mock('/mock/mdtrend', 'post', trend);
github baidu / NoahV / components / visual / demo / service / mock / mdreport.js View on Github external
/* eslint-disable */
const Mock = require('mockjs');

const report = function() {
    return {
    	"data": {
    		"title": "资源报表conf",
        	configure : '{"title":"资源报表conf","data":{"namespace":["forDemoNamespace"],"comments":"说明","columns":[{"source":"origin","metric":"#{metric1}-#{metric2}","statistics":"sum","group":"","header":"数据1","alias":"alias3","unit":"%","decimals":3,"threshold":[[0,90,"#ff0000"],[90,95,"#0000ff"],[99,100,"green"]],"timeType":"relative","time":"before(2h)","total":"sum","use":true,"offset":"-1d"},{"source":"origin","metric":"#{metric1}-#{metric2}","statistics":"sum","group":"综合数据","header":"数据1","alias":"alias1","unit":"%","decimals":3,"threshold":[[0,90,"#ff0000"],[90,95,"#0000ff"],[99,100,"green"]],"timeType":"relative","time":"before(2h)","total":null,"use":true,"offset":"-1d"},{"source":"origin","group":"综合数据","header":"数据2","alias":"alias2","metric":"#{metric1}-#{metric2}","unit":"%","decimals":3,"threshold":[[0,90,"#ff0000"],[90,95,"#0000ff"],[99,100,"green"]],"total":null,"use":true},{"source":"column","group":"综合数据","header":"列计算","metric":"#{alias3}+#{alias2}","unit":"","decimals":3,"threshold":[[null,90,"red"],[90,null,"yellow"],[99,100,"green"]],"total":"avg","use":true}]},"link":"http://www.baidu.com"}'
    	},
    	success: true
    };
}
 
Mock.mock('/mock/mdreport', 'post', report);
github baidu / NoahV / components / visual / demo / service / mock / circle.js View on Github external
/* eslint-disable */
const Mock = require('mockjs');
const circle = function() {
    return {
        data: {
            configure : '{"title":"仪表图配置path","data":[{"namespace":["forDemoNamespace"],"metric":"#{metric1}/#{metric2}","statistics":"avg"}],"style":{"decimals":4,"unit":"%","max":100,"min":0,"threshold":[[90,99,"yellow"],[0,90,"red"],[99,99.99,"green"]]},"link":"http://www.baidu.com","timeType":"fixed","time":"before(2h)"}',
            title: "仪表图配置path"
        },
        success: true
    };
}
Mock.mock('/mock/circle', 'post', circle);
github baidu / NoahV / components / visual / demo / service / mock / billboard.js View on Github external
/* eslint-disable */
const Mock = require('mockjs');
const billboard = function() {
    return {
        data: {
            configure : '{"title":"面板配置path","data":[{"namespace":["forDemoNamespace1"],"metric":"#{metric1}/#{metric2}","statistics":"avg","name":"name3","unit":"%","decimals":4},{"namespace":["forDemoNamespace2"],"metric":"#{metric3}","statistics":"avg","name":"name4","unit":"%","decimals":4}],"link":"http://www.baidu.com","timeType":"relative","time":"before(2h)"}',
            title: "面板配置path"
        },
        success: true
    };
};
Mock.mock('/mock/billboard', 'post', billboard);
github bluekvirus / Stage.js / tools / devserver / export.js View on Github external
_.each(walk(path.join(__dirname, 'data'), program.data), function(data, index){
	var temp = require(data),
		relative = path.relative(path.join(__dirname, 'data'), data);//take out the relative
	//check whether mock data or not
	if( path.extname(relative) === '.js' ){//mock js file
		//replace .mock.js with .json
		fs.writeFile(path.join(program.data, relative.replace(/(\.mock\.js)/, '.json')), JSON.stringify(Mock.mock(temp), null, '\t'), function(err){
			if(err){
				return console.log(err);
			}
			console.log('[', 'exported'.green, '-', 'mock', ']', data);
		});
	}else{
		fs.writeFile(path.join(program.data, relative), JSON.stringify(temp, null, '\t'), function(err){
			if(err){
				return console.log(err);
			}
			console.log('[', 'exported'.green, '-', 'copy'.grey, ']', data);
		});
	}
});
github snowlyg / IrisAdminApi / www / mock / mock-server.js View on Github external
response(req, res) {
      console.log('request invoke:' + req.path)
      res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond))
    }
  }
github TYRMars / ES6-StepPitGuide / gulp_es6 / server / routes / index.js View on Github external
router.get('/get/opencode', function (req, res, next) {
	var issue=makeIssue().issue;
	var data=mockjs.mock({
		'data': [/[1-3]/,/[4-5]/,/[6-7]/,/[8-9]/,/1[0-1]/]
	}).data;
	res.json({
		issue:issue,
		data:data
	})
});
github dad-skyrocket / dad_management / dad-management-client / src / mock / application.js View on Github external
status2 () {
                return Mock.mock({
                    'data|1': [
                        'active',
                        'pending',
                        'paused',
                    ],
                }).data
            },
            platform () {

mockjs

生成随机数据 & 拦截 Ajax 请求

Unrecognized
Latest version published 5 years ago

Package Health Score

38 / 100
Full package analysis

Popular mockjs functions