auth.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { http } from "@/utils/http";
  2. // 登录参数
  3. interface LoginParams {
  4. type: 'phone' | 'email';
  5. account: string;
  6. password: string;
  7. areaCode?: string;
  8. }
  9. // 注册参数
  10. interface RegisterParams {
  11. type: 'phone' | 'email';
  12. account: string;
  13. password: string;
  14. code: string;
  15. inviteCode?: string;
  16. areaCode?: string;
  17. }
  18. // 发送验证码参数
  19. interface SendCodeParams {
  20. type: 'phone' | 'email';
  21. account: string;
  22. areaCode?: string;
  23. scene: 'register' | 'login' | 'reset' | 'bind';
  24. }
  25. // 重置密码参数
  26. interface ResetPasswordParams {
  27. type: 'phone' | 'email';
  28. account: string;
  29. code: string;
  30. newPassword: string;
  31. areaCode?: string;
  32. }
  33. // 密码登录
  34. export function requestLogin(data: LoginParams): Promise<CommonResponse<{ token: string; userInfo: UserInfo }>> {
  35. return http.request({
  36. url: "/api/v1/dt/auth/login/password",
  37. method: "post",
  38. data
  39. });
  40. }
  41. // 短信登录
  42. export function requestLoginBySms(data: { phone: string; code: string; areaCode?: string }): Promise<CommonResponse<{ token: string; userInfo: UserInfo }>> {
  43. return http.request({
  44. url: "/api/v1/dt/auth/login/sms",
  45. method: "post",
  46. data
  47. });
  48. }
  49. // 注册
  50. export function requestRegister(data: RegisterParams): Promise<CommonResponse> {
  51. return http.request({
  52. url: "/api/v1/dt/auth/register",
  53. method: "post",
  54. data
  55. });
  56. }
  57. // 发送验证码
  58. export function requestSendCode(data: SendCodeParams): Promise<CommonResponse> {
  59. return http.request({
  60. url: "/api/v1/dt/auth/sms/send",
  61. method: "post",
  62. data
  63. });
  64. }
  65. // 重置密码
  66. export function requestResetPassword(data: ResetPasswordParams): Promise<CommonResponse> {
  67. return http.request({
  68. url: "/api/v1/dt/auth/password/reset",
  69. method: "post",
  70. data
  71. });
  72. }
  73. // 退出登录
  74. export function requestLogout(): Promise<CommonResponse> {
  75. return http.request({
  76. url: "/api/v1/dt/user/logout",
  77. method: "post"
  78. });
  79. }
  80. // 获取授权URL
  81. export function requestGetAuthUrl(redirectUri: string): Promise<CommonResponse<{ noDomainAuthUrl: string; defaultDomain: string }>> {
  82. return http.request({
  83. url: "/api/v1/dt/auth/url",
  84. method: "get",
  85. params: { redirectUri }
  86. });
  87. }
  88. // OAuth登录参数
  89. interface OAuthLoginParams {
  90. provider: 'google' | 'zalo' | 'telegram' | 'tiktok' | 'facebook';
  91. openId: string;
  92. nickname?: string;
  93. avatar?: string;
  94. email?: string;
  95. inviteCode?: string;
  96. extra?: string; // Zalo: code_verifier
  97. }
  98. // OAuth登录
  99. export function requestOAuthLogin(data: OAuthLoginParams): Promise<CommonResponse<{ token: string; user: UserInfo; isNew?: boolean }>> {
  100. return http.request({
  101. url: "/api/v1/dt/auth/oauth/login",
  102. method: "post",
  103. data
  104. });
  105. }
  106. // 获取OAuth配置
  107. export function requestOAuthConfig(): Promise<CommonResponse<{ googleClientId?: string; zaloAppId?: string; telegramBotName?: string; telegramBotId?: string; tiktokClientKey?: string; facebookAppId?: string }>> {
  108. return http.request({
  109. url: "/api/v1/dt/config/oauth",
  110. method: "get"
  111. });
  112. }