循环报警修改

This commit is contained in:
joylink_zhaoerwei 2023-10-10 14:02:46 +08:00
parent 60f97b5ea3
commit 8149d6d6f1

View File

@ -35,17 +35,14 @@ const watchInteract = () => {
document.removeEventListener('click', watchInteract); document.removeEventListener('click', watchInteract);
document.removeEventListener('keydown', watchInteract); document.removeEventListener('keydown', watchInteract);
}; };
let timer: string | number | NodeJS.Timeout | undefined = undefined;
let alarmType: number;
watch( watch(
() => lineNetStore.alarmInfo, () => lineNetStore.alarmInfo,
(val) => { (val) => {
if (val.length) { if (val.length) {
alarmType = val[0].alert_type; const alarmType = val[0].alert_type;
playAlarmMusic(alarmType); playAlarmMusic(alarmType);
alarm(); alarm(alarmType);
timingPlayAlarmMusic();
} }
} }
); );
@ -78,23 +75,30 @@ function playAlarmMusic(type: number) {
} }
//3 //3
function timingPlayAlarmMusic() { function timingPlayAlarmMusic(
dialog: DialogChainObject,
timer: string | number | NodeJS.Timeout | undefined
) {
clearTimeout(timer); clearTimeout(timer);
timer = setTimeout(() => { timer = setTimeout(() => {
if (dialogInstance.length) { if (dialogInstance.length) {
for (let i = 0; i < dialogInstance.length; i++) { for (let i = 0; i < dialogInstance.length; i++) {
if (dialogInstance[i].show) { if (dialogInstance[i].show && dialogInstance[i].dialog == dialog) {
playAlarmMusic(alarmType); playAlarmMusic(dialogInstance[i].alarmType);
timingPlayAlarmMusic(); timingPlayAlarmMusic(dialog, timer);
break;
} }
} }
} }
}, 180000); }, 180000);
} }
const dialogInstance: { dialog: DialogChainObject; show: boolean }[] = []; const dialogInstance: {
function alarm() { dialog: DialogChainObject;
show: boolean;
alarmType: number;
timer: string | number | NodeJS.Timeout | undefined;
}[] = [];
function alarm(alarmType: number) {
const dialogInstanceItem = $q const dialogInstanceItem = $q
.dialog({ component: alarmInfoDialog }) .dialog({ component: alarmInfoDialog })
.onCancel(() => { .onCancel(() => {
@ -103,7 +107,14 @@ function alarm() {
); );
dialogInstance[index].show = false; 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(() => { onMounted(() => {
@ -112,9 +123,9 @@ onMounted(() => {
}); });
onUnmounted(() => { onUnmounted(() => {
clearTimeout(timer);
if (dialogInstance.length) { if (dialogInstance.length) {
dialogInstance.forEach((item) => { dialogInstance.forEach((item) => {
clearTimeout(item.timer);
if (item.show) { if (item.show) {
item.dialog.hide(); item.dialog.hide();
} }