diff --git a/src/components/AiChatPanel.jsx b/src/components/AiChatPanel.jsx index bf7e1f1..3898177 100644 --- a/src/components/AiChatPanel.jsx +++ b/src/components/AiChatPanel.jsx @@ -184,6 +184,22 @@ export default function AiChatPanel() { }); }, [send]); + // MQTT 调度器 → AI 页操作:输入并发送 / 选择预设问题 + useEffect(() => { + const onAiAction = (e) => { + const { type, text, index } = e.detail || {}; + if (type === 'input' && text && String(text).trim()) { + setInput(String(text).trim()); + void send(String(text).trim()); + } else if (type === 'preset') { + const q = QUICK_QUESTIONS[Number(index)]; + if (q) void send(q); + } + }; + window.addEventListener('dpm:ai-action', onAiAction); + return () => window.removeEventListener('dpm:ai-action', onAiAction); + }, [send]); + const toggleVoice = useCallback(() => { if (voiceStateRef.current === 'recording') { const rec = recorderRef.current; diff --git a/src/components/ParkSidePanel.jsx b/src/components/ParkSidePanel.jsx index c0ef7af..d9c72da 100644 --- a/src/components/ParkSidePanel.jsx +++ b/src/components/ParkSidePanel.jsx @@ -85,6 +85,28 @@ export default function ParkSidePanel() { const list = COMPANIES.filter((c) => c.zone === activeZone); + // MQTT 调度器 → 企业面板操作:切换分区 / 切换展示企业 + useEffect(() => { + const onAiAction = (e) => { + const { type, zone, action } = e.detail || {}; + if (type === 'zone' && zone) { + const z = String(zone); + if (COMPANIES.some((c) => c.zone === z)) setActiveZone(z); + return; + } + if (type === 'company' && (action === 'next' || action === 'prev')) { + const cur = COMPANIES.filter((c) => c.zone === activeZone); + if (!cur.length) return; + const idx = cur.findIndex((c) => selected && c.room === selected.room); + const base = idx >= 0 ? idx : 0; + const n = (base + (action === 'next' ? 1 : -1) + cur.length) % cur.length; + setSelected(cur[n]); + } + }; + window.addEventListener('dpm:ai-action', onAiAction); + return () => window.removeEventListener('dpm:ai-action', onAiAction); + }, [activeZone, selected]); + return (