user.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/login/staff': {
  15. name: 'testName',
  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': async (req, res) => {
  86. const { password, username, type } = req.body;
  87. await waitTime(2000);
  88. if (password === '123456' && username === '蔡频') {
  89. res.send({
  90. code: 0,
  91. data: {
  92. token: ''
  93. },
  94. currentAuthority: 'admin',
  95. });
  96. return;
  97. }
  98. if (password === 'ant.design' && username === 'user') {
  99. res.send({
  100. status: 'ok',
  101. type,
  102. currentAuthority: 'user',
  103. });
  104. return;
  105. }
  106. if (type === 'mobile') {
  107. res.send({
  108. status: 'ok',
  109. type,
  110. currentAuthority: 'admin',
  111. });
  112. return;
  113. }
  114. res.send({
  115. status: 'error',
  116. type,
  117. currentAuthority: 'guest',
  118. });
  119. },
  120. 'POST /api/register': (req, res) => {
  121. res.send({
  122. status: 'ok',
  123. currentAuthority: 'user',
  124. });
  125. },
  126. 'GET /api/500': (req, res) => {
  127. res.status(500).send({
  128. timestamp: 1513932555104,
  129. status: 500,
  130. error: 'error',
  131. message: 'error',
  132. path: '/base/category/list',
  133. });
  134. },
  135. 'GET /api/404': (req, res) => {
  136. res.status(404).send({
  137. timestamp: 1513932643431,
  138. status: 404,
  139. error: 'Not Found',
  140. message: 'No message available',
  141. path: '/base/category/list/2121212',
  142. });
  143. },
  144. 'GET /api/403': (req, res) => {
  145. res.status(403).send({
  146. timestamp: 1513932555104,
  147. status: 403,
  148. error: 'Unauthorized',
  149. message: 'Unauthorized',
  150. path: '/base/category/list',
  151. });
  152. },
  153. 'GET /api/401': (req, res) => {
  154. res.status(401).send({
  155. timestamp: 1513932555104,
  156. status: 401,
  157. error: 'Unauthorized',
  158. message: 'Unauthorized',
  159. path: '/base/category/list',
  160. });
  161. },
  162. 'GET /api/login/captcha': getFakeCaptcha,
  163. };