From 5f667fb8cff28e211ac75ea39618926292a8763f Mon Sep 17 00:00:00 2001 From: Cui Hongwei Date: Sun, 19 Jul 2026 09:33:01 +0800 Subject: [PATCH] feat: connect alarm events to database --- src/views/qingAn.vue | 94 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/src/views/qingAn.vue b/src/views/qingAn.vue index fa38ddc..1d7576a 100644 --- a/src/views/qingAn.vue +++ b/src/views/qingAn.vue @@ -313,6 +313,8 @@ export default { lineMonitorRequesting: false, storageMatrixTimer: null, storageMatrixRequesting: false, + alarmEventTimer: null, + alarmEventRequesting: false, clockTimer: null, resizeHandler: null, alarmPieChart: null, @@ -626,6 +628,7 @@ export default { this.$nextTick(this.initAlarmPieChart) this.loadLineMonitorData() this.loadStorageMatrixData() + this.loadAlarmEventData() this.clockTimer = setInterval(this.updateTime, 1000) this.lineMonitorTimer = setInterval(() => { this.loadLineMonitorData() @@ -633,6 +636,9 @@ export default { this.storageMatrixTimer = setInterval(() => { this.loadStorageMatrixData() }, 5000) + this.alarmEventTimer = setInterval(() => { + this.loadAlarmEventData() + }, 10000) this.resizeHandler = () => { this.setScale() if (this.alarmPieChart) { @@ -672,6 +678,10 @@ export default { clearInterval(this.storageMatrixTimer) this.storageMatrixTimer = null } + if (this.alarmEventTimer) { + clearInterval(this.alarmEventTimer) + this.alarmEventTimer = null + } if (this.alarmPieChart) { this.alarmPieChart.dispose() this.alarmPieChart = null @@ -760,6 +770,87 @@ export default { } return '' }, + loadAlarmEventData() { + if (this.alarmEventRequesting) return + this.alarmEventRequesting = true + const data = this.CreateData('11', 'TV_报警异常事件_查询', []) + this.ExecDatabase(data) + .then((response) => { + const list = response && response.data ? response.data : null + if (!Array.isArray(list) || list.length === 0) return + if (list.length === 1 && list[0] && (list[0].result === '0' || list[0].result === 0)) return + this.applyAlarmEventData(list) + }) + .catch((error) => { + console.error('TV_报警异常事件_查询失败', error) + }) + .then(() => { + this.alarmEventRequesting = false + }) + }, + applyAlarmEventData(list) { + const events = [] + const stats = [] + list.forEach((item) => { + const rowType = this.formatDisplayValue(this.pickRecordValue(item, ['RowType', 'rowType'])).toLowerCase() + if (rowType === 'stat') { + const stat = this.createAlarmStatRow(item) + if (stat.value > 0) { + stats.push(stat) + } + return + } + if (rowType === 'event') { + events.push(this.createAlarmEventRow(item)) + } + }) + if (events.length) { + this.alarmEvents = events + } + if (stats.length) { + this.alarmFrequencyTop5 = stats + this.$nextTick(this.initAlarmPieChart) + } + }, + createAlarmEventRow(item) { + const type = this.normalizeAlarmEventType(this.pickRecordValue(item, ['EventType', 'eventType'])) + const time = this.formatDisplayValue(this.pickRecordValue(item, ['TimeText', 'timeText'])) + return { + time: time === '--' ? '--:--' : time, + device: this.formatDisplayValue(this.pickRecordValue(item, ['DeviceName', 'deviceName'])), + level: type === 'warn' ? '提示' : '报警', + type, + message: this.formatDisplayValue(this.pickRecordValue(item, ['Message', 'message'])), + code: this.formatDisplayValue(this.pickRecordValue(item, ['AlarmCode', 'alarmCode'])), + startTime: this.formatDisplayValue(this.pickRecordValue(item, ['StartTimeText', 'startTimeText'])) + } + }, + createAlarmStatRow(item) { + const name = this.formatDisplayValue(this.pickRecordValue(item, ['StatName', 'statName'])) + const code = this.formatDisplayValue(this.pickRecordValue(item, ['AlarmCode', 'alarmCode'])) + return { + name: name === '--' ? code : name, + code, + value: Number(this.pickRecordValue(item, ['CountValue', 'countValue'])) || 0 + } + }, + normalizeAlarmEventType(value) { + const type = String(value || '').trim().toLowerCase() + return ['alarm', 'warn', 'idle'].includes(type) ? type : 'alarm' + }, + pickRecordValue(item, keys) { + for (let i = 0; i < keys.length; i += 1) { + const value = item[keys[i]] + if (value !== undefined && value !== null) { + return value + } + } + return '' + }, + formatAlarmChartName(value) { + const text = String(value == null ? '' : value).trim() + return text.length > 9 ? `${text.slice(0, 9)}...` : text + }, loadLineMonitorData() { if (this.lineMonitorRequesting) return this.lineMonitorRequesting = true @@ -1026,6 +1117,7 @@ export default { } this.alarmPieChart = echarts.init(this.$refs.alarmPieChart) const names = this.alarmFrequencyTop5.map(item => item.name) + const shortNames = names.map(name => this.formatAlarmChartName(name)) const values = this.alarmFrequencyTop5.map(item => item.value) const maxValue = Math.max(...values, 1) const yAxisMax = Math.max(2, Math.ceil(maxValue / 2) * 2) @@ -1051,7 +1143,7 @@ export default { }, xAxis: { type: 'category', - data: names, + data: shortNames, axisTick: { show: false },