diff --git a/src/components/alarm/commonAlarm.vue b/src/components/alarm/commonAlarm.vue index b12fbb3..9884ed7 100644 --- a/src/components/alarm/commonAlarm.vue +++ b/src/components/alarm/commonAlarm.vue @@ -35,8 +35,8 @@ watch( (val) => { if (val.length) { const alarmType = val[0].alert_type; - playAlarmMusic(alarmType); alarm(alarmType); + playAlarmMusic(alarmType); } } ); @@ -69,18 +69,14 @@ function playAlarmMusic(type: number) { } //不关闭弹框,每3分钟播放一次报警音乐 -function timingPlayAlarmMusic( - dialog: DialogChainObject, - timer: string | number | NodeJS.Timeout | undefined -) { - clearTimeout(timer); - timer = setTimeout(() => { - if (dialogInstance.length) { - for (let i = 0; i < dialogInstance.length; i++) { - if (dialogInstance[i].show && dialogInstance[i].dialog == dialog) { - playAlarmMusic(dialogInstance[i].alarmType); - timingPlayAlarmMusic(dialog, timer); - } +function timingPlayAlarmMusic(dialog: DialogChainObject) { + const timerIndex = dialogInstance.findIndex((item) => item.dialog == dialog); + clearTimeout(dialogInstance[timerIndex].timer); + dialogInstance[timerIndex].timer = setTimeout(() => { + for (let i = 0; i < dialogInstance.length; i++) { + if (dialogInstance[i].show && dialogInstance[i].dialog == dialog) { + playAlarmMusic(dialogInstance[i].alarmType); + timingPlayAlarmMusic(dialog); } } }, 180000); @@ -102,13 +98,13 @@ function alarm(alarmType: number) { dialogInstance[index].show = false; }); let timer: string | number | NodeJS.Timeout | undefined = undefined; - timingPlayAlarmMusic(dialogInstanceItem, timer); dialogInstance.push({ dialog: dialogInstanceItem, show: true, alarmType, timer, }); + timingPlayAlarmMusic(dialogInstanceItem); } onUnmounted(() => {