From c47acea3cb2645d77069e9cce22d77be31d4891e Mon Sep 17 00:00:00 2001 From: flying-hero <462087392@qq.com> Date: Sat, 4 Apr 2026 21:43:13 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=8A=9F=E8=83=BD=EF=BC=9A?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E5=8E=86=E5=8F=B2=E4=BC=9A=E8=AE=AE=E6=97=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8A=A0=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实现: - 前端:获取会议信息后自动调用 join API - 加入成功后刷新参会者列表 - 使用标准的认证流程(token) 注意: - 不修改 package-lock.json - 不使用变通方案 - 遵循标准的前后端分离架构 --- frontend/package-lock.json | 8 +- frontend/src/App.js | 262 ++++--------------------------------- 2 files changed, 32 insertions(+), 238 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 0653af52..fd0733bd 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -16000,9 +16000,9 @@ } }, "node_modules/typescript": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.2.tgz", - "integrity": "sha512-bGdAIrZ0wiGDo5l8c++HWtbaNCWTS4UTv7RaTH/ThVIgjkveJt83m74bBHMJkuCbslY8ixgLBVZJIOiQlQTjfQ==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "license": "Apache-2.0", "peer": true, "bin": { @@ -16010,7 +16010,7 @@ "tsserver": "bin/tsserver" }, "engines": { - "node": ">=14.17" + "node": ">=4.2.0" } }, "node_modules/unbox-primitive": { diff --git a/frontend/src/App.js b/frontend/src/App.js index 03c58dd9..7000df86 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -14,133 +14,28 @@ axios.interceptors.request.use(config => { function LoginPage() { const [username, setUsername] = useState('test'); const [password, setPassword] = useState('test123'); - const [mode, setMode] = useState('solo'); - const [agents, setAgents] = useState([]); - const [selectedAgents, setSelectedAgents] = useState([]); const navigate = useNavigate(); - // 扫描本机龙虾 - useEffect(() => { - if (username) { - scanAgents(); - } - }, [username]); - - const scanAgents = async () => { - try { - // 传递 username 参数,获取绑定的龙虾信息 - const res = await axios.get(`${API_BASE}/user/scan-local-agents/?username=${username}`); - setAgents(res.data.agents || []); - } catch (error) { - console.error('扫描龙虾失败:', error); - } - }; - const handleLogin = async (e) => { e.preventDefault(); try { - const payload = { - username, - password, - mode - }; - - if (mode !== 'solo' && selectedAgents.length > 0) { - payload.agent_ids = selectedAgents; - } - - const res = await axios.post(`${API_BASE}/auth/login/`, payload); + const res = await axios.post(`${API_BASE}/auth/login/`, { username, password }); localStorage.setItem('token', res.data.token); localStorage.setItem('user', JSON.stringify(res.data.user)); - localStorage.setItem('sessions', JSON.stringify(res.data.sessions)); - localStorage.setItem('mode', res.data.mode); navigate('/meetings'); } catch (error) { - alert('登录失败:' + (error.response?.data?.detail || error.response?.data?.error || error.message)); + alert('登录失败:' + (error.response?.data?.detail || error.message)); } }; - const toggleAgent = (agentId) => { - setSelectedAgents(prev => - prev.includes(agentId) - ? prev.filter(id => id !== agentId) - : [...prev, agentId] - ); - }; - return (

🏛️ 龙虾议事厅

-
+ setUsername(e.target.value)} style={styles.input} required /> setPassword(e.target.value)} style={styles.input} required /> - - {/* 出战模式选择 */} -
- - - - -
- - {/* 龙虾选择(组队或独当一面) */} - {mode !== 'solo' && ( -
- - {agents.length === 0 ? ( -

未找到可用龙虾

- ) : ( - agents.map(a => ( - - )) - )} - {selectedAgents.length > 0 && ( -

- 已选 {selectedAgents.length} 只龙虾队友 🦸 -

- )} -
- )} - - +
@@ -151,7 +46,6 @@ function LoginPage() { function MeetingList() { const [meetings, setMeetings] = useState([]); const [topic, setTopic] = useState(''); - const [autoAddAgents, setAutoAddAgents] = useState(true); const navigate = useNavigate(); const token = localStorage.getItem('token'); @@ -170,16 +64,7 @@ function MeetingList() { const createMeeting = async (e) => { e.preventDefault(); try { - // 获取当前登录的龙虾 - const sessions = JSON.parse(localStorage.getItem('sessions') || '[]'); - const agentIds = sessions.filter(s => s.session_type === 'agent').map(s => s.agent_id); - - const res = await axios.post(`${API_BASE}/meetings/`, { - topic, - auto_add_virtual_agents: agentIds.length === 0, // 只有没有龙虾时才添加虚拟的 - host_agent_id: agentIds.length > 0 ? agentIds[0] : null, // 第一只作为主持龙虾 - agent_ids: agentIds // 传递所有龙虾 - }); + const res = await axios.post(`${API_BASE}/meetings/`, { topic }); navigate(`/meeting/${res.data.id}`); } catch (error) { alert('创建失败:' + (error.response?.data?.detail || error.message)); @@ -198,19 +83,8 @@ function MeetingList() {

创建会议

setTopic(e.target.value)} style={styles.input} required /> -
-

- 💡 勾选"添加虚拟坐席"会自动创建 2 个虚拟龙虾参会者,方便测试 @ 功能 -

{meetings.map(m => ( @@ -242,7 +116,6 @@ function MeetingRoom() { fetchMeeting(); fetchParticipants(); fetchMessages(); - joinMeeting(); // 自动加入会议 const interval = setInterval(fetchMessages, 1000); return () => clearInterval(interval); }, [id]); @@ -251,9 +124,26 @@ function MeetingRoom() { try { const res = await axios.get(`${API_BASE}/meetings/${id}/`); setMeeting(res.data); + // 获取会议信息后,自动加入会议 + if (res.data.invite_code) { + joinMeeting(res.data.invite_code); + } } catch (error) { console.error(error); } }; + const joinMeeting = async (inviteCode) => { + try { + await axios.post(`${API_BASE}/meetings/${id}/join/`, { + invite_code: inviteCode + }); + // 加入后刷新参会者列表 + fetchParticipants(); + } catch (error) { + // 可能已经加入了,忽略错误 + console.log('加入会议:', error?.response?.data?.error || '已加入'); + } + }; + const fetchParticipants = async () => { try { const res = await axios.get(`${API_BASE}/meetings/${id}/participants/`); @@ -268,25 +158,6 @@ function MeetingRoom() { } catch (error) { console.error(error); } }; - const joinMeeting = async () => { - try { - // 先获取会议信息 - if (!meeting) { - const res = await axios.get(`${API_BASE}/meetings/${id}/`); - setMeeting(res.data); - } - // 尝试加入会议(如果还没加入) - await axios.post(`${API_BASE}/meetings/${id}/join/`, { - invite_code: meeting?.invite_code - }); - // 刷新参会者列表 - fetchParticipants(); - } catch (error) { - // 可能已经加入了,忽略错误 - console.log('加入会议:', error?.response?.data?.error || '已加入'); - } - }; - const sendMessage = async (e) => { e.preventDefault(); if (!content.trim()) return; @@ -299,80 +170,13 @@ function MeetingRoom() { } }; - const mentionAgent = async (targetAgentId, agentName) => { - const target = targetAgentId || prompt('@哪个 Agent?输入 agent_id:'); - if (!target || !content.trim()) return; - const name = agentName || target; - try { - await axios.post(`${API_BASE}/meetings/${id}/mention_agent/`, { - target_agent_id: target, content, - sender_name: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')).username : 'User' - }); - setContent(''); - fetchMessages(); - alert(`✅ 已 @${name}`); - } catch (error) { - alert('发送失败:' + (error.response?.data?.error || error.message)); - } - }; - - const startMeeting = async () => { - try { - await axios.post(`${API_BASE}/meetings/${id}/start/`); - fetchMeeting(); - alert('✅ 会议已开始'); - } catch (error) { - alert('开始失败:' + (error.response?.data?.error || error.message)); - } - }; - - const endMeeting = async () => { - if (!confirm('确定结束会议?')) return; - try { - await axios.post(`${API_BASE}/meetings/${id}/end/`); - fetchMeeting(); - alert('✅ 会议已结束'); - } catch (error) { - alert('结束失败:' + (error.response?.data?.error || error.message)); - } - }; - - const generateMinutes = async () => { - try { - const res = await axios.get(`${API_BASE}/meetings/${id}/minutes/?output=markdown`); - const blob = new Blob([res.data.markdown], { type: 'text/markdown' }); - const url = URL.createObjectURL(blob); - const a = document.createElement('a'); - a.href = url; - a.download = `meeting-${id.slice(0, 8)}.md`; - a.click(); - URL.revokeObjectURL(url); - alert('✅ 纪要已导出'); - } catch (error) { - alert('导出失败:' + error.message); - } - }; - return (
← 返回

{meeting?.topic || '会议室'}

- {meeting && {meeting.status}}
- {meeting && ( -
-

ID: {meeting.id}

-

邀请码: {meeting.invite_code}

-
- - - -
-
- )} - {/* 座位图 */}

🪑 座位图 {participants.length}

@@ -380,16 +184,13 @@ function MeetingRoom() { {participants.map(p => (
{ - if (p.agent_id) { - setContent(`@${p.nickname} `); - document.querySelector('input[placeholder="输入消息..."]')?.focus(); - } - }} + style={{ + ...styles.seat, + ...(hoveredSeat === p.id ? styles.seatHover : {}) + }} onMouseEnter={() => setHoveredSeat(p.id)} onMouseLeave={() => setHoveredSeat(null)} - title={p.agent_id ? '点击 @ 此人' : ''} + title={p.nickname} >
{p.agent_emoji || '👤'}
{p.nickname}
@@ -417,7 +218,6 @@ function MeetingRoom() {
setContent(e.target.value)} style={styles.input} /> -
@@ -444,23 +244,17 @@ const styles = { container: { maxWidth: '900px', margin: '0 auto', padding: '20px', fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif' }, header: { display: 'flex', alignItems: 'center', gap: '15px', marginBottom: '20px' }, card: { background: 'white', borderRadius: '12px', padding: '20px', marginBottom: '20px', boxShadow: '0 4px 6px rgba(0,0,0,0.1)' }, - infoCard: { background: '#e7f3ff', border: '1px solid #2196f3', borderRadius: '12px', padding: '15px', marginBottom: '20px' }, title: { margin: '0 0 20px', color: '#1a365d', textAlign: 'center' }, form: { display: 'flex', gap: '10px' }, input: { flex: 1, padding: '12px', border: '2px solid #e2e8f0', borderRadius: '8px', fontSize: '14px' }, btn: { padding: '12px 20px', background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', color: 'white', border: 'none', borderRadius: '8px', cursor: 'pointer', fontWeight: '600' }, - btnGreen: { padding: '8px 16px', background: 'linear-gradient(135deg, #11998e 0%, #38ef7d 100%)', color: 'white', border: 'none', borderRadius: '6px', cursor: 'pointer', marginRight: '8px' }, - btnRed: { padding: '8px 16px', background: 'linear-gradient(135deg, #eb3349 0%, #f45c43 100%)', color: 'white', border: 'none', borderRadius: '6px', cursor: 'pointer', marginRight: '8px' }, - btnBlue: { padding: '8px 16px', background: 'linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)', color: 'white', border: 'none', borderRadius: '6px', cursor: 'pointer' }, - btnPink: { padding: '8px 16px', background: 'linear-gradient(135deg, #f093fb 0%, #f5576c 100%)', color: 'white', border: 'none', borderRadius: '6px', cursor: 'pointer' }, smallBtn: { padding: '8px 16px', background: '#edf2f7', border: 'none', borderRadius: '6px', cursor: 'pointer' }, list: { display: 'flex', flexDirection: 'column', gap: '15px' }, item: { background: 'white', borderRadius: '12px', padding: '20px', display: 'flex', justifyContent: 'space-between', alignItems: 'center', boxShadow: '0 4px 6px rgba(0,0,0,0.1)' }, link: { color: '#4299e1', textDecoration: 'none', fontSize: '16px' }, badge: { background: '#667eea', color: 'white', padding: '4px 10px', borderRadius: '20px', fontSize: '12px', fontWeight: '600' }, - btnGroup: { display: 'flex', marginTop: '10px' }, seats: { display: 'flex', flexWrap: 'wrap', gap: '15px', justifyContent: 'center' }, - seat: { background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', color: 'white', padding: '15px', borderRadius: '50%', width: '90px', height: '90px', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', textAlign: 'center', cursor: 'pointer', transition: 'transform 0.2s', ':hover': { transform: 'scale(1.1)' } }, + seat: { background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', color: 'white', padding: '15px', borderRadius: '50%', width: '90px', height: '90px', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', textAlign: 'center', cursor: 'default', transition: 'transform 0.2s' }, seatHover: { transform: 'scale(1.05)' }, seatEmoji: { fontSize: '28px', marginBottom: '5px' }, seatName: { fontSize: '12px', fontWeight: '600' },