Compare commits

..

No commits in common. "1a648252e6f5dc20308ea2442457fc34757cbcc1" and "b433c10b0b03805243f9d7b35a111c9475328d15" have entirely different histories.

2 changed files with 23 additions and 29 deletions

View File

@ -58,16 +58,12 @@ export interface LoginParams {
verifyCode?: string verifyCode?: string
} }
export interface RegisterParams {
username: string
password: string
confirmPassword: string
phone: string
phoneCode: string
email: string
emailCode: string
}
export interface RegisterParams {
phone: string
password: string
verifyCode?: string
}
// 定义后端返回的用户信息类型 // 定义后端返回的用户信息类型
export interface UserInfo { export interface UserInfo {
@ -103,7 +99,7 @@ export const userApi = {
register(data: RegisterParams) { register(data: RegisterParams) {
return request.post<ApiResponse>('/user/register', data) return request.post<ApiResponse<{ token: string }>>('/auth/login', data)
}, },
@ -112,17 +108,15 @@ export const userApi = {
return request.post<ApiResponse<{ token: string }>>('/auth/login', data) return request.post<ApiResponse<{ token: string }>>('/auth/login', data)
}, },
// 发送验证码
sendVerifyCode(phone: string) {
return request.post<ApiResponse<void>>('/user/getEmailCode', { phone })
},
// 发送验证码 // 发送验证码
sendVerifyEmailCode(email: string) { sendVerifyEmailCode(email: string) {
return request.post<ApiResponse>('/user/getEmailCode', { email }) return request.post<ApiResponse>('/user/getEmailCode', { email })
}, },
// 发送验证码
sendVerifyPhoneCode(phone: string) {
return request.post<ApiResponse>('/user/getphoneCode', { phone })
},
// 获取当前登录用户信息 // 获取当前登录用户信息
getCurrentUser() { getCurrentUser() {

View File

@ -198,16 +198,15 @@ import type { FormInstance } from 'element-plus'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { userApi } from '@/api/user' import { userApi } from '@/api/user'
const router = useRouter() const router = useRouter()
const registerFormRef = ref<FormInstance>() const registerFormRef = ref<FormInstance>()
const loading = ref(false) const loading = ref(false)
const registerForm = reactive({ const registerForm = reactive({
username: '', username: '',
phone: '',
password: '', password: '',
confirmPassword: '', confirmPassword: '',
phone: '',
phoneCode: '', phoneCode: '',
email: '', email: '',
emailCode: '' emailCode: ''
@ -267,16 +266,15 @@ const handleRegister = async () => {
loading.value = true loading.value = true
try { try {
// //
const response = await userApi.register(registerForm) // const response = await register(registerForm)
console.log(response)
// //
// await new Promise(resolve => setTimeout(resolve, 1000)) await new Promise(resolve => setTimeout(resolve, 1000))
ElMessage.success('注册成功') ElMessage.success('注册成功')
router.push('/login') router.push('/login')
} catch (error) { } catch (error) {
//ElMessage.error('') ElMessage.error('注册失败,请稍后重试')
} finally { } finally {
loading.value = false loading.value = false
} }
@ -311,11 +309,11 @@ const startEmailCooldown = () => {
} }
// //
const sendPhoneCode = async () => { const sendPhoneCode = () => {
// if (phoneCooldown.value > 0 || !registerForm.phone) { if (phoneCooldown.value > 0 || !registerForm.phone) {
// ElMessage.warning('') ElMessage.warning('请先输入手机号')
// return return
// } }
// //
if (!/^1[3-9]\d{9}$/.test(registerForm.phone)) { if (!/^1[3-9]\d{9}$/.test(registerForm.phone)) {
@ -323,7 +321,7 @@ const sendPhoneCode = async () => {
return return
} }
await userApi.sendVerifyPhoneCode(registerForm.phone) //
ElMessage.success('手机验证码已发送') ElMessage.success('手机验证码已发送')
startPhoneCooldown() startPhoneCooldown()
} }
@ -331,7 +329,9 @@ const sendPhoneCode = async () => {
// //
const sendEmailCode = async () => { const sendEmailCode = async () => {
if (emailCooldown.value > 0 || !registerForm.email) return if (emailCooldown.value > 0 || !registerForm.email) return
await userApi.sendVerifyEmailCode(registerForm.email) const result = await userApi.sendVerifyEmailCode(registerForm.email)
console.log(result)
console.log(result.code)
ElMessage.success('邮箱验证码已发送') ElMessage.success('邮箱验证码已发送')
startEmailCooldown() startEmailCooldown()
} }