登录注册功能

This commit is contained in:
Ken 2025-03-12 11:43:42 +08:00
parent 9ae23571be
commit e0768dace1
2 changed files with 28 additions and 14 deletions

View file

@ -75,6 +75,16 @@ export default {
}) })
.fail((err) => { // 添加错误参数 .fail((err) => { // 添加错误参数
}).send()
}, // 登录
register(registerForm, callback) {
RequestService.sendRequest().url(`${getServiceUrl()}/api/v1/user/register`).method('POST')
.data(registerForm)
.success((res) => {
RequestService.clearRequestTime()
callback(res)
})
.fail(() => {
}).send() }).send()
}, },
} }

View file

@ -138,21 +138,25 @@ export default {
showDanger('验证码不能为空') showDanger('验证码不能为空')
return return
} }
Api.user.register({
try {
await api.post('/user/register', {
username: this.form.username, username: this.form.username,
password: this.form.password, password: this.form.password,
captcha: this.form.captcha, captcha: this.form.captcha,
uuid: this.captchaUuid uuid: this.captchaUuid
}) }).then(response => {
if (response.data.code === 200) {
showSuccess('注册成功!') showSuccess('注册成功!')
goToPage('/login') goToPage('/login')
} catch (error) { } else {
const msg = error.response?.data?.msg || '注册失败' showDanger(response.data.msg || '注册失败')
showDanger(msg)
this.fetchCaptcha() this.fetchCaptcha()
} }
}).catch(error => {
const msg = error.response?.data?.msg || '注册失败'
showDanger(msg)
this.fetchCaptcha() // 自动刷新验证码
});
}, },
goToLogin() { goToLogin() {