前后端联调测试第一个ts接口
This commit is contained in:
parent
3b612cf022
commit
a0cd9dc031
|
@ -58,13 +58,17 @@ export interface LoginParams {
|
|||
verifyCode?: string
|
||||
}
|
||||
|
||||
|
||||
export interface RegisterParams {
|
||||
phone: string
|
||||
username: string
|
||||
password: string
|
||||
verifyCode?: string
|
||||
confirmPassword: string
|
||||
phone: string
|
||||
phoneCode: string
|
||||
email: string
|
||||
emailCode: string
|
||||
}
|
||||
|
||||
|
||||
// 定义后端返回的用户信息类型
|
||||
export interface UserInfo {
|
||||
id: number
|
||||
|
@ -99,7 +103,7 @@ export const userApi = {
|
|||
|
||||
|
||||
register(data: RegisterParams) {
|
||||
return request.post<ApiResponse<{ token: string }>>('/auth/login', data)
|
||||
return request.post<ApiResponse>('/user/register', data)
|
||||
},
|
||||
|
||||
|
||||
|
@ -108,15 +112,17 @@ export const userApi = {
|
|||
return request.post<ApiResponse<{ token: string }>>('/auth/login', data)
|
||||
},
|
||||
|
||||
// 发送验证码
|
||||
sendVerifyCode(phone: string) {
|
||||
return request.post<ApiResponse<void>>('/user/getEmailCode', { phone })
|
||||
},
|
||||
|
||||
|
||||
|
||||
// 发送验证码
|
||||
sendVerifyEmailCode(email: string) {
|
||||
return request.post<ApiResponse>('/user/getEmailCode', { email })
|
||||
},
|
||||
// 发送验证码
|
||||
sendVerifyPhoneCode(phone: string) {
|
||||
return request.post<ApiResponse>('/user/getphoneCode', { phone })
|
||||
},
|
||||
|
||||
// 获取当前登录用户信息
|
||||
getCurrentUser() {
|
||||
|
|
|
@ -198,15 +198,16 @@ import type { FormInstance } from 'element-plus'
|
|||
import { ElMessage } from 'element-plus'
|
||||
import { userApi } from '@/api/user'
|
||||
|
||||
|
||||
const router = useRouter()
|
||||
const registerFormRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
|
||||
const registerForm = reactive({
|
||||
username: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
phone: '',
|
||||
phoneCode: '',
|
||||
email: '',
|
||||
emailCode: ''
|
||||
|
@ -266,15 +267,16 @@ const handleRegister = async () => {
|
|||
loading.value = true
|
||||
try {
|
||||
// 这里添加实的注册逻辑
|
||||
// const response = await register(registerForm)
|
||||
const response = await userApi.register(registerForm)
|
||||
console.log(response)
|
||||
|
||||
// 模拟注册成功
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
// await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
|
||||
ElMessage.success('注册成功')
|
||||
router.push('/login')
|
||||
} catch (error) {
|
||||
ElMessage.error('注册失败,请稍后重试')
|
||||
//ElMessage.error('注册失败,请稍后重试')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
|
@ -309,11 +311,11 @@ const startEmailCooldown = () => {
|
|||
}
|
||||
|
||||
// 发送手机验证码
|
||||
const sendPhoneCode = () => {
|
||||
if (phoneCooldown.value > 0 || !registerForm.phone) {
|
||||
ElMessage.warning('请先输入手机号')
|
||||
return
|
||||
}
|
||||
const sendPhoneCode = async () => {
|
||||
// if (phoneCooldown.value > 0 || !registerForm.phone) {
|
||||
// ElMessage.warning('请先输入手机号')
|
||||
// return
|
||||
// }
|
||||
|
||||
// 验证手机号格式
|
||||
if (!/^1[3-9]\d{9}$/.test(registerForm.phone)) {
|
||||
|
@ -321,7 +323,7 @@ const sendPhoneCode = () => {
|
|||
return
|
||||
}
|
||||
|
||||
// 这里添加发送验证码的逻辑
|
||||
await userApi.sendVerifyPhoneCode(registerForm.phone)
|
||||
ElMessage.success('手机验证码已发送')
|
||||
startPhoneCooldown()
|
||||
}
|
||||
|
@ -329,9 +331,7 @@ const sendPhoneCode = () => {
|
|||
// 发送邮箱验证码
|
||||
const sendEmailCode = async () => {
|
||||
if (emailCooldown.value > 0 || !registerForm.email) return
|
||||
const result = await userApi.sendVerifyEmailCode(registerForm.email)
|
||||
console.log(result)
|
||||
console.log(result.code)
|
||||
await userApi.sendVerifyEmailCode(registerForm.email)
|
||||
ElMessage.success('邮箱验证码已发送')
|
||||
startEmailCooldown()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue