feat: 启用短信验证码发送与登录功能,更新API路径并移除模拟逻辑。
This commit is contained in:
parent
b050b1c875
commit
7c64f0c76a
@ -8,9 +8,9 @@ export default {
|
|||||||
// 手机号
|
// 手机号
|
||||||
registerPhone: (data) => request.post('/app-user/register', data, { noNeedToken: true }),
|
registerPhone: (data) => request.post('/app-user/register', data, { noNeedToken: true }),
|
||||||
loginPhone: (data) => request.post('/app-user/login', data, { noNeedToken: true }),
|
loginPhone: (data) => request.post('/app-user/login', data, { noNeedToken: true }),
|
||||||
// 短信验证码(待后端实现)
|
// 短信验证码
|
||||||
sendVerifyCode: (data) => request.post('/app-user/send-verify-code', data, { noNeedToken: true }),
|
sendVerifyCode: (data) => request.post('/sms/send-code', data, { noNeedToken: true }),
|
||||||
loginWithVerifyCode: (data) => request.post('/app-user/login-with-code', data, { noNeedToken: true }),
|
loginWithVerifyCode: (data) => request.post('/sms/login', data, { noNeedToken: true }),
|
||||||
// pages
|
// pages
|
||||||
getIndustryList: () => request.get('/industry/list'),
|
getIndustryList: () => request.get('/industry/list'),
|
||||||
getHistoryList: (params) => request.get('/app-valuations/', { params }),
|
getHistoryList: (params) => request.get('/app-valuations/', { params }),
|
||||||
|
|||||||
@ -115,10 +115,7 @@ async function handleSendCode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO: 调用发送验证码接口
|
await api.sendVerifyCode({ phone })
|
||||||
// await api.sendVerifyCode({ phone })
|
|
||||||
|
|
||||||
// 模拟发送成功
|
|
||||||
$message.success('验证码已发送')
|
$message.success('验证码已发送')
|
||||||
|
|
||||||
// 开始倒计时
|
// 开始倒计时
|
||||||
@ -131,7 +128,7 @@ async function handleSendCode() {
|
|||||||
}
|
}
|
||||||
}, 1000)
|
}, 1000)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
$message.error('验证码发送失败,请重试')
|
// error is handled by interceptor usually, but we can catch specific ones if needed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,32 +146,22 @@ async function handleLogin() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 等待后端接口完成后再启用验证码验证
|
if (!verifyCode) {
|
||||||
// if (!verifyCode) {
|
$message.warning('请输入验证码')
|
||||||
// $message.warning('请输入验证码')
|
return
|
||||||
// return
|
}
|
||||||
// }
|
|
||||||
//
|
if (verifyCode.length < 4) {
|
||||||
// if (verifyCode.length < 4) {
|
$message.warning('请输入完整的验证码')
|
||||||
// $message.warning('请输入完整的验证码')
|
return
|
||||||
// return
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO: 调用登录接口,传入手机号和验证码
|
const res = await api.loginWithVerifyCode({ phone, code: verifyCode })
|
||||||
// const res = await api.loginWithVerifyCode({ phone, verifyCode })
|
if (res.data?.access_token) {
|
||||||
// setToken(res.access_token)
|
setToken(res.data.access_token)
|
||||||
|
|
||||||
// 模拟登录成功(暂时使用原有的注册+登录逻辑)
|
|
||||||
await api.registerPhone({ phone })
|
|
||||||
.then(res => {
|
|
||||||
return api.loginPhone({ phone, password: phone.slice(5, 11) })
|
|
||||||
})
|
|
||||||
.catch(res => {
|
|
||||||
if (res.error && res.error.access_token) {
|
|
||||||
setToken(res.error.access_token)
|
|
||||||
localStorage.setItem('phone', phone)
|
localStorage.setItem('phone', phone)
|
||||||
|
|
||||||
if (query.redirect) {
|
if (query.redirect) {
|
||||||
@ -184,10 +171,11 @@ async function handleLogin() {
|
|||||||
} else {
|
} else {
|
||||||
router.push('/home')
|
router.push('/home')
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$message.error('登录失败:未获取到token')
|
||||||
}
|
}
|
||||||
})
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
$message.error('登录失败,请重试')
|
console.error(error)
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user