user.ts 3.5 KB

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