.roadhogrc.mock.js 2.2 KB

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