user.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { MockMethod } from 'vite-plugin-mock';
  2. import { resultError, resultSuccess, getRequestToken, requestParams, baseUrl } from '../_util';
  3. export function createFakeUserList() {
  4. return [
  5. {
  6. userId: '1',
  7. username: '',
  8. realname: '管理员',
  9. avatar: 'https://q1.qlogo.cn/g?b=qq&nk=190848757&s=640',
  10. desc: 'manager',
  11. password: '',
  12. token: 'fakeToken1',
  13. homePath: '/dashboard/analysis',
  14. roles: [
  15. {
  16. roleName: 'Super Admin',
  17. value: 'super',
  18. },
  19. ],
  20. },
  21. {
  22. userId: '2',
  23. username: 'jeecg',
  24. password: '123456',
  25. realname: '测试用户',
  26. avatar: 'https://q1.qlogo.cn/g?b=qq&nk=339449197&s=640',
  27. desc: 'tester',
  28. token: 'fakeToken2',
  29. homePath: '/dashboard/workbench',
  30. roles: [
  31. {
  32. roleName: 'Tester',
  33. value: 'test',
  34. },
  35. ],
  36. },
  37. ];
  38. }
  39. const fakeCodeList: any = {
  40. '1': ['1000', '3000', '5000'],
  41. '2': ['2000', '4000', '6000'],
  42. };
  43. export default [
  44. // mock user login
  45. {
  46. url: `${baseUrl}/sys/login`,
  47. timeout: 200,
  48. method: 'post',
  49. response: ({ body }) => {
  50. const { username, password } = body;
  51. const checkUser = createFakeUserList().find((item) => item.username === username && password === item.password);
  52. if (!checkUser) {
  53. return resultError('Incorrect account or password!');
  54. }
  55. const { userId, username: _username, token, realname, desc, roles } = checkUser;
  56. return resultSuccess({
  57. roles,
  58. userId,
  59. username: _username,
  60. token,
  61. realname,
  62. desc,
  63. });
  64. },
  65. },
  66. {
  67. url: `${baseUrl}/sys/user/getUserInfo`,
  68. method: 'get',
  69. response: (request: requestParams) => {
  70. const token = getRequestToken(request);
  71. if (!token) return resultError('Invalid token');
  72. const checkUser = createFakeUserList().find((item) => item.token === token);
  73. if (!checkUser) {
  74. return resultError('The corresponding user information was not obtained!');
  75. }
  76. return resultSuccess(checkUser);
  77. },
  78. },
  79. {
  80. url: `${baseUrl}/sys/permissionNew/getPermCode`,
  81. timeout: 200,
  82. method: 'get',
  83. response: (request: requestParams) => {
  84. const token = getRequestToken(request);
  85. if (!token) return resultError('Invalid token');
  86. const checkUser = createFakeUserList().find((item) => item.token === token);
  87. if (!checkUser) {
  88. return resultError('Invalid token!');
  89. }
  90. const codeList = fakeCodeList[checkUser.userId];
  91. return resultSuccess(codeList);
  92. },
  93. },
  94. {
  95. url: `${baseUrl}/sys/logout`,
  96. timeout: 200,
  97. method: 'get',
  98. response: (request: requestParams) => {
  99. const token = getRequestToken(request);
  100. if (!token) return resultError('Invalid token');
  101. const checkUser = createFakeUserList().find((item) => item.token === token);
  102. if (!checkUser) {
  103. return resultError('Invalid token!');
  104. }
  105. return resultSuccess(undefined, { message: 'Token has been destroyed' });
  106. },
  107. },
  108. {
  109. url: `${baseUrl}/sys/randomImage/1629428467008`,
  110. timeout: 200,
  111. method: 'get',
  112. response: (request: requestParams) => {
  113. const result =
  114. 'data:image/jpg;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAjAGkDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5i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Y9q39X0Sx1myuLLUknWwbLSLDdyQrKGUhgxRlOPvZUnac5OT0AseQfEHT7u71CP4keHrbTZJtFSGWQ/Zmk+3gMytMByDGm0BXwrbVdwwVYmPqXhvxDZeKdEj1bRL6AWM42NvT9/DLtVQkmWOXBx16jbjIINGl+GdPs9I/seG6nSAfIY7e/n3qqEBVSQuZI1A25RWABOOhO7P8NeA/DejRveaBpb2IuW2k/bJmDxjIDlJNyk4LYyOjHBGaAOwjeQogYxtIuBNtbhTjPH6cHsalqlbWMFrcSNuVnkkeZAwG5c/eI79wOO2O+SbtABSMiuMMoYZBwRnkHIP50UUALRRRQAUUUUAFFFFACBVUsVUAscsQOpxjn8AKWiigBFVUQIihVUYAAwAKY8EUkqSOgZ0BCk9uQf5qD+FFFAElFFFAH//2Q==';
  115. return resultSuccess(result);
  116. },
  117. },
  118. ] as MockMethod[];