From 4f941807dfea12538002eed1249b9d33a1467be3 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期四, 19 六月 2025 11:35:39 +0800
Subject: [PATCH] 报警模式

---
 src/views/deviceWindoes2.vue |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/views/deviceWindoes2.vue b/src/views/deviceWindoes2.vue
index eb75eea..189bb11 100644
--- a/src/views/deviceWindoes2.vue
+++ b/src/views/deviceWindoes2.vue
@@ -1532,7 +1532,7 @@
         <div class="dialog-footer">
           <el-button @click="centerDialogVisible = false">取消</el-button>
           <el-button @click="test">测试播报</el-button>
-          <el-button @click="playAlarm">测试报警</el-button>
+          <el-button @click="toggleAlarm">测试报警</el-button>
           <el-button type="primary" @click="saveSet"> 确认 </el-button>
           <el-button type="success" @click="shuaxin"> 刷新 </el-button>
         </div>
@@ -1684,12 +1684,19 @@
 // 创建 Audio 对象,指向 public 目录下的音频文件
 const alarmSound = new Audio(alertbaojin)
 
-// 播放报警声的方法
-const playAlarm = () => {
-  alarmSound.currentTime = 0 // 重置到开头,以便可以重复播放
-  alarmSound.play().catch((err) => {
-    console.error('播放失败:', err)
-  })
+// 控制播放状态的变量
+const isPlaying = ref(false)
+// 切换播放/暂停的方法
+const toggleAlarm = () => {
+  if (isPlaying.value) {
+    alarmSound.pause()
+  } else {
+    alarmSound.currentTime = 0 // 从头开始播放
+    alarmSound.play().catch((err) => {
+      console.error('播放失败:', err)
+    })
+  }
+  isPlaying.value = !isPlaying.value
 }
 // 语音播报
 import Speech from "speak-tts";
@@ -2138,7 +2145,8 @@
     if(centerDialogVisible3.value===false){
       centerDialogVisible3.value = true;
       关闭弹框警告();
-      播报警告文本(倒计时告警文本.value);
+      // 播报警告文本(倒计时告警文本.value);
+      toggleAlarm()
     }
   
   }else{
@@ -2283,6 +2291,7 @@
               倒计时告警文本.value = dataBody.倒计时?.提醒文本;
               关闭弹框警告();
               播报警告文本(倒计时告警文本.value);
+              toggleAlarm()
             } else if (倒计时.value <= -60) {
               centerDialogVisible3.value = false;
             }
@@ -2347,6 +2356,7 @@
   setTimeout(function () {
     console.log("30秒已过,关闭报警设置弹框。");
     centerDialogVisible3.value = false;
+    toggleAlarm()
     倒计时.value=-100
   }, 30000); // 30000 毫秒 = 30 秒
 };

--
Gitblit v1.8.0