告警信息

This commit is contained in:
cwchen 2025-12-23 16:06:33 +08:00
parent 9fb36f623d
commit 63bf3719c7
3 changed files with 16 additions and 101 deletions

View File

@ -3,7 +3,7 @@ import request from '@/utils/request'
// 告警管理->告警列表->查询告警列表 // 告警管理->告警列表->查询告警列表
export function alarmListAPI(params) { export function alarmListAPI(params) {
return request({ return request({
url: '/smartCar/alarm/getAlarmList', url: '/smartCar/data/alarm/getAlarmList',
method: 'GET', method: 'GET',
params params
}) })

View File

@ -368,8 +368,11 @@ export default {
/* 生成查询参数 */ /* 生成查询参数 */
this.formLabel.map((e) => { this.formLabel.map((e) => {
if (e.f_type === 'dateRange' || e.f_type === 'dateTimeRange') { if (e.f_type === 'dateRange' || e.f_type === 'dateTimeRange') {
//
this.$set(this.queryParams, e.dateType[0], '') this.$set(this.queryParams, e.dateType[0], '')
this.$set(this.queryParams, e.dateType[1], '') this.$set(this.queryParams, e.dateType[1], '')
// v-model
this.$set(this.queryParams, e.f_model, null)
this.typeList = e.dateType this.typeList = e.dateType
if (this.isOneMonth) { if (this.isOneMonth) {
@ -672,10 +675,10 @@ export default {
if (diffDays > 31) { if (diffDays > 31) {
const newEndDate = new Date(startDate) const newEndDate = new Date(startDate)
newEndDate.setDate(startDate.getDate() + 31) newEndDate.setDate(startDate.getDate() + 31)
this.queryParams.time = [ this.$set(this.queryParams, 'time', [
start, start,
newEndDate.toISOString().split('T')[0], newEndDate.toISOString().split('T')[0],
] ])
this.$message.warning( this.$message.warning(
'选择的时间范围超过31天查询将会缓慢已自动调整', '选择的时间范围超过31天查询将会缓慢已自动调整',
) )
@ -686,12 +689,13 @@ export default {
const [_1, _2] = type const [_1, _2] = type
if (e && e.length > 0) { if (e && e.length > 0) {
const [_time1, _time2] = e const [_time1, _time2] = e
this.queryParams[_1] = _time1 // 使 $set
this.queryParams[_2] = _time2 this.$set(this.queryParams, _1, _time1)
this.$set(this.queryParams, _2, _time2)
} else { } else {
// //
this.queryParams[_1] = '' this.$set(this.queryParams, _1, '')
this.queryParams[_2] = '' this.$set(this.queryParams, _2, '')
} }
} }
} }

View File

@ -4,7 +4,7 @@
<!-- 数据列表 --> <!-- 数据列表 -->
<div class="table-container"> <div class="table-container">
<TableModel :formLabel="formLabel" :showOperation="false" :showRightTools="false" ref="alermTableRef" <TableModel :formLabel="formLabel" :showOperation="false" :showRightTools="false" ref="alermTableRef"
:columnsList="columnsList" :request-api="wrappedAPI" :handleColWidth="250" :showSearch="true"> :columnsList="columnsList" :request-api="alarmListAPI" :handleColWidth="250" :showSearch="true">
<template slot="tableTitle"> <template slot="tableTitle">
<h3>数据列表</h3> <h3>数据列表</h3>
</template> </template>
@ -31,105 +31,16 @@ export default {
showSearch: true, showSearch: true,
formLabel, formLabel,
columnsList, columnsList,
wrappedAPI: null, alarmListAPI
} }
}, },
created() {
// API
this.wrappedAPI = this.wrapAPIWithTestData(alarmListAPI)
},
methods: { methods: {
/** 包装API函数支持测试数据 */
wrapAPIWithTestData(apiFunc) {
return async (params) => {
try {
// API
const res = await apiFunc(params)
if (res.code === 200) {
return res
}
} catch (error) {
console.log('API调用失败使用测试数据:', error)
}
// 使 /* 搜索操作 */
const allTestData = this.getTestData() handleQuery() {
this.$refs.alarmTableRef.getTableList()
//
let filteredData = allTestData
if (params.startTime) {
filteredData = filteredData.filter(item => {
const itemTime = new Date(item.alarmTime.replace(/\//g, '-'))
const startTime = new Date(params.startTime.replace(' ', 'T'))
return itemTime >= startTime
})
}
if (params.endTime) {
filteredData = filteredData.filter(item => {
const itemTime = new Date(item.alarmTime.replace(/\//g, '-'))
const endTime = new Date(params.endTime.replace(' ', 'T'))
return itemTime <= endTime
})
}
//
const pageNum = params.pageNum || 1
const pageSize = params.pageSize || 10
const start = (pageNum - 1) * pageSize
const end = start + pageSize
return {
code: 200,
rows: filteredData.slice(start, end),
total: filteredData.length,
msg: 'success'
}
}
}, },
/** 获取测试数据 */
getTestData() {
const alarmContents = [
'设备位置发生变化,当前设备位置:×××××XXX',
'设备连接异常,请检查网络连接状态',
'设备电量不足,当前电量:15%,请及时充电',
'设备温度过高,当前温度:85°C,请检查散热系统',
'设备存储空间不足,当前使用率:95%,请清理数据',
'设备传感器故障,传感器编号:S001,请联系维修',
'数据传输异常,数据包丢失率:10%,请检查网络',
'设备离线,最后在线时间:2025/06/02 08:30',
]
const testData = []
// 1000
for (let i = 0; i < 1000; i++) {
const date = new Date()
date.setDate(date.getDate() - Math.floor(i / 50))
date.setHours(8 + (i % 12), (i % 60), 0, 0)
const alarmTime = this.formatDateTime(date)
testData.push({
serialNo: i + 1,
alarmContent: alarmContents[i % alarmContents.length],
alarmTime: alarmTime,
})
}
return testData
},
/** 格式化日期时间 */
formatDateTime(date) {
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
const hours = String(date.getHours()).padStart(2, '0')
const minutes = String(date.getMinutes()).padStart(2, '0')
return `${year}/${month}/${day} ${hours}:${minutes}`
},
}, },
} }
</script> </script>