user.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. const tokens = {
  11. admin: {
  12. token: 'admin-token'
  13. },
  14. editor: {
  15. token: 'editor-token'
  16. }
  17. }
  18. const users = {
  19. 'admin-token': {
  20. roles: ['admin'],
  21. introduction: 'I am a super administrator',
  22. avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
  23. name: 'Super Admin'
  24. },
  25. 'editor-token': {
  26. roles: ['editor'],
  27. introduction: 'I am an editor',
  28. avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
  29. name: 'Normal Editor'
  30. }
  31. }
  32. export default [
  33. // user login
  34. {
  35. url: '/vue-element-admin/user/login',
  36. type: 'post',
  37. response: config => {
  38. const { username } = config.body
  39. const token = tokens[username]
  40. // mock error
  41. if (!token) {
  42. return {
  43. code: 60204,
  44. message: 'Account and password are incorrect.'
  45. }
  46. }
  47. return {
  48. code: 20000,
  49. data: token
  50. }
  51. }
  52. },
  53. // get user info
  54. {
  55. url: '/vue-element-admin/user/info\.*',
  56. type: 'get',
  57. response: config => {
  58. const { token } = config.query
  59. const info = users[token]
  60. // mock error
  61. if (!info) {
  62. return {
  63. code: 50008,
  64. message: 'Login failed, unable to get user details.'
  65. }
  66. }
  67. return {
  68. code: 20000,
  69. data: info
  70. }
  71. }
  72. },
  73. // user logout
  74. {
  75. url: '/vue-element-admin/user/logout',
  76. type: 'post',
  77. response: _ => {
  78. return {
  79. code: 20000,
  80. data: 'success'
  81. }
  82. }
  83. }
  84. ]