2025-09-16
This commit is contained in:
@@ -131,9 +131,11 @@
|
||||
|
||||
// 选择省市区
|
||||
const handleRegion = (e) => {
|
||||
console.log(e);
|
||||
userRegister.userRegisterForm.regionLabel = e[0].label + "/" + e[1].label + "/" + e[2].label
|
||||
userRegister.userRegisterForm.region = e[2].value
|
||||
userRegister.userRegisterForm.province = e[0].value
|
||||
userRegister.userRegisterForm.city = e[1].value
|
||||
userRegister.userRegisterForm.district = e[2].value
|
||||
userRegister.userRegisterForm.district_id = e[2].value
|
||||
}
|
||||
|
||||
|
||||
@@ -162,10 +164,11 @@
|
||||
callback(new Error('密码必须包含字母和数字'));
|
||||
} else {
|
||||
// 如果确认密码已输入,重新验证确认密码
|
||||
if (userRegister.userRegisterForm.confirmPassword) {
|
||||
userRegisterRef.value?.validateField('confirmPassword');
|
||||
}
|
||||
callback();
|
||||
// if (userRegister.userRegisterForm.confirmPassword && userRegister.userRegisterForm.confirmPassword == userRegister.userRegisterForm.password) {
|
||||
// return true
|
||||
// }
|
||||
// callback(new Error('两次输入的密码不一致'));
|
||||
return true
|
||||
}
|
||||
};
|
||||
|
||||
@@ -183,14 +186,17 @@
|
||||
const userRegisterRef = ref()
|
||||
const userRegister = reactive({
|
||||
userRegisterForm: {
|
||||
username: '13758452159',
|
||||
phone: '13758452159',
|
||||
smsCode: 'asrfdv',
|
||||
region: '',
|
||||
username: '',
|
||||
phone: '',
|
||||
smsCode: '',
|
||||
province: '',
|
||||
city: '',
|
||||
district: '',
|
||||
district_id: '',
|
||||
regionLabel: '',
|
||||
password: 's123456s',
|
||||
confirmPassword: 's123456s',
|
||||
captcha: 'vfjs',
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
captcha: '',
|
||||
},
|
||||
rules: {
|
||||
phone: [{
|
||||
@@ -238,8 +244,7 @@
|
||||
max: 4,
|
||||
message: '验证码长度为4位',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
}],
|
||||
}
|
||||
})
|
||||
|
||||
@@ -252,47 +257,54 @@
|
||||
})
|
||||
return
|
||||
}
|
||||
// 等待表单验证完成
|
||||
const valid = await userRegisterRef.value.validate();
|
||||
if (valid) {
|
||||
console.log(valid);
|
||||
|
||||
try {
|
||||
userRegisterRef.value.validate((valid : any) => {
|
||||
if (valid) {
|
||||
// 验证通过后执行的逻辑
|
||||
console.log('表单验证通过', userRegister.userRegisterForm);
|
||||
|
||||
// 提交注册
|
||||
const registerData = {
|
||||
username: userRegister.userRegisterForm.phone,
|
||||
phone: userRegister.userRegisterForm.phone,
|
||||
province: userRegister.userRegisterForm.province,
|
||||
city: userRegister.userRegisterForm.city,
|
||||
district: userRegister.userRegisterForm.district,
|
||||
district_id: userRegister.userRegisterForm.district_id,
|
||||
password: userRegister.userRegisterForm.password,
|
||||
smsCode: userRegister.userRegisterForm.smsCode,
|
||||
captchaId: captchaId.value,
|
||||
captchaText: userRegister.userRegisterForm.captcha,
|
||||
}
|
||||
authAPI.register(registerData).then(response => {
|
||||
if (response.success) {
|
||||
console.log('注册结果', response);
|
||||
uni.setStorageSync("token", response.token)
|
||||
uni.setStorageSync("user", response.user)
|
||||
uni.showToast({
|
||||
title: '注册成功',
|
||||
success() {
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
url: '/pages/home/index'
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
}
|
||||
}).catch((err) => {
|
||||
setTimeout(() => {
|
||||
userRegister.userRegisterForm.captcha = ''
|
||||
loadCaptcha()
|
||||
}, 1000)
|
||||
})
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
// 验证失败时会进入这里,无需额外处理(表单会自动显示错误信息)
|
||||
console.log('表单验证失败', error);
|
||||
}
|
||||
// userRegisterRef.value.validate((valid : any) => {
|
||||
// if (valid) {
|
||||
// // 验证验证码
|
||||
// captchaAPI.verify({
|
||||
// captchaId: captchaId.value,
|
||||
// captchaText: userRegister.userRegisterForm.captcha
|
||||
// }).then(verifyResponse => {
|
||||
// console.log(verifyResponse);
|
||||
// if (!verifyResponse.data.success) {
|
||||
// uni.showToast({
|
||||
// title: verifyResponse.data.message || '验证码错误',
|
||||
// icon: 'error'
|
||||
// })
|
||||
// // 重新加载验证码
|
||||
// loadCaptcha()
|
||||
// return
|
||||
// }
|
||||
// })
|
||||
// const registerData = {
|
||||
// username: userRegister.userRegisterForm.phone,
|
||||
// phone: userRegister.userRegisterForm.phone,
|
||||
// city: userRegister.userRegisterForm.region,
|
||||
// password: userRegister.userRegisterForm.password,
|
||||
// smsCode: userRegister.userRegisterForm.smsCode,
|
||||
// captchaId: captchaId.value,
|
||||
// captchaText: userRegister.userRegisterForm.captcha,
|
||||
// province: userRegister.userRegisterForm.region,
|
||||
// }
|
||||
// authAPI.register(registerData).then(response => {
|
||||
// // 直接注册成功的情况
|
||||
// // setToken(response.data.token)
|
||||
// // setUser(response.data.user)
|
||||
// console.log(response);
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
}
|
||||
|
||||
// 手机验证码
|
||||
@@ -314,8 +326,22 @@
|
||||
// 获取手机验证码
|
||||
const getMsgCode = () => {
|
||||
// 校验手机号
|
||||
console.log("发送验证码");
|
||||
if (msgCodeRef.value.canGetCode) {
|
||||
console.log("发送验证码");
|
||||
captchaAPI.smsSend(userRegister.userRegisterForm.phone).then(res => {
|
||||
const result = res.json();
|
||||
if (result.success) {
|
||||
uni.showToast({
|
||||
title: '验证码发送成功,请查收短信',
|
||||
icon: 'success'
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: result.message || '发送失败,请重试',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
})
|
||||
msgCodeRef.value.start();
|
||||
} else {
|
||||
uni.showToast({
|
||||
@@ -434,7 +460,7 @@
|
||||
letter-spacing: -2%;
|
||||
text-align: center;
|
||||
color: #3781EF;
|
||||
|
||||
display: ruby;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user