user.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. const waitTime = (time = 100) => {
  2. return new Promise((resolve) => {
  3. setTimeout(() => {
  4. resolve(true);
  5. }, time);
  6. });
  7. };
  8. async function getFakeCaptcha(req, res) {
  9. await waitTime(2000);
  10. return res.json('captcha-xxx');
  11. } // 代码中会兼容本地 service mock 以及部署站点的静态数据
  12. export default {
  13. // 支持值为 Object 和 Array
  14. 'GET /api/currentUser': {
  15. name: 'Serati Ma',
  16. avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/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. unreadCount: 11,
  50. country: 'China',
  51. geographic: {
  52. province: {
  53. label: '浙江省',
  54. key: '330000',
  55. },
  56. city: {
  57. label: '杭州市',
  58. key: '330100',
  59. },
  60. },
  61. address: '西湖区工专路 77 号',
  62. phone: '0752-268888888',
  63. },
  64. // GET POST 可省略
  65. 'GET /api/users': [
  66. {
  67. key: '1',
  68. name: 'John Brown',
  69. age: 32,
  70. address: 'New York No. 1 Lake Park',
  71. },
  72. {
  73. key: '2',
  74. name: 'Jim Green',
  75. age: 42,
  76. address: 'London No. 1 Lake Park',
  77. },
  78. {
  79. key: '3',
  80. name: 'Joe Black',
  81. age: 32,
  82. address: 'Sidney No. 1 Lake Park',
  83. },
  84. ],
  85. 'POST /api/login/account': async (req, res) => {
  86. const { password, userName, type } = req.body;
  87. await waitTime(2000);
  88. if (password === 'ant.design' && userName === 'admin') {
  89. res.send({
  90. status: 'ok',
  91. type,
  92. currentAuthority: 'admin',
  93. });
  94. return;
  95. }
  96. if (password === 'ant.design' && userName === 'user') {
  97. res.send({
  98. status: 'ok',
  99. type,
  100. currentAuthority: 'user',
  101. });
  102. return;
  103. }
  104. if (type === 'mobile') {
  105. res.send({
  106. status: 'ok',
  107. type,
  108. currentAuthority: 'admin',
  109. });
  110. return;
  111. }
  112. res.send({
  113. status: 'error',
  114. type,
  115. currentAuthority: 'guest',
  116. });
  117. },
  118. 'POST /api/register': (req, res) => {
  119. res.send({
  120. status: 'ok',
  121. currentAuthority: 'user',
  122. });
  123. },
  124. 'GET /api/500': (req, res) => {
  125. res.status(500).send({
  126. timestamp: 1513932555104,
  127. status: 500,
  128. error: 'error',
  129. message: 'error',
  130. path: '/base/category/list',
  131. });
  132. },
  133. 'GET /api/404': (req, res) => {
  134. res.status(404).send({
  135. timestamp: 1513932643431,
  136. status: 404,
  137. error: 'Not Found',
  138. message: 'No message available',
  139. path: '/base/category/list/2121212',
  140. });
  141. },
  142. 'GET /api/403': (req, res) => {
  143. res.status(403).send({
  144. timestamp: 1513932555104,
  145. status: 403,
  146. error: 'Unauthorized',
  147. message: 'Unauthorized',
  148. path: '/base/category/list',
  149. });
  150. },
  151. 'GET /api/401': (req, res) => {
  152. res.status(401).send({
  153. timestamp: 1513932555104,
  154. status: 401,
  155. error: 'Unauthorized',
  156. message: 'Unauthorized',
  157. path: '/base/category/list',
  158. });
  159. },
  160. 'GET /api/login/captcha': getFakeCaptcha,
  161. };