user.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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: 'admin',
  8. realname: '管理员',
  9. avatar: 'https://q1.qlogo.cn/g?b=qq&nk=190848757&s=640',
  10. desc: 'manager',
  11. password: '123456',
  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(
  52. (item) => item.username === username && password === item.password
  53. );
  54. if (!checkUser) {
  55. return resultError('Incorrect account or password!');
  56. }
  57. const { userId, username: _username, token, realname, desc, roles } = checkUser;
  58. return resultSuccess({
  59. roles,
  60. userId,
  61. username: _username,
  62. token,
  63. realname,
  64. desc,
  65. });
  66. },
  67. },
  68. {
  69. url: `${baseUrl}/sys/user/getUserInfo`,
  70. method: 'get',
  71. response: (request: requestParams) => {
  72. const token = getRequestToken(request);
  73. if (!token) return resultError('Invalid token');
  74. const checkUser = createFakeUserList().find((item) => item.token === token);
  75. if (!checkUser) {
  76. return resultError('The corresponding user information was not obtained!');
  77. }
  78. return resultSuccess(checkUser);
  79. },
  80. },
  81. {
  82. url: `${baseUrl}/sys/permission/getPermCode`,
  83. timeout: 200,
  84. method: 'get',
  85. response: (request: requestParams) => {
  86. const token = getRequestToken(request);
  87. if (!token) return resultError('Invalid token');
  88. const checkUser = createFakeUserList().find((item) => item.token === token);
  89. if (!checkUser) {
  90. return resultError('Invalid token!');
  91. }
  92. const codeList = fakeCodeList[checkUser.userId];
  93. return resultSuccess(codeList);
  94. },
  95. },
  96. {
  97. url: `${baseUrl}/sys/logout`,
  98. timeout: 200,
  99. method: 'get',
  100. response: (request: requestParams) => {
  101. const token = getRequestToken(request);
  102. if (!token) return resultError('Invalid token');
  103. const checkUser = createFakeUserList().find((item) => item.token === token);
  104. if (!checkUser) {
  105. return resultError('Invalid token!');
  106. }
  107. return resultSuccess(undefined, { message: 'Token has been destroyed' });
  108. },
  109. },
  110. {
  111. url: `${baseUrl}/sys/randomImage/1629428467008`,
  112. timeout: 200,
  113. method: 'get',
  114. response: (request: requestParams) => {
  115. const result =
  116. 'data:image/jpg;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAjAGkDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh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dgw3mZOB8uMjgY9q39X0Sx1myuLLUknWwbLSLDdyQrKGUhgxRlOPvZUnac5OT0AseQfEHT7u71CP4keHrbTZJtFSGWQ/Zmk+3gMytMByDGm0BXwrbVdwwVYmPqXhvxDZeKdEj1bRL6AWM42NvT9/DLtVQkmWOXBx16jbjIINGl+GdPs9I/seG6nSAfIY7e/n3qqEBVSQuZI1A25RWABOOhO7P8NeA/DejRveaBpb2IuW2k/bJmDxjIDlJNyk4LYyOjHBGaAOwjeQogYxtIuBNtbhTjPH6cHsalqlbWMFrcSNuVnkkeZAwG5c/eI79wOO2O+SbtABSMiuMMoYZBwRnkHIP50UUALRRRQAUUUUAFFFFACBVUsVUAscsQOpxjn8AKWiigBFVUQIihVUYAAwAKY8EUkqSOgZ0BCk9uQf5qD+FFFAElFFFAH//2Q==';
  117. return resultSuccess(result);
  118. },
  119. },
  120. ] as MockMethod[];