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