diff --git a/src/components/GlobalVision.jsx b/src/components/GlobalVision.jsx index e66643d..839c5a1 100644 --- a/src/components/GlobalVision.jsx +++ b/src/components/GlobalVision.jsx @@ -31,6 +31,18 @@ export default function GlobalVision() { window.dispatchEvent(new CustomEvent('dpm:hand-track', { detail: { hands: vision.hands } })); }, [vision.hands]); + // 视觉识别状态广播:dpm:vision-status(页眉图标展示全部视觉相关状态) + useEffect(() => { + window.dispatchEvent(new CustomEvent('dpm:vision-status', { + detail: { + status: vision.status, // off|loading|detecting|facing|triggered|silent|error + cameraOn: vision.cameraOn, + gesture: vision.gesture, // raise 等最近一次手势 + faces: vision.faces, + }, + })); + }, [vision.status, vision.cameraOn, vision.gesture, vision.faces]); + return ( <> {/* 摄像头驱动(隐藏,仅供全局抽帧识别) */} diff --git a/src/components/PageHeader.jsx b/src/components/PageHeader.jsx index 6db3574..1fc4036 100644 --- a/src/components/PageHeader.jsx +++ b/src/components/PageHeader.jsx @@ -24,6 +24,7 @@ export default function PageHeader() { const [now, setNow] = useState(new Date()); const [aboutOpen, setAboutOpen] = useState(false); const [gestureHit, setGestureHit] = useState(false); // 识别到手势 → 惊喜图标 3s + const [vision, setVision] = useState({ status: 'off', cameraOn: false, gesture: null }); // 视觉识别状态 const pageIdx = usePageIndex(); const gestureTimer = useRef(null); @@ -32,7 +33,7 @@ export default function PageHeader() { return () => clearInterval(iv); }, []); - // 全局手势事件 → 右上角状态图标(默认灰色探索 → 识别到手势变绿色惊喜) + // 全局手势事件 → 惊喜图标 3s useEffect(() => { const onGesture = (e) => { if (!e.detail || !e.detail.type) return; @@ -47,6 +48,17 @@ export default function PageHeader() { }; }, []); + // 视觉识别状态(GlobalVision 广播):off/loading/detecting/facing/triggered/silent/error + useEffect(() => { + const onStatus = (e) => setVision(e.detail || {}); + window.addEventListener('dpm:vision-status', onStatus); + return () => window.removeEventListener('dpm:vision-status', onStatus); + }, []); + + // 图标状态:手势(绿) > 视觉识别中(浅蓝) > 默认(灰) + const visionActive = vision.cameraOn && vision.status !== 'error' && vision.status !== 'off'; + const visionError = vision.status === 'error'; + const dateStr = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`; const week = ['日', '一', '二', '三', '四', '五', '六'][now.getDay()]; const timeStr = now.toLocaleTimeString('zh-CN', { hour12: false }); @@ -101,9 +113,9 @@ export default function PageHeader() { {status}