feat:日志报警页面更新

This commit is contained in:
吉浩茹
2025-10-01 04:07:37 +08:00
parent deb4d99393
commit 5f20cc7cd3
7 changed files with 833 additions and 516 deletions

View File

@ -67,7 +67,7 @@
<script>
import mqttDataManager from '@/utils/mqttDataManager.js'
import { dataHistoryApi } from '@/utils/api.js'
import { dataHistoryApi, eventApi } from '@/utils/api.js'
import EChart from '@/uni_modules/e-chart/components/e-chart/e-chart.vue'
export default {
@ -99,6 +99,8 @@ export default {
lastUpdateTime: null,
dataSource: 'empty' // 'api' | 'empty' | 'error'
},
// 页面初始化状态
hasInitialized: false,
// ECharts配置选项
temperatureOption: {
title: {
@ -312,6 +314,16 @@ export default {
// 调用历史数据接口
this.getHistoryData()
},
onShow() {
console.log('📱 参数记录页面显示,触发页面更新')
// 只有在非首次显示时才重新获取历史数据
// 首次显示时已经在onLoad中获取过了
if (this.hasInitialized) {
this.getHistoryData()
} else {
this.hasInitialized = true
}
},
onUnload() {
// 页面卸载时移除监听器
if (this.dataUpdateHandler) {
@ -467,6 +479,9 @@ export default {
lastUpdateTime: new Date().toLocaleString(),
dataSource: 'api'
}
// 保存查询事件
await this.createQueryEvent('success', response.length)
} else {
console.log('📊 没有历史数据,显示空状态')
// 没有数据时显示空状态
@ -478,6 +493,9 @@ export default {
lastUpdateTime: new Date().toLocaleString(),
dataSource: 'empty'
}
// 保存查询事件(无数据)
await this.createQueryEvent('empty', 0)
}
return response
@ -494,6 +512,9 @@ export default {
dataSource: 'error'
}
// 保存查询事件(错误)
await this.createQueryEvent('error', 0)
// 显示错误提示
uni.showToast({
title: '数据加载失败',
@ -680,6 +701,58 @@ export default {
this.$refs.pm25ChartRef.setOption(this.pm25Option)
}
}
},
// 创建查询事件
async createQueryEvent(status, dataCount) {
try {
const currentTime = this.formatDateTime(new Date())
const queryEvent = {
eventType: "参数记录查询",
eventTime: currentTime,
status: this.getEventStatus(status),
description: this.getEventDescription(status, dataCount),
deviceId: "PARAMETER_QUERY_001"
}
console.log('📤 提交查询事件:', queryEvent)
const response = await eventApi.create(queryEvent)
console.log('✅ 查询事件创建成功:', response)
} catch (error) {
console.error('❌ 查询事件创建失败:', error)
}
},
// 获取事件状态
getEventStatus(status) {
const statusMap = {
'success': '已完成',
'empty': '已完成',
'error': '失败'
};
return statusMap[status] || '未知';
},
// 获取事件描述
getEventDescription(status, dataCount) {
const descriptions = {
'success': `成功查询到${dataCount}条参数记录数据`,
'empty': '查询参数记录,但未找到数据',
'error': '查询参数记录时发生错误'
};
return descriptions[status] || '未知查询状态';
},
// 时间格式化函数
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')
const seconds = String(date.getSeconds()).padStart(2, '0')
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}
}
}