diff --git a/public/audio/alert_left.mp3 b/public/audio/alert_left.mp3 new file mode 100644 index 0000000..f597e87 Binary files /dev/null and b/public/audio/alert_left.mp3 differ diff --git a/src/pages/measure/components/MeasureAction.tsx b/src/pages/measure/components/MeasureAction.tsx index 57688ed..ab06787 100644 --- a/src/pages/measure/components/MeasureAction.tsx +++ b/src/pages/measure/components/MeasureAction.tsx @@ -92,7 +92,6 @@ export default function MeasureAction() { }); }; - // 开始/重新测量按钮点击事件 const onStart = () => { if (startBtnText === "新测量") { @@ -168,9 +167,7 @@ export default function MeasureAction() { /** ----------------------- WebSocket 消息处理 ----------------------- **/ useEffect(() => { // 处理任务状态消息 - const handleStateMessage = (state: MeasureState["data"]) => { - - }; + const handleStateMessage = (state: MeasureState["data"]) => {}; // 处理事件消息 const handleEventMessage = (type: TaskState["data"]) => { @@ -236,6 +233,22 @@ export default function MeasureAction() { console.error("播放音频时出错:", err); }); break; + case "WRONG_SIDE": + const audio5 = new Audio("/audio/alert_left.mp3"); + // 播放音频 + audio5 + .play() + .then(() => { + console.log("音频开始播放"); + }) + .catch(err => { + console.error("播放音频时出错:", err); + }); + // 把状态全部置灰 + updated.forEach(u => (u.color = "h")); + // 调用重新测量 + onStart(); + break; default: break; } @@ -255,8 +268,8 @@ export default function MeasureAction() { } }; - const subscription = wsClient.dataOb.subscribe((data) => { - if ( data.path === "/api/measurement-task/get-task-state") { + const subscription = wsClient.dataOb.subscribe(data => { + if (data.path === "/api/measurement-task/get-task-state") { handleStateMessage(data.data); } else if (data.path === "/api/measurement-task/event") { handleEventMessage(data.data); diff --git a/src/services/wsTypes.ts b/src/services/wsTypes.ts index 3a3ee86..699f8a4 100644 --- a/src/services/wsTypes.ts +++ b/src/services/wsTypes.ts @@ -11,7 +11,8 @@ export type TaskState = { | "FINISH_RECORD_LEFT" | "END_RECORD_SIG" | "END_RECORD" - | "START_RECORD_RIGHT"; + | "START_RECORD_RIGHT" + | "WRONG_SIDE"; // data: { // event: "START_RECORD_SIG" | "END_RECORD_SIG" | "FINISHED" | "START_RECORD_LEFT" | "FINISH_RECORD_RIGHT" | "FINISH_RECORD" | "FINISH_RECORD_LEFT" | "END_RECORD_SIG" | "END_RECORD" | "START_RECORD_RIGHT"; // };