user.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. // code: 0,
  16. // data: {
  17. // "staffId": "NcDlEdO0O0Oi",
  18. // "categoryId": "McTlIdO0O0Oi",
  19. // "username": "蔡频",
  20. // "categoryTitle": "总部",
  21. // "avatar": "/global/avatar/avatar_41",
  22. // "qq": "2147422",
  23. // "qualifications": "大专"
  24. // }
  25. // },
  26. // GET POST 可省略
  27. 'GET /api/users': [
  28. {
  29. key: '1',
  30. name: 'John Brown',
  31. age: 32,
  32. address: 'New York No. 1 Lake Park'
  33. },
  34. {
  35. key: '2',
  36. name: 'Jim Green',
  37. age: 42,
  38. address: 'London No. 1 Lake Park'
  39. },
  40. {
  41. key: '3',
  42. name: 'Joe Black',
  43. age: 32,
  44. address: 'Sidney No. 1 Lake Park'
  45. }
  46. ],
  47. 'POST /api/login': async (req, res) => {
  48. const { password, username, type } = req.body
  49. await waitTime(2000)
  50. if (password === '123456' && username === '蔡频') {
  51. res.send({
  52. code: 0,
  53. data: {
  54. token:
  55. 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdGFmZklkIjoiTmNEbEVkTzBPME9pIiwiY2F0ZWdvcnlJZCI6Ik1jVGxJZE8wTzBPaSIsInVzZXJuYW1lIjoiXHU4NTIxXHU5ODkxIiwiY2F0ZWdvcnlUaXRsZSI6Ilx1NjAzYlx1OTBlOCIsImF2YXRhciI6IlwvZ2xvYmFsXC9hdmF0YXJcL2F2YXRhcl80MSIsInFxIjoiMjE0NzQyMiIsInF1YWxpZmljYXRpb25zIjoiXHU1OTI3XHU0ZTEzIiwiYXVkIjoiIiwiZXhwIjoxNjEyODQyNDg3LCJpYXQiOjE2MTI3NTYwODcsImlzcyI6IiIsImp0aSI6IjgyNWRmNTBjNjg3NDQ0ZDJhZDA1ZDNiNzhhOGE0YmVhIiwibmJmIjoxNjEyNzU2MDg3LCJzdWIiOiIifQ.Iexq-ep6YiVM61nEoCDSd72NS-Qh63Ll5vAhlxTgVEo'
  56. },
  57. currentAuthority: 'admin'
  58. })
  59. return
  60. }
  61. if (password === 'ant.design' && username === 'user') {
  62. res.send({
  63. status: 'ok',
  64. type,
  65. currentAuthority: 'user'
  66. })
  67. return
  68. }
  69. if (type === 'mobile') {
  70. res.send({
  71. status: 'ok',
  72. type,
  73. currentAuthority: 'admin'
  74. })
  75. return
  76. }
  77. res.send({
  78. status: 'error',
  79. type,
  80. currentAuthority: 'guest'
  81. })
  82. },
  83. 'POST /api/register': (req, res) => {
  84. res.send({
  85. status: 'ok',
  86. currentAuthority: 'user'
  87. })
  88. },
  89. 'GET /api/500': (req, res) => {
  90. res.status(500).send({
  91. timestamp: 1513932555104,
  92. status: 500,
  93. error: 'error',
  94. message: 'error',
  95. path: '/base/category/list'
  96. })
  97. },
  98. 'GET /api/404': (req, res) => {
  99. res.status(404).send({
  100. timestamp: 1513932643431,
  101. status: 404,
  102. error: 'Not Found',
  103. message: 'No message available',
  104. path: '/base/category/list/2121212'
  105. })
  106. },
  107. 'GET /api/403': (req, res) => {
  108. res.status(403).send({
  109. timestamp: 1513932555104,
  110. status: 403,
  111. error: 'Unauthorized',
  112. message: 'Unauthorized',
  113. path: '/base/category/list'
  114. })
  115. },
  116. 'GET /api/401': (req, res) => {
  117. res.status(401).send({
  118. timestamp: 1513932555104,
  119. status: 401,
  120. error: 'Unauthorized',
  121. message: 'Unauthorized',
  122. path: '/base/category/list'
  123. })
  124. },
  125. 'GET /api/login/captcha': getFakeCaptcha
  126. }