|
|
|
@ -90,14 +90,13 @@
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
<script setup lang="js" name="UserRegister">
|
|
|
|
|
import { ref, computed, onMounted } from 'vue';
|
|
|
|
|
import request from '@/utils/request';
|
|
|
|
|
import {ElMessage} from 'element-plus'
|
|
|
|
|
import { ElMessage } from 'element-plus';
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['toggleForm']);
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'UserRegister',
|
|
|
|
|
setup(props, { emit }) {
|
|
|
|
|
const currentType = ref('username');
|
|
|
|
|
const cooldown = ref(0); // 验证码倒计时
|
|
|
|
|
|
|
|
|
@ -121,18 +120,17 @@ export default {
|
|
|
|
|
|
|
|
|
|
// 前端验证格式
|
|
|
|
|
const isValidInput = computed(() => {
|
|
|
|
|
const value = registerForm.value[currentType.value]
|
|
|
|
|
if (!value) return false
|
|
|
|
|
|
|
|
|
|
const value = registerForm.value[currentType.value];
|
|
|
|
|
if (!value) return false;
|
|
|
|
|
switch (currentType.value) {
|
|
|
|
|
case 'email':
|
|
|
|
|
return /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(value)
|
|
|
|
|
return /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(value);
|
|
|
|
|
case 'phone':
|
|
|
|
|
return /^1[3-9]\d{9}$/.test(value)
|
|
|
|
|
return /^1[3-9]\d{9}$/.test(value);
|
|
|
|
|
default:
|
|
|
|
|
return false
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 图形验证码URL
|
|
|
|
|
const captchaUrl = ref('/user/captcha');
|
|
|
|
@ -163,7 +161,6 @@ export default {
|
|
|
|
|
// 发送验证码方法(邮箱/手机注册时使用)
|
|
|
|
|
async function sendCode() {
|
|
|
|
|
if (cooldown.value > 0 || !isValidInput.value) return;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// TODO:发送验证码请求
|
|
|
|
|
const response = await request.post(`/user/send-code`, {
|
|
|
|
@ -198,7 +195,6 @@ export default {
|
|
|
|
|
captchaUrl.value = `/user/captcha?t=${new Date().getTime()}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO:暂时跳过手机/邮箱验证码验证的注册
|
|
|
|
|
// 注册
|
|
|
|
|
async function register() {
|
|
|
|
|
try {
|
|
|
|
@ -260,7 +256,6 @@ export default {
|
|
|
|
|
duration: 500
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (error) {
|
|
|
|
|
console.error('注册失败:', error);
|
|
|
|
@ -273,24 +268,6 @@ export default {
|
|
|
|
|
// 初始化图形验证码
|
|
|
|
|
refreshCaptcha();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 返回模板需要使用的数据和方法
|
|
|
|
|
return {
|
|
|
|
|
currentType,
|
|
|
|
|
registerTypes,
|
|
|
|
|
registerForm,
|
|
|
|
|
captchaUrl,
|
|
|
|
|
inputType,
|
|
|
|
|
placeholder,
|
|
|
|
|
showVerifyCode,
|
|
|
|
|
cooldown,
|
|
|
|
|
sendCode,
|
|
|
|
|
refreshCaptcha,
|
|
|
|
|
register,
|
|
|
|
|
isValidInput
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|