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 }),
|
||||
loginPhone: (data) => request.post('/app-user/login', data, { noNeedToken: true }),
|
||||
// 短信验证码(待后端实现)
|
||||
sendVerifyCode: (data) => request.post('/app-user/send-verify-code', data, { noNeedToken: true }),
|
||||
loginWithVerifyCode: (data) => request.post('/app-user/login-with-code', data, { noNeedToken: true }),
|
||||
// 短信验证码
|
||||
sendVerifyCode: (data) => request.post('/sms/send-code', data, { noNeedToken: true }),
|
||||
loginWithVerifyCode: (data) => request.post('/sms/login', data, { noNeedToken: true }),
|
||||
// pages
|
||||
getIndustryList: () => request.get('/industry/list'),
|
||||
getHistoryList: (params) => request.get('/app-valuations/', { params }),
|
||||
|
||||
@ -115,10 +115,7 @@ async function handleSendCode() {
|
||||
}
|
||||
|
||||
try {
|
||||
// TODO: 调用发送验证码接口
|
||||
// await api.sendVerifyCode({ phone })
|
||||
|
||||
// 模拟发送成功
|
||||
await api.sendVerifyCode({ phone })
|
||||
$message.success('验证码已发送')
|
||||
|
||||
// 开始倒计时
|
||||
@ -131,7 +128,7 @@ async function handleSendCode() {
|
||||
}
|
||||
}, 1000)
|
||||
} catch (error) {
|
||||
$message.error('验证码发送失败,请重试')
|
||||
// error is handled by interceptor usually, but we can catch specific ones if needed
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,45 +146,36 @@ async function handleLogin() {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: 等待后端接口完成后再启用验证码验证
|
||||
// if (!verifyCode) {
|
||||
// $message.warning('请输入验证码')
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// if (verifyCode.length < 4) {
|
||||
// $message.warning('请输入完整的验证码')
|
||||
// return
|
||||
// }
|
||||
if (!verifyCode) {
|
||||
$message.warning('请输入验证码')
|
||||
return
|
||||
}
|
||||
|
||||
if (verifyCode.length < 4) {
|
||||
$message.warning('请输入完整的验证码')
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
|
||||
try {
|
||||
// TODO: 调用登录接口,传入手机号和验证码
|
||||
// const res = await api.loginWithVerifyCode({ phone, verifyCode })
|
||||
// setToken(res.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)
|
||||
|
||||
if (query.redirect) {
|
||||
const path = query.redirect
|
||||
Reflect.deleteProperty(query, 'redirect')
|
||||
router.push({ path, query })
|
||||
} else {
|
||||
router.push('/home')
|
||||
}
|
||||
}
|
||||
})
|
||||
const res = await api.loginWithVerifyCode({ phone, code: verifyCode })
|
||||
if (res.data?.access_token) {
|
||||
setToken(res.data.access_token)
|
||||
localStorage.setItem('phone', phone)
|
||||
|
||||
if (query.redirect) {
|
||||
const path = query.redirect
|
||||
Reflect.deleteProperty(query, 'redirect')
|
||||
router.push({ path, query })
|
||||
} else {
|
||||
router.push('/home')
|
||||
}
|
||||
} else {
|
||||
$message.error('登录失败:未获取到token')
|
||||
}
|
||||
} catch (error) {
|
||||
$message.error('登录失败,请重试')
|
||||
console.error(error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user