Browse Source

方向错误时,音频提示

feature/rail
zhangjiming 5 months ago
parent
commit
220f00c169
  1. BIN
      public/audio/alert_left.mp3
  2. 25
      src/pages/measure/components/MeasureAction.tsx
  3. 3
      src/services/wsTypes.ts

BIN
public/audio/alert_left.mp3

25
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);

3
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";
// };

Loading…
Cancel
Save