import React, { useState } from 'react'; import { View, Text, TextInput, TouchableOpacity, StyleSheet, ActivityIndicator, Alert } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import { theme } from '../theme'; import * as API from '../api'; interface LoginScreenProps { onLoginSuccess: () => void; onBack: () => void; } export const LoginScreen: React.FC = ({ onLoginSuccess, onBack }) => { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const handleLogin = async () => { if (!username.trim() || !password.trim()) { Alert.alert('提示', '请输入账号和密码'); return; } setLoading(true); try { const result = await API.login(username.trim(), password); if (result.ok) { Alert.alert('登录成功', `欢迎,${result.username}`, [ { text: '好的', onPress: onLoginSuccess } ]); } else { Alert.alert('登录失败', result.error || '账号或密码错误'); } } catch (error) { Alert.alert('错误', '登录请求失败,请检查网络'); } finally { setLoading(false); } }; return ( ← 返回 观空禅音 账号 密码 {loading ? ( ) : ( 登录 )} 登录后可同步歌单选择、播放进度等配置到云端,跨设备使用。 ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: theme.colors.background, }, header: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: theme.spacing.md, paddingVertical: theme.spacing.sm, }, backBtn: { padding: theme.spacing.xs, }, backText: { fontSize: 15, color: theme.colors.primary, }, title: { flex: 1, textAlign: 'center', fontSize: 18, fontWeight: '600', color: theme.colors.text, marginRight: 40, }, form: { paddingHorizontal: theme.spacing.xl, paddingTop: theme.spacing.xl, }, label: { fontSize: 14, color: theme.colors.textSecondary, marginBottom: 6, }, input: { backgroundColor: theme.colors.surface, borderRadius: 8, paddingHorizontal: theme.spacing.md, paddingVertical: theme.spacing.sm, fontSize: 16, color: theme.colors.text, marginBottom: theme.spacing.md, borderWidth: 1, borderColor: theme.colors.border, }, loginBtn: { backgroundColor: theme.colors.primary, borderRadius: 8, paddingVertical: theme.spacing.sm, alignItems: 'center', marginTop: theme.spacing.md, }, loginBtnDisabled: { opacity: 0.6, }, loginBtnText: { fontSize: 16, fontWeight: '600', color: '#fff', }, hint: { fontSize: 13, color: theme.colors.textSecondary, marginTop: theme.spacing.lg, textAlign: 'center', lineHeight: 20, }, });