.umirc.mock.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import mockjs from 'mockjs';
  2. import { getRule, postRule } from './mock/rule';
  3. import { getActivities, getNotice, getFakeList, postFakeList, getFakeCaptcha } from './mock/api';
  4. import { getFakeChartData } from './mock/chart';
  5. import { getProfileBasicData } from './mock/profile';
  6. import { getProfileAdvancedData } from './mock/profile';
  7. import { getNotices } from './mock/notices';
  8. import { getProvince, getCity } from './mock/geographic';
  9. // 是否禁用代理
  10. const noProxy = process.env.NO_PROXY === 'true';
  11. // 代码中会兼容本地 service mock 以及部署站点的静态数据
  12. const proxy = {
  13. // 支持值为 Object 和 Array
  14. 'GET /api/currentUser': {
  15. name: 'Serati Ma',
  16. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
  17. userid: '00000001',
  18. email: 'antdesign@alipay.com',
  19. signature: '海纳百川,有容乃大',
  20. title: '交互专家',
  21. group: '蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED',
  22. tags: [
  23. {
  24. key: '0',
  25. label: '很有想法的',
  26. },
  27. {
  28. key: '1',
  29. label: '专注设计',
  30. },
  31. {
  32. key: '2',
  33. label: '辣~',
  34. },
  35. {
  36. key: '3',
  37. label: '大长腿',
  38. },
  39. {
  40. key: '4',
  41. label: '川妹子',
  42. },
  43. {
  44. key: '5',
  45. label: '海纳百川',
  46. },
  47. ],
  48. notifyCount: 12,
  49. country: 'China',
  50. geographic: {
  51. province: {
  52. label: '浙江省',
  53. key: '330000',
  54. },
  55. city: {
  56. label: '杭州市',
  57. key: '330100',
  58. },
  59. },
  60. address: '西湖区工专路 77 号',
  61. phone: '0752-268888888',
  62. },
  63. // GET POST 可省略
  64. 'GET /api/users': [
  65. {
  66. key: '1',
  67. name: 'John Brown',
  68. age: 32,
  69. address: 'New York No. 1 Lake Park',
  70. },
  71. {
  72. key: '2',
  73. name: 'Jim Green',
  74. age: 42,
  75. address: 'London No. 1 Lake Park',
  76. },
  77. {
  78. key: '3',
  79. name: 'Joe Black',
  80. age: 32,
  81. address: 'Sidney No. 1 Lake Park',
  82. },
  83. ],
  84. 'GET /api/project/notice': getNotice,
  85. 'GET /api/activities': getActivities,
  86. 'GET /api/rule': getRule,
  87. 'POST /api/rule': postRule,
  88. 'POST /api/forms': (req, res) => {
  89. res.send({ message: 'Ok' });
  90. },
  91. 'GET /api/tags': mockjs.mock({
  92. 'list|100': [{ name: '@city', 'value|1-100': 150, 'type|0-2': 1 }],
  93. }),
  94. 'GET /api/fake_list': getFakeList,
  95. 'POST /api/fake_list': postFakeList,
  96. 'GET /api/fake_chart_data': getFakeChartData,
  97. 'GET /api/profile/basic': getProfileBasicData,
  98. 'GET /api/profile/advanced': getProfileAdvancedData,
  99. 'POST /api/login/account': (req, res) => {
  100. const { password, userName, type } = req.body;
  101. if (password === '888888' && userName === 'admin') {
  102. res.send({
  103. status: 'ok',
  104. type,
  105. currentAuthority: 'admin',
  106. });
  107. return;
  108. }
  109. if (password === '123456' && userName === 'user') {
  110. res.send({
  111. status: 'ok',
  112. type,
  113. currentAuthority: 'user',
  114. });
  115. return;
  116. }
  117. res.send({
  118. status: 'error',
  119. type,
  120. currentAuthority: 'guest',
  121. });
  122. },
  123. 'POST /api/register': (req, res) => {
  124. res.send({ status: 'ok', currentAuthority: 'user' });
  125. },
  126. 'GET /api/notices': getNotices,
  127. 'GET /api/500': (req, res) => {
  128. res.status(500).send({
  129. timestamp: 1513932555104,
  130. status: 500,
  131. error: 'error',
  132. message: 'error',
  133. path: '/base/category/list',
  134. });
  135. },
  136. 'GET /api/404': (req, res) => {
  137. res.status(404).send({
  138. timestamp: 1513932643431,
  139. status: 404,
  140. error: 'Not Found',
  141. message: 'No message available',
  142. path: '/base/category/list/2121212',
  143. });
  144. },
  145. 'GET /api/403': (req, res) => {
  146. res.status(403).send({
  147. timestamp: 1513932555104,
  148. status: 403,
  149. error: 'Unauthorized',
  150. message: 'Unauthorized',
  151. path: '/base/category/list',
  152. });
  153. },
  154. 'GET /api/401': (req, res) => {
  155. res.status(401).send({
  156. timestamp: 1513932555104,
  157. status: 401,
  158. error: 'Unauthorized',
  159. message: 'Unauthorized',
  160. path: '/base/category/list',
  161. });
  162. },
  163. 'GET /api/geographic/province': getProvince,
  164. 'GET /api/geographic/city/:province': getCity,
  165. 'GET /api/captcha': getFakeCaptcha,
  166. };
  167. export default (noProxy ? {} : proxy);