import React, { useState } from 'react' import { api } from '../services/api' import './Login.css' const Login = ({ onLoggedIn }) => { const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [busy, setBusy] = useState(false) const [error, setError] = useState('') const doLogin = async () => { setBusy(true) setError('') try { await api.login(username, password) if (typeof onLoggedIn === 'function') await onLoggedIn() } catch (e) { setError(e?.message || '登录失败') } finally { setBusy(false) } } return (