user.ts 3.2 KB

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