.roadhogrc.mock.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import mockjs from 'mockjs';
  2. import { getRule, postRule } from './mock/rule';
  3. import { getActivities, getNotice, getFakeList } from './mock/api';
  4. import { getFakeChartData } from './mock/chart';
  5. import { imgMap } from './mock/utils';
  6. import { getProfileData } from './mock/profile';
  7. import { getNotices } from './mock/notices';
  8. import { format, delay } from 'roadhog-api-doc';
  9. // 代码中会兼容本地 service mock 以及部署站点的静态数据
  10. const proxy = {
  11. // 支持值为 Object 和 Array
  12. 'GET /api/currentUser': {
  13. $desc: "获取当前用户接口",
  14. $params: {
  15. pageSize: {
  16. desc: '分页',
  17. exp: 2,
  18. },
  19. },
  20. $body: {
  21. name: 'momo.zxy',
  22. avatar: imgMap.user,
  23. userid: '00000001',
  24. notifyCount: 12,
  25. },
  26. },
  27. // GET POST 可省略
  28. 'GET /api/users': [{
  29. key: '1',
  30. name: 'John Brown',
  31. age: 32,
  32. address: 'New York No. 1 Lake Park',
  33. }, {
  34. key: '2',
  35. name: 'Jim Green',
  36. age: 42,
  37. address: 'London No. 1 Lake Park',
  38. }, {
  39. key: '3',
  40. name: 'Joe Black',
  41. age: 32,
  42. address: 'Sidney No. 1 Lake Park',
  43. }],
  44. 'GET /api/project/notice': getNotice,
  45. 'GET /api/activities': getActivities,
  46. 'GET /api/rule': getRule,
  47. 'POST /api/rule': {
  48. $params: {
  49. pageSize: {
  50. desc: '分页',
  51. exp: 2,
  52. },
  53. },
  54. $body: postRule,
  55. },
  56. 'POST /api/forms': (req, res) => {
  57. res.send('Ok');
  58. },
  59. 'GET /api/tags': mockjs.mock({
  60. 'list|100': [{ name: '@city', 'value|1-100': 50, 'type|0-2': 1 }]
  61. }),
  62. 'GET /api/fake_list': getFakeList,
  63. 'GET /api/fake_chart_data': getFakeChartData,
  64. 'GET /api/profile': getProfileData,
  65. 'POST /api/login/account': (req, res) => {
  66. res.send({ status: 'error', type: 'account' });
  67. },
  68. 'POST /api/login/mobile': (req, res) => {
  69. res.send({ status: 'ok', type: 'mobile' });
  70. },
  71. 'POST /api/register': (req, res) => {
  72. res.send({ status: 'ok' });
  73. },
  74. 'GET /api/notices': getNotices,
  75. };
  76. export default delay(proxy, 1000);