feat:产线运行看板-实时报警信息模块

main
黄伟杰 5 days ago
parent 355624cb56
commit 0995e60412

@ -1,84 +1,113 @@
<template> <template>
<div class="card"> <div class="card">
<div class="panel-title"> <div class="card-header">
<span class="title-dot"></span> <div class="card-title">
<span>Payment method</span> <span class="card-title-icon">
<div class="date-filter"> <Icon icon="fa-solid:bell" />
<el-date-picker </span>
v-model="pickedDate" <span>实时报警信息</span>
type="date"
format="YYYY MM/DD"
value-format="YYYY-MM-DD"
:clearable="false"
size="small"
/>
</div> </div>
<span class="tag">滚动展示</span>
</div> </div>
<div class="panel-body"> <div class="card-body">
<div ref="chartRef" class="chart"></div> <ul ref="listRef" class="alarm-list">
<li
v-for="(a, index) in alarms"
:key="index"
class="alarm-item"
:class="[a.type, { 'animating-out': index === 0 && isAnimating }]"
:title="a.msg"
>
<span class="alarm-time">[{{ a.time }}]</span>
<span class="alarm-msg">{{ a.msg }}</span>
<span class="alarm-level">{{ a.level }}</span>
</li>
</ul>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, onUnmounted, ref } from 'vue' import { ref, onMounted, onUnmounted } from 'vue'
import * as echarts from 'echarts' import { useRoute } from 'vue-router'
import { colors, style } from '../utils' import { DeviceWarningRecordApi, DeviceWarningRecordVO } from '@/api/iot/deviceWarningRecord'
const chartRef = ref<HTMLElement | null>(null) const route = useRoute()
let chart: echarts.ECharts | null = null const orgId = route.query.orgId
const pickedDate = ref('2023-08-31')
const alarms = ref<any[]>([])
const render = () => { const isAnimating = ref(false)
if (!chart) return let timer: ReturnType<typeof setInterval> | null = null
const x = ['9:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00']
const y = [60, 120, 165, 140, 185, 150, 190] const getAlarms = async () => {
chart.setOption({ try {
backgroundColor: 'transparent', const data = (await DeviceWarningRecordApi.getList({ orgId })) || []
grid: { top: '14%', left: '6%', right: '4%', bottom: '12%', containLabel: true }, alarms.value = data.map((item: DeviceWarningRecordVO) => {
tooltip: { trigger: 'axis' }, let timeStr = ''
xAxis: { type: 'category', data: x, axisLine: style.axisLine, axisLabel: { ...style.axisLabel, fontSize: 10 } }, if (item.createTime) {
yAxis: { type: 'value', axisLine: { show: false }, axisLabel: { ...style.axisLabel, fontSize: 10 }, splitLine: style.splitLine }, const d = new Date(item.createTime)
series: [ timeStr = d.toTimeString().slice(0, 8)
{ }
type: 'line',
smooth: true, let type = 'safe'
showSymbol: true, let levelText = item.alarmLevel
symbolSize: 6,
lineStyle: { width: 2, color: colors.cyan }, if (item.alarmLevel === '2') {
itemStyle: { color: colors.cyan }, type = 'danger'
areaStyle: { levelText = '严重'
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ } else if (item.alarmLevel === '1') {
{ offset: 0, color: 'rgba(34,211,238,0.38)' }, type = 'warn'
{ offset: 1, color: 'rgba(34,211,238,0.06)' } levelText = '警告'
]) } else if (item.alarmLevel === '0') {
}, type = 'safe'
data: y levelText = '提示'
} else {
if (item.alarmLevel === '严重') type = 'danger'
else if (item.alarmLevel === '警告') type = 'warn'
else if (item.alarmLevel === '提示') type = 'safe'
} }
]
}) return {
time: timeStr,
level: levelText,
type,
msg: `${item.deviceName}-${item.ruleName}`
}
})
startAnimation()
} catch (error) {
console.error('Failed to fetch alarms:', error)
}
} }
const resize = () => { const startAnimation = () => {
chart?.resize() if (timer) clearInterval(timer)
if (alarms.value.length === 0) return
timer = setInterval(() => {
isAnimating.value = true
setTimeout(() => {
const first = alarms.value.shift()
if (first) {
alarms.value.push(first)
}
isAnimating.value = false
}, 360)
}, 3000)
} }
onMounted(() => { onMounted(() => {
if (!chartRef.value) return getAlarms()
chart = echarts.init(chartRef.value, 'dark', { renderer: 'canvas' })
render()
window.addEventListener('resize', resize)
}) })
onUnmounted(() => { onUnmounted(() => {
window.removeEventListener('resize', resize) if (timer) clearInterval(timer)
chart?.dispose()
}) })
</script> </script>
<style scoped> <style scoped>
.card { .card {
height: 100%;
background: linear-gradient(135deg, rgba(15,23,42,0.96), rgba(15,23,42,0.88)); background: linear-gradient(135deg, rgba(15,23,42,0.96), rgba(15,23,42,0.88));
border-radius: 8px; border-radius: 8px;
border: 1px solid rgba(30,64,175,0.85); border: 1px solid rgba(30,64,175,0.85);
@ -90,7 +119,6 @@ onUnmounted(() => {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
overflow: hidden; overflow: hidden;
min-height: 0;
} }
.card::before, .card::before,
@ -119,52 +147,110 @@ onUnmounted(() => {
border-top: none; border-top: none;
} }
.panel-title { .card-header {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 10px; justify-content: space-between;
padding: 10px 12px; margin-bottom: 8px;
padding: 10px 12px 4px;
border-bottom: 1px solid rgba(41, 54, 95, 0.9); border-bottom: 1px solid rgba(41, 54, 95, 0.9);
font-size: 16px; }
font-weight: 900;
.card-title {
display: flex;
align-items: center;
gap: 8px;
font-size: 15px;
font-weight: 700;
color: #e5f0ff; color: #e5f0ff;
} }
.title-dot { .card-title-icon {
width: 10px; color: #22d3ee;
height: 10px;
border-radius: 50%;
border: 1px solid rgba(56,189,248,0.95);
box-shadow: 0 0 12px rgba(56,189,248,0.45);
} }
.date-filter { .card-body {
margin-left: auto; flex: 1;
display: inline-flex; min-height: 0;
display: flex;
flex-direction: column;
gap: 8px;
padding: 10px 12px 12px;
overflow: hidden;
}
.tag {
border-radius: 999px;
padding: 2px 6px;
font-size: 10px;
border: 1px solid rgba(148,163,184,0.4);
color: #94a3b8;
}
.alarm-list {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: 6px;
height: 100%;
overflow: hidden;
}
.alarm-item {
display: flex;
align-items: center; align-items: center;
gap: 8px;
padding: 7px 8px;
border-radius: 6px;
background: rgba(15,23,42,0.92);
border: 1px solid rgba(30,64,175,0.9);
font-size: 11px;
color: #e5f0ff;
transition: background 0.3s, box-shadow 0.3s;
flex-shrink: 0;
} }
.date-filter :deep(.el-input__wrapper) { .alarm-item.danger {
background: rgba(2,6,23,0.35); border-left: 3px solid #ef4444;
box-shadow: none; box-shadow: 0 0 18px rgba(239,68,68,0.4);
border: 1px solid rgba(148,163,184,0.35);
} }
.date-filter :deep(.el-input__inner) { .alarm-item.warn {
color: rgba(224,242,254,0.95); border-left: 3px solid #f59e0b;
font-size: 12px; box-shadow: 0 0 14px rgba(245,158,11,0.35);
font-weight: 700; }
.alarm-item.safe {
border-left: 3px solid #22c55e;
box-shadow: 0 0 12px rgba(34,197,94,0.35);
}
.alarm-time {
width: 64px;
flex: 0 0 auto;
color: #94a3b8;
} }
.panel-body { .alarm-msg {
flex: 1; flex: 1;
min-height: 0; white-space: nowrap;
padding: 10px 12px; overflow: hidden;
text-overflow: ellipsis;
} }
.chart { .alarm-level {
width: 100%; flex: 0 0 auto;
height: 100%; border-radius: 999px;
min-height: 160px; padding: 2px 6px;
border: 1px solid rgba(148,163,184,0.6);
font-size: 10px;
}
.animating-out {
transition: all 0.35s;
transform: translateY(-48px);
opacity: 0;
} }
</style> </style>

Loading…
Cancel
Save