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