user.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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: 'Jack Ma',
  16. avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
  17. userid: '007',
  18. email: 'antdesign@alipay.com',
  19. signature: '自我驱动',
  20. title: '资深程序员',
  21. group: 'FE',
  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. notifyCount: 12,
  37. unreadCount: 11,
  38. country: 'China',
  39. geographic: {
  40. province: {
  41. label: '浙江省',
  42. key: '330000',
  43. },
  44. city: {
  45. label: '杭州市',
  46. key: '330100',
  47. },
  48. },
  49. address: '西湖区工专路 77 号',
  50. phone: '0752-268888888',
  51. },
  52. // GET POST 可省略
  53. 'GET /api/users': [
  54. {
  55. key: '1',
  56. name: 'John Brown',
  57. age: 32,
  58. address: 'New York No. 1 Lake Park',
  59. },
  60. {
  61. key: '2',
  62. name: 'Jim Green',
  63. age: 42,
  64. address: 'London No. 1 Lake Park',
  65. },
  66. {
  67. key: '3',
  68. name: 'Joe Black',
  69. age: 32,
  70. address: 'Sidney No. 1 Lake Park',
  71. },
  72. ],
  73. 'POST /api/login/account': async (req, res) => {
  74. const { password, userName, type } = req.body;
  75. await waitTime(2000);
  76. if (password === 'ant.design' && userName === 'admin') {
  77. res.send({
  78. status: 'ok',
  79. type,
  80. currentAuthority: 'admin',
  81. });
  82. return;
  83. }
  84. if (password === 'ant.design' && userName === 'user') {
  85. res.send({
  86. status: 'ok',
  87. type,
  88. currentAuthority: 'user',
  89. });
  90. return;
  91. }
  92. if (type === 'mobile') {
  93. res.send({
  94. status: 'ok',
  95. type,
  96. currentAuthority: 'admin',
  97. });
  98. return;
  99. }
  100. res.send({
  101. status: 'error',
  102. type,
  103. currentAuthority: 'guest',
  104. });
  105. },
  106. 'POST /api/register': (req, res) => {
  107. res.send({
  108. status: 'ok',
  109. currentAuthority: 'user',
  110. });
  111. },
  112. 'GET /api/500': (req, res) => {
  113. res.status(500).send({
  114. timestamp: 1513932555104,
  115. status: 500,
  116. error: 'error',
  117. message: 'error',
  118. path: '/base/category/list',
  119. });
  120. },
  121. 'GET /api/404': (req, res) => {
  122. res.status(404).send({
  123. timestamp: 1513932643431,
  124. status: 404,
  125. error: 'Not Found',
  126. message: 'No message available',
  127. path: '/base/category/list/2121212',
  128. });
  129. },
  130. 'GET /api/403': (req, res) => {
  131. res.status(403).send({
  132. timestamp: 1513932555104,
  133. status: 403,
  134. error: 'Unauthorized',
  135. message: 'Unauthorized',
  136. path: '/base/category/list',
  137. });
  138. },
  139. 'GET /api/401': (req, res) => {
  140. res.status(401).send({
  141. timestamp: 1513932555104,
  142. status: 401,
  143. error: 'Unauthorized',
  144. message: 'Unauthorized',
  145. path: '/base/category/list',
  146. });
  147. },
  148. 'GET /api/login/captcha': getFakeCaptcha,
  149. };