You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
984 B

3 years ago
  1. 'use strict';
  2. var Mock = require('mockjs');
  3. const Controller = require('egg').Controller;
  4. class HomeController extends Controller {
  5. async index() {
  6. const { ctx } = this;
  7. ctx.body = 'hi, egg';
  8. }
  9. async mock() {
  10. const { ctx } = this;
  11. var data = '';
  12. var template = ctx.request.body.template ;
  13. /*
  14. template = {
  15. 'list|20':[{
  16. 'id|+1':1,
  17. 'serial_number|1-100':1,
  18. 'warn_number|1-100':1,
  19. 'warn_name|1':['流水线编排服务异常','磁盘占用超过阈值'],
  20. 'warn_level|1':['紧急','重要'],
  21. 'warn_detail':'环境IP:127.0.0.1,服务名称:XX',
  22. 'create_time':'@date("yyyy-MM-dd")',
  23. 'finish_time':'@date("yyyy-MM-dd")',
  24. 'contact|4':'abc'
  25. }]
  26. };
  27. */
  28. try{
  29. data =Mock.mock(JSON.parse(template));
  30. }catch(e){
  31. data = '为了服务器安全,只允许符合json语法的字符串'
  32. }
  33. ctx.body = data;
  34. }
  35. }
  36. module.exports = HomeController;