auth.ts 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { Request, Response } from 'express';
  2. /**
  3. * @author bianlanzhou
  4. * @since 2024-10-15
  5. * @desc mock数据
  6. */
  7. /** 等待时间 */
  8. const waitTime = (time = 100) => {
  9. return new Promise((resolve) => {
  10. setTimeout(() => {
  11. resolve(true);
  12. }, time);
  13. });
  14. };
  15. /** 图片验证码响应数据 */
  16. const imageCaptchaRespData = {
  17. "success": true,
  18. "errCode": null,
  19. "errMessage": null,
  20. "data": {
  21. "uuid": "387b2e19-ede2-457f-8094-cdd1e811fa86",
  22. "img": "/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAjAGQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGV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3rMxSd2TEZldcIOfur69M5/T19Oh01YodoFMg07bPux3rkji5/vHLVzVr/NP9B8q0LWkWQgiXitpRxUMKbVAqworlKHAcUU4DiigDi1qQUUUAIUUnkCp41AHAoooAnUChkU9QKKKAJIkUdAKsqB6UUUASgDFOUDPSiigCwtSLRRQBIOlFFFAH//2Q==",
  23. "type": "IMAGE",
  24. "code": "5",
  25. }
  26. }
  27. /** 用户名密码登录响应数据 */
  28. const loginRespData = {
  29. "success": true,
  30. "errCode": null,
  31. "errMessage": null,
  32. "data": "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImFmZmZiMmExLTc2ZTYtNGM0My05Y2E4LTI0MjJkYzMyYjUyYyJ9.KvzhtlNE0e4jm_L3tEVB6euN0PWu3eX1uHNjrRYYJ6oHhd8AAvxxejG19arsY0PgV4dkN85SI61TkGFAHrH7tw"
  33. }
  34. /** otp登录响应数据 */
  35. const otpLoginRespData = {
  36. "success": true,
  37. "errCode": null,
  38. "errMessage": null,
  39. }
  40. /** 获取当前登录用户响应数据 */
  41. const fetchCurrentUserRespData = {
  42. "success": false,
  43. "errCode": null,
  44. "errMessage": null,
  45. "data": {
  46. "id": 1,
  47. "username": "admin",
  48. "nickName": "管理员",
  49. "deptId": null,
  50. "avatar": '/icons/user.svg',
  51. "loginIp": "127.0.0.1",
  52. "permissions": [
  53. "*:*:*"
  54. ],
  55. "sysDept": null,
  56. "roles": null
  57. }
  58. }
  59. /** 获取图片验证码 */
  60. const getImageCaptcha = async (req: Request, res: Response) => {
  61. await waitTime(2000);
  62. res.json(imageCaptchaRespData);
  63. }
  64. /** 用户名密码登录 */
  65. const handleLogin = async (req: Request, res: Response) => {
  66. await waitTime(2000);
  67. res.json(loginRespData);
  68. }
  69. /** otp登录 */
  70. const handleOtpLogin = async (req: Request, res: Response) => {
  71. await waitTime(2000);
  72. res.json(otpLoginRespData);
  73. }
  74. /** 获取当前用户 */
  75. const handleFetchCurrentUser = async (req: Request, res: Response) => {
  76. await waitTime(2000);
  77. res.json(fetchCurrentUserRespData);
  78. }
  79. export default {
  80. 'GET /auth/captcha/image': getImageCaptcha,
  81. 'POST /auth/login': handleLogin,
  82. 'POST /auth/otp-login': handleOtpLogin,
  83. 'GET /auth/current-user': handleFetchCurrentUser,
  84. };