user.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
  14. name: 'Super Admin'
  15. },
  16. 'editor-token': {
  17. roles: ['editor'],
  18. introduction: 'I am an editor',
  19. avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
  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. ]