user.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. const tokens = {
  2. admin: {
  3. token: 'admin-token'
  4. },
  5. editor: {
  6. token: 'editor-token'
  7. }
  8. };
  9. const users = {
  10. 'admin-token': {
  11. roles: ['admin'],
  12. introduction: 'I am a super administrator',
  13. avatar: 'https://picsum.photos/id/237/200/300',
  14. name: 'Super Admin'
  15. },
  16. 'editor-token': {
  17. roles: ['editor'],
  18. introduction: 'I am an editor',
  19. avatar: 'https://picsum.photos/id/247/200/300',
  20. name: 'Normal Editor'
  21. }
  22. };
  23. module.exports = [
  24. // user login
  25. {
  26. url: '/vue-admin-template/user/login',
  27. type: 'post',
  28. response: config => {
  29. const { username } = config.body;
  30. const token = tokens[username];
  31. // mock error
  32. if (!token) {
  33. return {
  34. code: 60204,
  35. message: 'Account and password are incorrect.'
  36. };
  37. }
  38. return {
  39. code: 20000,
  40. data: token
  41. };
  42. }
  43. },
  44. // get user info
  45. {
  46. url: '/vue-admin-template/user/info.*',
  47. type: 'get',
  48. response: config => {
  49. const { token } = config.query;
  50. const info = users[token];
  51. // mock error
  52. if (!info) {
  53. return {
  54. code: 50008,
  55. message: 'Login failed, unable to get user details.'
  56. };
  57. }
  58. return {
  59. code: 20000,
  60. data: info
  61. };
  62. }
  63. },
  64. // user logout
  65. {
  66. url: '/vue-admin-template/user/logout',
  67. type: 'post',
  68. response: _ => {
  69. return {
  70. code: 20000,
  71. data: 'success'
  72. };
  73. }
  74. }
  75. ];