更新:登录功能

This commit is contained in:
2025-11-04 12:37:04 +08:00
commit a21fb92916
897 changed files with 51500 additions and 0 deletions

49
api/modules/auth.ts Normal file
View File

@@ -0,0 +1,49 @@
// api/modules/auth.ts
import { mainClient } from '@/api/clients/main'
import type { IApiResponse } from '@/api/types'
import type { IUserInfo, ILoginResponse } from '@/types/user'
/**
* 验证码登录/注册
* @param tel 邮箱地址
* @param code 验证码
*/
export async function loginWithCode(tel: string, code: string) {
const res = await mainClient.request<IApiResponse<ILoginResponse>>({
url: 'book/user/registerOrLogin',
method: 'GET',
data: { tel, code }
})
return res
}
/**
* 密码登录
* @param phone 邮箱地址
* @param password 密码
*/
export async function loginWithPassword(phone: string, password: string) {
const res = await mainClient.request<IApiResponse<ILoginResponse>>({
url: 'book/user/login',
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
data: { phone, password }
})
return res
}
/**
* 重置密码
* @param phone 邮箱地址
* @param code 验证码
* @param password 新密码
*/
export async function resetPassword(phone: string, code: string, password: string) {
const res = await mainClient.request<IApiResponse>({
url: 'book/user/setPassword',
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
data: { phone, code, password }
})
return res.data
}

31
api/modules/common.ts Normal file
View File

@@ -0,0 +1,31 @@
// api/modules/common.ts
import { mainClient } from '@/api/clients/main'
import type { IApiResponse } from '@/api/types'
import type { IAgreement } from '@/types/user'
export const commonApi = {
/**
* 发送邮箱验证码
* @param email 邮箱地址
*/
sendMailCaptcha: async (email: string) => {
const res = await mainClient.request<IApiResponse>({
url: 'common/user/getMailCaptcha',
method: 'GET',
data: { email }
})
return res.data
},
/**
* 获取协议内容
* @param id 协议 ID (111: 用户协议, 112: 隐私政策)
*/
getAgreement: async (id: number) => {
const res = await mainClient.request<IApiResponse<IAgreement>>({
url: 'sys/agreement/getAgreement',
method: 'POST',
data: { id }
})
return res.agreement
}
}