前后端联调测试第一个ts接口
This commit is contained in:
parent
4d592db87e
commit
3b612cf022
|
@ -3,6 +3,7 @@ export interface ApiResponse<T = any> {
|
|||
code: number
|
||||
message: string
|
||||
data: T
|
||||
timestamp: number
|
||||
}
|
||||
|
||||
// 分页请求参数接口
|
|
@ -1,5 +1,5 @@
|
|||
import request from '@/utils/request'
|
||||
import type { ApiResponse, PageResult } from './types'
|
||||
import type { ApiResponse, PageResult } from './common/types'
|
||||
|
||||
// 定义接口的请求参数类型
|
||||
|
||||
|
@ -58,6 +58,13 @@ export interface LoginParams {
|
|||
verifyCode?: string
|
||||
}
|
||||
|
||||
|
||||
export interface RegisterParams {
|
||||
phone: string
|
||||
password: string
|
||||
verifyCode?: string
|
||||
}
|
||||
|
||||
// 定义后端返回的用户信息类型
|
||||
export interface UserInfo {
|
||||
id: number
|
||||
|
@ -84,8 +91,18 @@ export interface UserQueryParams {
|
|||
ageRange?: [number, number]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 用户API接口
|
||||
export const userApi = {
|
||||
|
||||
|
||||
register(data: RegisterParams) {
|
||||
return request.post<ApiResponse<{ token: string }>>('/auth/login', data)
|
||||
},
|
||||
|
||||
|
||||
// 手机号密码登录
|
||||
login(data: LoginParams) {
|
||||
return request.post<ApiResponse<{ token: string }>>('/auth/login', data)
|
||||
|
@ -98,7 +115,7 @@ export const userApi = {
|
|||
|
||||
// 发送验证码
|
||||
sendVerifyEmailCode(email: string) {
|
||||
return request.post<ApiResponse<void>>('/user/getEmailCode', { email })
|
||||
return request.post<ApiResponse>('/user/getEmailCode', { email })
|
||||
},
|
||||
|
||||
// 获取当前登录用户信息
|
||||
|
|
|
@ -279,7 +279,6 @@ const sendEmailCode = async () => {
|
|||
ElMessage.warning('请先输入邮箱')
|
||||
return
|
||||
}
|
||||
console.log(111)
|
||||
await userApi.sendVerifyEmailCode(emailForm.email)
|
||||
ElMessage.success('验证码已发送')
|
||||
startCooldown('email')
|
||||
|
|
|
@ -196,6 +196,7 @@ import { useRouter } from 'vue-router'
|
|||
import { User, Lock, Phone, Message, Platform, Right, Key } from '@element-plus/icons-vue'
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { userApi } from '@/api/user'
|
||||
|
||||
const router = useRouter()
|
||||
const registerFormRef = ref<FormInstance>()
|
||||
|
@ -326,9 +327,11 @@ const sendPhoneCode = () => {
|
|||
}
|
||||
|
||||
// 发送邮箱验证码
|
||||
const sendEmailCode = () => {
|
||||
const sendEmailCode = async () => {
|
||||
if (emailCooldown.value > 0 || !registerForm.email) return
|
||||
// 这里添加发送验证码的逻辑
|
||||
const result = await userApi.sendVerifyEmailCode(registerForm.email)
|
||||
console.log(result)
|
||||
console.log(result.code)
|
||||
ElMessage.success('邮箱验证码已发送')
|
||||
startEmailCooldown()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue