import { View, Input, Button, Text, Image } from '@tarojs/components' import { useState } from 'react' import Taro from '@tarojs/taro' import { authManager } from '../../utils/auth' import './index.css' export default function Login() { const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [loading, setLoading] = useState(false) const handleLogin = async () => { if (!username || !password) { Taro.showToast({ title: '请输入用户名和密码', icon: 'none' }) return } setLoading(true) try { const user = await authManager.login(username, password) Taro.showToast({ title: '登录成功', icon: 'success' }) // 登录成功后跳转到首页 setTimeout(() => { Taro.switchTab({ url: '/pages/index/index' }) }, 1500) } catch (error: any) { Taro.showToast({ title: error.message || '登录失败', icon: 'none' }) } finally { setLoading(false) } } const goToRegister = () => { Taro.navigateTo({ url: '/pages/register/index' }) } return ( 欢迎回来 请使用您的账号登录 用户名 setUsername(e.detail.value)} maxlength={20} /> 密码 setPassword(e.detail.value)} maxlength={20} /> 还没有账号? 立即注册 登录即表示您同意我们的 用户协议 隐私政策 ) }