user.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import { Request, Response } from 'express';
  2. const waitTime = (time: number = 100) => {
  3. return new Promise((resolve) => {
  4. setTimeout(() => {
  5. resolve(true);
  6. }, time);
  7. });
  8. };
  9. async function getFakeCaptcha(req: Request, res: Response) {
  10. await waitTime(2000);
  11. return res.json('captcha-xxx');
  12. }
  13. // 代码中会兼容本地 service mock 以及部署站点的静态数据
  14. export default {
  15. // 支持值为 Object 和 Array
  16. 'GET /api/currentUser': {
  17. name: 'Serati Ma',
  18. avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
  19. userid: '00000001',
  20. email: 'antdesign@alipay.com',
  21. signature: '海纳百川,有容乃大',
  22. title: '交互专家',
  23. group: '蚂蚁集团-某某某事业群-某某平台部-某某技术部-UED',
  24. tags: [
  25. {
  26. key: '0',
  27. label: '很有想法的',
  28. },
  29. {
  30. key: '1',
  31. label: '专注设计',
  32. },
  33. {
  34. key: '2',
  35. label: '辣~',
  36. },
  37. {
  38. key: '3',
  39. label: '大长腿',
  40. },
  41. {
  42. key: '4',
  43. label: '川妹子',
  44. },
  45. {
  46. key: '5',
  47. label: '海纳百川',
  48. },
  49. ],
  50. notifyCount: 12,
  51. unreadCount: 11,
  52. country: 'China',
  53. geographic: {
  54. province: {
  55. label: '浙江省',
  56. key: '330000',
  57. },
  58. city: {
  59. label: '杭州市',
  60. key: '330100',
  61. },
  62. },
  63. address: '西湖区工专路 77 号',
  64. phone: '0752-268888888',
  65. },
  66. // GET POST 可省略
  67. 'GET /api/users': [
  68. {
  69. key: '1',
  70. name: 'John Brown',
  71. age: 32,
  72. address: 'New York No. 1 Lake Park',
  73. },
  74. {
  75. key: '2',
  76. name: 'Jim Green',
  77. age: 42,
  78. address: 'London No. 1 Lake Park',
  79. },
  80. {
  81. key: '3',
  82. name: 'Joe Black',
  83. age: 32,
  84. address: 'Sidney No. 1 Lake Park',
  85. },
  86. ],
  87. 'POST /api/login/account': async (req: Request, res: Response) => {
  88. const { password, userName, type } = req.body;
  89. await waitTime(2000);
  90. if (password === 'ant.design' && userName === 'admin') {
  91. res.send({
  92. status: 'ok',
  93. type,
  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: Request, res: Response) => {
  121. res.send({ status: 'ok', currentAuthority: 'user' });
  122. },
  123. 'GET /api/500': (req: Request, res: Response) => {
  124. res.status(500).send({
  125. timestamp: 1513932555104,
  126. status: 500,
  127. error: 'error',
  128. message: 'error',
  129. path: '/base/category/list',
  130. });
  131. },
  132. 'GET /api/404': (req: Request, res: Response) => {
  133. res.status(404).send({
  134. timestamp: 1513932643431,
  135. status: 404,
  136. error: 'Not Found',
  137. message: 'No message available',
  138. path: '/base/category/list/2121212',
  139. });
  140. },
  141. 'GET /api/403': (req: Request, res: Response) => {
  142. res.status(403).send({
  143. timestamp: 1513932555104,
  144. status: 403,
  145. error: 'Unauthorized',
  146. message: 'Unauthorized',
  147. path: '/base/category/list',
  148. });
  149. },
  150. 'GET /api/401': (req: Request, res: Response) => {
  151. res.status(401).send({
  152. timestamp: 1513932555104,
  153. status: 401,
  154. error: 'Unauthorized',
  155. message: 'Unauthorized',
  156. path: '/base/category/list',
  157. });
  158. },
  159. 'GET /api/login/captcha': getFakeCaptcha,
  160. };