From 8149d6d6f1b2f1ec7abc17992b0c387ca5c08d29 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Tue, 10 Oct 2023 14:02:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E6=8A=A5=E8=AD=A6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/alarm/commonAlarm.vue | 39 ++++++++++++++++++---------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/components/alarm/commonAlarm.vue b/src/components/alarm/commonAlarm.vue index 6e89f00..04f2231 100644 --- a/src/components/alarm/commonAlarm.vue +++ b/src/components/alarm/commonAlarm.vue @@ -35,17 +35,14 @@ const watchInteract = () => { document.removeEventListener('click', watchInteract); document.removeEventListener('keydown', watchInteract); }; -let timer: string | number | NodeJS.Timeout | undefined = undefined; -let alarmType: number; watch( () => lineNetStore.alarmInfo, (val) => { if (val.length) { - alarmType = val[0].alert_type; + const alarmType = val[0].alert_type; playAlarmMusic(alarmType); - alarm(); - timingPlayAlarmMusic(); + alarm(alarmType); } } ); @@ -78,23 +75,30 @@ function playAlarmMusic(type: number) { } //不关闭弹框,每3分钟播放一次报警音乐 -function timingPlayAlarmMusic() { +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) { - playAlarmMusic(alarmType); - timingPlayAlarmMusic(); - break; + if (dialogInstance[i].show && dialogInstance[i].dialog == dialog) { + playAlarmMusic(dialogInstance[i].alarmType); + timingPlayAlarmMusic(dialog, timer); } } } }, 180000); } -const dialogInstance: { dialog: DialogChainObject; show: boolean }[] = []; -function alarm() { +const dialogInstance: { + dialog: DialogChainObject; + show: boolean; + alarmType: number; + timer: string | number | NodeJS.Timeout | undefined; +}[] = []; +function alarm(alarmType: number) { const dialogInstanceItem = $q .dialog({ component: alarmInfoDialog }) .onCancel(() => { @@ -103,7 +107,14 @@ function alarm() { ); dialogInstance[index].show = false; }); - dialogInstance.push({ dialog: dialogInstanceItem, show: true }); + let timer: string | number | NodeJS.Timeout | undefined = undefined; + timingPlayAlarmMusic(dialogInstanceItem, timer); + dialogInstance.push({ + dialog: dialogInstanceItem, + show: true, + alarmType, + timer, + }); } onMounted(() => { @@ -112,9 +123,9 @@ onMounted(() => { }); onUnmounted(() => { - clearTimeout(timer); if (dialogInstance.length) { dialogInstance.forEach((item) => { + clearTimeout(item.timer); if (item.show) { item.dialog.hide(); }