Files
dyf-vue-ui/src/views/homeIndex/components/RealTimeAlarm.vue

147 lines
3.5 KiB
Vue
Raw Normal View History

2025-09-27 16:10:17 +08:00
<template>
2025-09-27 17:58:15 +08:00
<div class="alarm-table-container">
<div class="alarm-table-header">
<div class="header-item">报警时间</div>
<div class="header-item">设备类型</div>
<div class="header-item">设备IMEI</div>
<div class="header-item">报警事件</div>
2025-09-29 09:31:03 +08:00
<div class="header-item ">报警位置</div>
2025-09-27 17:58:15 +08:00
</div>
<div class="alarm-table-body" ref="tableBody"
:style="{ animationDuration: `${alarmData.length * 2}s`, animationTimingFunction: 'linear' }">
<div v-for="(item, index) in alarmData" :key="index" class="alarm-item">
2025-09-28 15:28:15 +08:00
<div class="item-cell">{{ item.startTime }}</div>
<div class="item-cell">{{ item.deviceTypeName }}</div>
<div class="item-cell">{{ item.deviceImei }}</div>
<div class="item-cell alarm-event">
{{ {
0: '强制报警',
1: '撞击闯入',
2: '自动报警',
2025-09-29 09:31:03 +08:00
3: '电子围栏告警'
}[item.deviceAction] }}
2025-09-28 15:28:15 +08:00
</div>
2025-09-29 09:31:03 +08:00
<div class="item-cell loaction">{{ item.location }}</div>
2025-09-27 17:58:15 +08:00
</div>
</div>
</div>
2025-09-27 16:10:17 +08:00
</template>
2025-09-27 17:58:15 +08:00
<script setup>
2025-09-28 15:28:15 +08:00
import { getRealtimeAlarm } from '@/api/homeIndex/index';
2025-09-29 11:27:36 +08:00
let alarmTimer = null;
2025-09-27 17:58:15 +08:00
// 模拟报警数据
const alarmData = ref([
]);
2025-09-28 15:28:15 +08:00
const getRealtimeAlarmData = () => {
getRealtimeAlarm().then((res) => {
alarmData.value = res.data;
});
}
2025-09-29 11:27:36 +08:00
const startAlarmTimer = () => {
if (alarmTimer) {
clearInterval(alarmTimer);
}
getRealtimeAlarmData();
alarmTimer = setInterval(getRealtimeAlarmData, 40 * 1000);
};
const clearAlarmTimer = () => {
if (alarmTimer) {
clearInterval(alarmTimer);
alarmTimer = null;
}
};
2025-09-27 17:58:15 +08:00
const tableBody = ref(null);
onMounted(() => {
2025-09-29 11:27:36 +08:00
startAlarmTimer();
2025-09-27 17:58:15 +08:00
// 启动滚动动画
if (tableBody.value) {
tableBody.value.style.animationName = 'scroll';
tableBody.value.style.animationIterationCount = 'infinite';
}
});
2025-09-29 11:27:36 +08:00
onUnmounted(() => {
clearAlarmTimer(); // 组件销毁时清除定时器
})
2025-09-27 16:10:17 +08:00
</script>
2025-09-27 17:58:15 +08:00
<style scoped lang="scss">
.alarm-table-container {
width: 100%;
border-radius: 4px;
overflow: hidden;
margin-top: 4vh;
padding: 1.5vw;
}
.alarm-table-header {
display: flex;
2025-09-28 15:28:15 +08:00
color: #00C0FF;
2025-09-27 17:58:15 +08:00
border-bottom: 1px dashed rgba(100, 150, 200, 0.3);
2025-09-28 15:28:15 +08:00
font-size: 0.8vw;
2025-09-27 17:58:15 +08:00
}
.header-item {
flex: 1;
padding: 8px;
text-align: center;
}
.alarm-table-body {
height: 18vh;
/* 可根据需求调整高度 */
overflow: auto;
color: #fff;
}
2025-09-29 09:31:03 +08:00
/* Webkit浏览器滚动条样式 */
.alarm-table-body::-webkit-scrollbar {
width: 8px;
}
.alarm-table-body::-webkit-scrollbar-track {
background: transparent;
border-radius: 4px;
}
.alarm-table-body::-webkit-scrollbar-thumb {
background: #267AD0;
border-radius: 4px;
}
.alarm-table-body::-webkit-scrollbar-thumb:hover {
background: #267AD0;
}
2025-09-27 17:58:15 +08:00
.alarm-item {
display: flex;
border-bottom: 1px dashed rgba(100, 150, 200, 0.3);
font-size: 0.6vw;
align-items: center;
2025-09-29 09:31:03 +08:00
padding: 0.8vw;
2025-09-27 17:58:15 +08:00
}
.item-cell {
flex: 1;
text-align: center;
}
2025-09-29 09:31:03 +08:00
// .item-cell.loaction{
// color: #267AD0;
// }
2025-09-27 17:58:15 +08:00
.alarm-event {
color: #ff5252;
/* 报警事件红色显示 */
}
/* 滚动动画 */
@keyframes scroll {
0% {
transform: translateY(0);
}
100% {
transform: translateY(-50%);
}
}
</style>