Compare commits
No commits in common. "88349683e71018190f4ca5e7a681d87670e68fd4" and "8bca3e097850de57e1322771ef3dea82d335573b" have entirely different histories.
88349683e7
...
8bca3e0978
@ -31,6 +31,7 @@ const actions = {
|
||||
|
||||
const getters = {
|
||||
isAuthenticated: (state) => state.isAuthenticated,
|
||||
user: (state) => state.user,
|
||||
token: (state) => state.token,
|
||||
};
|
||||
|
||||
|
||||
@ -9,9 +9,7 @@ const username = ref('');
|
||||
const phoneNumber = ref('');
|
||||
const password = ref('');
|
||||
const verificationCode = ref('');
|
||||
const correctCode = ref('');
|
||||
const router = useRouter();
|
||||
const verificationCodeImage = ref('');
|
||||
|
||||
const handleRegister = async () => {
|
||||
console.log('Registering with', {
|
||||
@ -20,10 +18,6 @@ const handleRegister = async () => {
|
||||
password: password.value,
|
||||
verificationCode: verificationCode.value
|
||||
});
|
||||
if (verificationCode.value!==correctCode.value){
|
||||
await ElMessageBox.alert("验证码错误");
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.post('/api/register', {
|
||||
@ -44,19 +38,20 @@ const handleRegister = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const getVerificationCode = async () => {
|
||||
const sendVerificationCode = async () => {
|
||||
try {
|
||||
const response = await axios.get('/api/getVerificationCode');
|
||||
const response = await axios.post('/api/sendVerificationCode', {
|
||||
phoneNumber: phoneNumber.value,
|
||||
});
|
||||
|
||||
if (response.status === 200) {
|
||||
verificationCodeImage.value = '/api/'+response.data.path; // 更新验证码图片路径
|
||||
correctCode.value = response.data.code;
|
||||
ElMessage.success('验证码已获取');
|
||||
verificationCode.value = response.data.code;
|
||||
ElMessage.success('验证码已发送');
|
||||
} else {
|
||||
ElMessage.error('获取验证码失败,请稍后再试');
|
||||
ElMessage.error('发送验证码失败,请稍后再试');
|
||||
}
|
||||
} catch (error) {
|
||||
ElMessage.error('获取验证码失败,请稍后再试');
|
||||
ElMessage.error('发送验证码失败,请稍后再试');
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@ -82,13 +77,10 @@ const getVerificationCode = async () => {
|
||||
<label for="verificationCode">验证码</label>
|
||||
<ElInput v-model="verificationCode" type="text" id="verificationCode" placeholder="请输入验证码" required>
|
||||
<template #append>
|
||||
<ElButton type="primary" @click="getVerificationCode" class="verification-button">获取验证码</ElButton>
|
||||
<ElButton type="primary" @click="sendVerificationCode" class="verification-button">获取验证码</ElButton>
|
||||
</template>
|
||||
</ElInput>
|
||||
</ElFormItem>
|
||||
<ElFormItem v-if="verificationCodeImage">
|
||||
<img :src="verificationCodeImage" alt="验证码" />
|
||||
</ElFormItem>
|
||||
<ElFormItem>
|
||||
<ElButton type="primary" native-type="submit" class="register-button">注册</ElButton>
|
||||
</ElFormItem>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user