diff --git a/src/passport/login.tsx b/src/passport/login.tsx index 9cc2a3c..76103cd 100644 --- a/src/passport/login.tsx +++ b/src/passport/login.tsx @@ -1,13 +1,83 @@ import {useEffect, useState} from "react"; import Taro from '@tarojs/taro' import {Input, Radio, Button} from '@nutui/nutui-react-taro' +import {loginBySms} from '@/api/passport/login' const Login = () => { const [isAgree, setIsAgree] = useState(false) + const [phone, setPhone] = useState('') + const [password, setPassword] = useState('') + const [loading, setLoading] = useState(false) + const reload = () => { Taro.hideTabBar() } + // 处理登录 + const handleLogin = async () => { + if (!isAgree) { + Taro.showToast({ + title: '请先同意服务协议', + icon: 'none' + }) + return + } + + if (!phone || phone.trim() === '') { + Taro.showToast({ + title: '请输入手机号', + icon: 'none' + }) + return + } + + if (!password || password.trim() === '') { + Taro.showToast({ + title: '请输入密码', + icon: 'none' + }) + return + } + + // 验证手机号格式 + const phoneRegex = /^1[3-9]\d{9}$/ + if (!phoneRegex.test(phone)) { + Taro.showToast({ + title: '请输入正确的手机号', + icon: 'none' + }) + return + } + + try { + setLoading(true) + await loginBySms({ + phone: phone, + code: password + }) + + Taro.showToast({ + title: '登录成功', + icon: 'success' + }) + + // 延迟跳转到首页 + setTimeout(() => { + Taro.reLaunch({ + url: '/pages/index/index' + }) + }, 1500) + } catch (error: any) { + console.error('登录失败:', error) + Taro.showToast({ + title: error.message || '登录失败,请重试', + icon: 'none' + }) + } finally { + setLoading(false) + } + } + useEffect(() => { reload() }, []) @@ -19,11 +89,23 @@ const Login = () => { <>
- + setPhone(val)} + style={{backgroundColor: '#ffffff', borderRadius: '8px'}} + />
- + setPassword(val)} + style={{backgroundColor: '#ffffff', borderRadius: '8px'}} + />
{/*
*/} {/* { {/* onClick={() => Taro.navigateTo({url: '/passport/register'})}>立即注册*/} {/*
*/}
- +
{/*
*/} {/* */}