diff --git a/frontend/src/App.js b/frontend/src/App.js index bfd39190..54820a20 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -14,17 +14,49 @@ axios.interceptors.request.use(config => { function LoginPage() { const [username, setUsername] = useState('test'); const [password, setPassword] = useState('test123'); + const [loginMode, setLoginMode] = useState('human_only'); + const [agents, setAgents] = useState([]); + const [selectedAgent, setSelectedAgent] = useState(''); const navigate = useNavigate(); + // 扫描本机龙虾 + useEffect(() => { + scanAgents(); + }, []); + + const scanAgents = async () => { + try { + const res = await axios.get(`${API_BASE}/user/scan-local-agents/`); + setAgents(res.data.agents || []); + if (res.data.agents?.length > 0) { + setSelectedAgent(res.data.agents[0].agent_id); + } + } catch (error) { + console.error('扫描龙虾失败:', error); + } + }; + const handleLogin = async (e) => { e.preventDefault(); try { - const res = await axios.post(`${API_BASE}/auth/login/`, { username, password }); + const payload = { + username, + password, + login_mode: loginMode + }; + + if (loginMode !== 'human_only' && selectedAgent) { + payload.selected_agent_id = selectedAgent; + } + + const res = await axios.post(`${API_BASE}/auth/login/`, payload); localStorage.setItem('token', res.data.token); localStorage.setItem('user', JSON.stringify(res.data.user)); + localStorage.setItem('sessions', JSON.stringify(res.data.sessions)); + localStorage.setItem('login_mode', res.data.login_mode); navigate('/meetings'); } catch (error) { - alert('登录失败:' + (error.response?.data?.detail || error.message)); + alert('登录失败:' + (error.response?.data?.detail || error.response?.data?.error || error.message)); } }; @@ -32,9 +64,67 @@ function LoginPage() {

🏛️ 龙虾议事厅

-
+ setUsername(e.target.value)} style={styles.input} required /> setPassword(e.target.value)} style={styles.input} required /> + + {/* 身份模式选择 */} +
+ + + + +
+ + {/* 龙虾选择 */} + {loginMode !== 'human_only' && ( +
+ + +
+ )} +