auth.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0d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ldcIOfur69M5/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: true,
  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. sysDept: null,
  54. roles: null,
  55. },
  56. };
  57. /** 获取图片验证码 */
  58. const getImageCaptcha = async (req: Request, res: Response) => {
  59. await waitTime(2000);
  60. res.json(imageCaptchaRespData);
  61. };
  62. /** 用户名密码登录 */
  63. const handleLogin = async (req: Request, res: Response) => {
  64. await waitTime(2000);
  65. res.json(loginRespData);
  66. };
  67. /** otp登录 */
  68. const handleOtpLogin = async (req: Request, res: Response) => {
  69. await waitTime(2000);
  70. res.json(otpLoginRespData);
  71. };
  72. /** 获取当前用户 */
  73. const handleFetchCurrentUser = async (req: Request, res: Response) => {
  74. await waitTime(2000);
  75. res.json(fetchCurrentUserRespData);
  76. };
  77. export default {
  78. 'GET /auth/captcha/image': getImageCaptcha,
  79. 'POST /auth/login': handleLogin,
  80. 'POST /auth/otp-login': handleOtpLogin,
  81. 'GET /auth/current-user': handleFetchCurrentUser,
  82. };