fix:设备状态接口更新、删除无用逻辑

This commit is contained in:
吉浩茹
2025-11-14 11:06:48 +08:00
parent c8f7242f7c
commit 2cb78c4155
7 changed files with 143 additions and 374 deletions

View File

@ -1,20 +1,6 @@
<template> <template>
<view class="page-container alarm-record-container"> <view class="page-container alarm-record-container">
<!-- 页面头部 -->
<!-- <view class="page-header">
<view class="header-left">
<text class="page-title">报警记录</text>
</view>
<view class="header-right">
<view class="system-title">
<view class="system-title-icon">
<text class="icon">📋</text>
</view>
<text class="system-title-text">移动式检修车间系统</text>
</view>
</view>
</view> -->
<!-- 日期选择区域 --> <!-- 日期选择区域 -->
<view class="date-picker-container"> <view class="date-picker-container">
<picker <picker
@ -39,9 +25,6 @@
<view class="table-cell header-cell content-column">内容</view> <view class="table-cell header-cell content-column">内容</view>
<view class="table-cell header-cell type-column">种类</view> <view class="table-cell header-cell type-column">种类</view>
<view class="table-cell header-cell time-column">时间</view> <view class="table-cell header-cell time-column">时间</view>
<!-- <view class="table-cell header-cell level-column">级别</view> -->
<!-- <view class="table-cell header-cell action-column">处置</view> -->
<!-- <view class="table-cell header-cell action-time-column">时间</view> -->
</view> </view>
<!-- 表格内容 --> <!-- 表格内容 -->
@ -70,12 +53,6 @@
<view class="table-cell content-column">{{ alarm.content }}</view> <view class="table-cell content-column">{{ alarm.content }}</view>
<view class="table-cell type-column">{{ alarm.type }}</view> <view class="table-cell type-column">{{ alarm.type }}</view>
<view class="table-cell time-column">{{ alarm.time }}</view> <view class="table-cell time-column">{{ alarm.time }}</view>
<!-- <view class="table-cell level-column" :class="getLevelClass(alarm.level)"> -->
<!-- <view class="table-cell level-column">
{{ alarm.level }}
</view> -->
<!-- <view class="table-cell action-column">{{ alarm.action }}</view> -->
<!-- <view class="table-cell action-time-column">{{ alarm.actionTime }}</view> -->
</view> </view>
</template> </template>
@ -94,12 +71,7 @@
<view class="load-more-spinner"></view> <view class="load-more-spinner"></view>
<text class="load-more-text">正在加载更多...</text> <text class="load-more-text">正在加载更多...</text>
</view> </view>
<!-- 没有更多数据提示 -->
<!-- <view class="no-more-container" v-if="!hasMoreData && alarmList.length > 0 && !isLoadingMore">
<text class="no-more-text">已加载全部数据</text>
</view> -->
<!-- 底部间距确保最后一条记录完全显示 --> <!-- 底部间距确保最后一条记录完全显示 -->
<view class="table-bottom-spacing"></view> <view class="table-bottom-spacing"></view>
</scroll-view> </scroll-view>
@ -138,29 +110,6 @@ const endTime = ref('');
// MQTT报警服务接口预留 // MQTT报警服务接口预留
const mqttAlarmService = { const mqttAlarmService = {
// 连接MQTT服务器
// connect: async () => {
// console.log('MQTT报警服务连接中...');
// try {
// // 模拟连接延迟
// await new Promise(resolve => setTimeout(resolve, 1000));
// isConnected.value = true;
// console.log('MQTT报警服务连接成功');
// return Promise.resolve();
// } catch (error) {
// console.error('MQTT报警连接失败:', error);
// isConnected.value = false;
// return Promise.reject(error);
// }
// },
// 订阅报警数据
// subscribeAlarmData: () => {
// console.log('订阅系统报警数据');
// // 这里后期会实现真实的MQTT报警订阅
// return Promise.resolve();
// },
// 获取历史报警记录(分页) // 获取历史报警记录(分页)
getHistoryAlarms: async (page = 0, size = 20, isLoadMore = false) => { getHistoryAlarms: async (page = 0, size = 20, isLoadMore = false) => {
try { try {
@ -193,8 +142,6 @@ const mqttAlarmService = {
} }
} }
console.log('📅 查询时间范围:', queryStartTime, '至', queryEndTime);
// 调用分页获取告警接口 // 调用分页获取告警接口
const response = await alertApi.getListByCreateTime({ const response = await alertApi.getListByCreateTime({
page: page, page: page,
@ -268,7 +215,6 @@ const mqttAlarmService = {
// 获取实时报警 // 获取实时报警
getRealtimeAlarms: async () => { getRealtimeAlarms: async () => {
console.log('获取实时报警');
try { try {
// 模拟实时报警数据 // 模拟实时报警数据
const contents = ['温度超标', '湿度异常', '压力偏高', '洁净度超标', '设备故障', '通讯中断']; const contents = ['温度超标', '湿度异常', '压力偏高', '洁净度超标', '设备故障', '通讯中断'];
@ -319,7 +265,6 @@ const mqttAlarmService = {
// 确认报警 // 确认报警
confirmAlarm: async (alarmId) => { confirmAlarm: async (alarmId) => {
console.log('确认报警:', alarmId);
try { try {
// 模拟确认操作 // 模拟确认操作
await new Promise(resolve => setTimeout(resolve, 300)); await new Promise(resolve => setTimeout(resolve, 300));
@ -340,7 +285,6 @@ const mqttAlarmService = {
// 清空报警记录 // 清空报警记录
clearAlarms: async () => { clearAlarms: async () => {
console.log('清空报警记录');
try { try {
// 模拟清空操作 // 模拟清空操作
await new Promise(resolve => setTimeout(resolve, 300)); await new Promise(resolve => setTimeout(resolve, 300));
@ -401,20 +345,6 @@ const formatDateTime = (dateString) => {
} }
}; };
// 获取级别样式类
const getLevelClass = (level) => {
switch (level) {
case 'A':
return 'level-a';
case 'B':
return 'level-b';
case 'C':
return 'level-c';
default:
return '';
}
};
// 滚动事件处理 // 滚动事件处理
let scrollTimer = null; let scrollTimer = null;
@ -434,8 +364,6 @@ const onScroll = (e) => {
}; };
const onScrollToLower = () => { const onScrollToLower = () => {
console.log('滚动到底部,尝试加载更多数据');
// 如果正在加载或没有更多数据,则不处理 // 如果正在加载或没有更多数据,则不处理
if (isLoadingMore.value || !hasMoreData.value) { if (isLoadingMore.value || !hasMoreData.value) {
console.log('正在加载中或无更多数据,跳过'); console.log('正在加载中或无更多数据,跳过');
@ -457,19 +385,11 @@ const scrollToTop = () => {
// 日期选择处理,选择后直接查询 // 日期选择处理,选择后直接查询
const onDateChange = async (e) => { const onDateChange = async (e) => {
selectedDate.value = e.detail.value; selectedDate.value = e.detail.value;
console.log('选择的日期:', selectedDate.value);
// 自动构建开始和结束时间 // 自动构建开始和结束时间
if (selectedDate.value) { if (selectedDate.value) {
startTime.value = `${selectedDate.value} 00:00:00`; startTime.value = `${selectedDate.value} 00:00:00`;
endTime.value = `${selectedDate.value} 23:59:59`; endTime.value = `${selectedDate.value} 23:59:59`;
console.log('开始时间:', startTime.value);
console.log('结束时间:', endTime.value);
// 选择日期后直接查询
console.log('🔍 开始查询报警记录');
console.log('查询时间范围:', startTime.value, '至', endTime.value);
try { try {
// 重置分页状态 // 重置分页状态
currentPage.value = 0; currentPage.value = 0;
@ -478,12 +398,6 @@ const onDateChange = async (e) => {
// 使用选择的日期范围查询 // 使用选择的日期范围查询
await mqttAlarmService.getHistoryAlarms(0, pageSize.value, false); await mqttAlarmService.getHistoryAlarms(0, pageSize.value, false);
uni.showToast({
title: '查询成功',
icon: 'success',
duration: 1500
});
} catch (error) { } catch (error) {
console.error('❌ 查询失败:', error); console.error('❌ 查询失败:', error);
} }

View File

@ -173,12 +173,10 @@ const formatDateTime = (dateString) => {
const mqttLogService = { const mqttLogService = {
// 连接MQTT服务器 // 连接MQTT服务器
connect: async () => { connect: async () => {
console.log('MQTT日志服务连接中...');
try { try {
// 模拟连接延迟 // 模拟连接延迟
await new Promise(resolve => setTimeout(resolve, 1000)); await new Promise(resolve => setTimeout(resolve, 1000));
isConnected.value = true; isConnected.value = true;
console.log('MQTT日志服务连接成功');
return Promise.resolve(); return Promise.resolve();
} catch (error) { } catch (error) {
console.error('MQTT日志连接失败:', error); console.error('MQTT日志连接失败:', error);
@ -189,14 +187,12 @@ const mqttLogService = {
// 订阅日志数据 // 订阅日志数据
subscribeLogData: () => { subscribeLogData: () => {
console.log('订阅系统日志数据');
// 这里后期会实现真实的MQTT日志订阅 // 这里后期会实现真实的MQTT日志订阅
return Promise.resolve(); return Promise.resolve();
}, },
// 获取历史日志(分页) // 获取历史日志(分页)
getHistoryLogs: async (page = 0, size = 20, isLoadMore = false, queryDate = '') => { getHistoryLogs: async (page = 0, size = 20, isLoadMore = false, queryDate = '') => {
console.log(`📄 加载第${page}页数据,每页${size}条,查询日期:${queryDate}`);
try { try {
if (!isLoadMore) { if (!isLoadMore) {
isLoading.value = true; isLoading.value = true;
@ -227,8 +223,6 @@ const mqttLogService = {
} }
} }
console.log('📅 查询时间范围:', queryStartTime, '至', queryEndTime);
// 构建查询参数 // 构建查询参数
const params = { const params = {
page: page, page: page,
@ -258,11 +252,7 @@ const mqttLogService = {
// 更新分页状态 // 更新分页状态
currentPage.value = page; currentPage.value = page;
hasMoreData.value = newLogs.length === size; // 如果返回的数据少于请求的数量,说明没有更多数据 hasMoreData.value = newLogs.length === size; // 如果返回的数据少于请求的数量,说明没有更多数据
console.log(`✅ 第${page}页数据加载完成,共${newLogs.length}`);
} catch (error) { } catch (error) {
console.error('❌ 获取历史日志失败:', error);
if (!isLoadMore) { if (!isLoadMore) {
// 首次加载失败时显示空数据 // 首次加载失败时显示空数据
logList.value = []; logList.value = [];
@ -277,7 +267,6 @@ const mqttLogService = {
// 断开连接 // 断开连接
disconnect: () => { disconnect: () => {
console.log('MQTT日志服务断开连接');
isConnected.value = false; isConnected.value = false;
// 这里后期会实现真实的MQTT断开 // 这里后期会实现真实的MQTT断开
} }
@ -316,14 +305,12 @@ const onScroll = (e) => {
}; };
const onScrollToLower = () => { const onScrollToLower = () => {
console.log('📜 滚动到底部,触发加载更多');
if (isLoadingMore.value || !hasMoreData.value) { if (isLoadingMore.value || !hasMoreData.value) {
console.log('⏸️ 正在加载中或没有更多数据,跳过加载'); console.log('⏸️ 正在加载中或没有更多数据,跳过加载');
return; return;
} }
const nextPage = currentPage.value + 1; const nextPage = currentPage.value + 1;
console.log(`📄 开始加载第${nextPage}页数据`);
mqttLogService.getHistoryLogs(nextPage, pageSize.value, true, props.queryDate); mqttLogService.getHistoryLogs(nextPage, pageSize.value, true, props.queryDate);
}; };
@ -335,19 +322,10 @@ const scrollToTop = () => {
// 日期选择处理,选择后直接查询 // 日期选择处理,选择后直接查询
const onDateChange = async (e) => { const onDateChange = async (e) => {
selectedDate.value = e.detail.value; selectedDate.value = e.detail.value;
console.log('选择的日期:', selectedDate.value);
// 自动构建开始和结束时间 // 自动构建开始和结束时间
if (selectedDate.value) { if (selectedDate.value) {
startTime.value = `${selectedDate.value} 00:00:00`; startTime.value = `${selectedDate.value} 00:00:00`;
endTime.value = `${selectedDate.value} 23:59:59`; endTime.value = `${selectedDate.value} 23:59:59`;
console.log('开始时间:', startTime.value);
console.log('结束时间:', endTime.value);
// 选择日期后直接查询
console.log('🔍 开始查询系统日志');
console.log('查询时间范围:', startTime.value, '至', endTime.value);
try { try {
// 重置分页状态 // 重置分页状态
currentPage.value = 0; currentPage.value = 0;
@ -356,12 +334,6 @@ const onDateChange = async (e) => {
// 使用选择的日期范围查询 // 使用选择的日期范围查询
await mqttLogService.getHistoryLogs(0, pageSize.value, false, selectedDate.value); await mqttLogService.getHistoryLogs(0, pageSize.value, false, selectedDate.value);
uni.showToast({
title: '查询成功',
icon: 'success',
duration: 1500
});
} catch (error) { } catch (error) {
console.error('❌ 查询失败:', error); console.error('❌ 查询失败:', error);
} }
@ -373,12 +345,8 @@ const onDateChange = async (e) => {
// 组件生命周期 // 组件生命周期
onMounted(async () => { onMounted(async () => {
try { try {
// 连接MQTT并初始化
// await mqttLogService.connect();
// await mqttLogService.subscribeLogData();
await mqttLogService.getHistoryLogs(0, pageSize.value, false, props.queryDate); await mqttLogService.getHistoryLogs(0, pageSize.value, false, props.queryDate);
} catch (error) { } catch (error) {
console.error('日志系统初始化失败:', error);
uni.showToast({ uni.showToast({
title: '连接失败', title: '连接失败',
icon: 'error' icon: 'error'
@ -388,7 +356,6 @@ onMounted(async () => {
// 刷新数据方法 // 刷新数据方法
const refreshData = async () => { const refreshData = async () => {
console.log('🔄 刷新系统日志数据')
try { try {
// 重置分页状态 // 重置分页状态
currentPage.value = 0; currentPage.value = 0;
@ -404,7 +371,6 @@ const refreshData = async () => {
// 按日期查询方法 // 按日期查询方法
const queryByDate = async (queryDate) => { const queryByDate = async (queryDate) => {
console.log('📅 按日期查询系统日志:', queryDate)
try { try {
// 重置分页状态 // 重置分页状态
currentPage.value = 0; currentPage.value = 0;

View File

@ -1,5 +1,5 @@
{ {
"name" : "上动联", "name" : "上动联",
"appid" : "__UNI__0B541D7", "appid" : "__UNI__0B541D7",
"description" : "", "description" : "",
"versionName" : "1.1.0", "versionName" : "1.1.0",

View File

@ -95,7 +95,7 @@
class="ac-power-btn" class="ac-power-btn"
:class="getAcButtonClass()" :class="getAcButtonClass()"
@click="toggleAirConditioner" @click="toggleAirConditioner"
:disabled="!canOperateAc() || acControlLoading" :disabled="!canOperateAc() || acControlLoading || !isGatewayOnline"
> >
{{ getAcButtonText() }} {{ getAcButtonText() }}
</button> </button>
@ -110,7 +110,7 @@
</view> </view>
</view> </view>
<view class="ac-temp-control"> <view class="ac-temp-control">
<button class="ac-btn decrease temperature-decrease" @click="decreaseTemperature"> <button class="ac-btn decrease temperature-decrease" @click="decreaseTemperature" :disabled="!isGatewayOnline">
<text class="btn-icon"></text> <text class="btn-icon"></text>
</button> </button>
<view class="ac-temp-display"> <view class="ac-temp-display">
@ -122,10 +122,11 @@
@input="onTemperatureInput" @input="onTemperatureInput"
@blur="onTemperatureBlur" @blur="onTemperatureBlur"
@focus="onTemperatureFocus" @focus="onTemperatureFocus"
:disabled="!isGatewayOnline"
/> />
<text class="ac-temp-unit">°C</text> <text class="ac-temp-unit">°C</text>
</view> </view>
<button class="ac-btn increase temperature-increase" @click="increaseTemperature"> <button class="ac-btn increase temperature-increase" @click="increaseTemperature" :disabled="!isGatewayOnline">
<text class="btn-icon">+</text> <text class="btn-icon">+</text>
</button> </button>
</view> </view>
@ -142,7 +143,7 @@
</view> </view>
</view> </view>
<view class="ac-temp-control"> <view class="ac-temp-control">
<button class="ac-btn decrease humidity-decrease" @click="decreaseHumidity"> <button class="ac-btn decrease humidity-decrease" @click="decreaseHumidity" :disabled="!isGatewayOnline">
<text class="btn-icon"></text> <text class="btn-icon"></text>
</button> </button>
<view class="ac-temp-display"> <view class="ac-temp-display">
@ -154,10 +155,11 @@
@input="onHumidityInput" @input="onHumidityInput"
@blur="onHumidityBlur" @blur="onHumidityBlur"
@focus="onHumidityFocus" @focus="onHumidityFocus"
:disabled="!isGatewayOnline"
/> />
<text class="ac-temp-unit">%</text> <text class="ac-temp-unit">%</text>
</view> </view>
<button class="ac-btn increase humidity-increase" @click="increaseHumidity"> <button class="ac-btn increase humidity-increase" @click="increaseHumidity" :disabled="!isGatewayOnline">
<text class="btn-icon">+</text> <text class="btn-icon">+</text>
</button> </button>
</view> </view>
@ -194,7 +196,7 @@
</view> </view>
</view> </view>
<button class="settings-button" @click="openSettingsModal"> <button class="settings-button" @click="openSettingsModal" :disabled="!isGatewayOnline">
<text class="settings-icon"></text> <text class="settings-icon"></text>
<text class="settings-text">参数设定</text> <text class="settings-text">参数设定</text>
</button> </button>
@ -253,8 +255,8 @@
</view> </view>
<view class="modal-actions"> <view class="modal-actions">
<button class="cancel-btn" @click="closeSettingsModal">取消</button> <button class="cancel-btn" @click="closeSettingsModal" :disabled="!isGatewayOnline">取消</button>
<button class="confirm-btn" @click="saveSettings">确定</button> <button class="confirm-btn" @click="saveSettings" :disabled="!isGatewayOnline">确定</button>
</view> </view>
</view> </view>
</uni-popup> </uni-popup>
@ -297,6 +299,7 @@ export default {
wdisConnected: 0, wdisConnected: 0,
sdisConnected: 0, sdisConnected: 0,
pmisConnected: 0, pmisConnected: 0,
isGatewayOnline: false, // 网关是否在线 禁用按钮
connectionStatus: { connectionStatus: {
isConnected: false, isConnected: false,
lastUpdate: null lastUpdate: null
@ -329,7 +332,9 @@ export default {
humidity: null, humidity: null,
pm25: null pm25: null
}, },
dataFetchInterval: null dataFetchInterval: null,
// 是否已经提示过设备离线
hasShownOfflineAlert: false
} }
}, },
onLoad() { onLoad() {
@ -345,23 +350,17 @@ export default {
this.initMqttListener(); this.initMqttListener();
}, },
onShow() { onShow() {
console.log('📱 环境参数页面显示,触发页面更新');
this.init(); this.init();
// 注意init() 中已经包含了状态检查,不需要单独调用 getStatus() // 页面显示时重新启动定时器(如果之前被停止了)
// 重新启动定时器 if (!this.dataFetchInterval) {
this.startDataFetching(); this.startDataFetching();
// // 只有在非首次显示时才重新获取最新空调温度 }
// if (this.hasCreatedStartupEvent) {
// this.init();
// }
}, },
onHide() { onHide() {
console.log('📱 环境参数页面隐藏,停止定时器');
// 页面隐藏时停止定时器 // 页面隐藏时停止定时器
this.stopDataFetching(); this.stopDataFetching();
}, },
onUnload() { onUnload() {
console.log('📱 环境参数页面卸载,清理所有资源');
// 页面卸载时移除监听器 // 页面卸载时移除监听器
if (this.dataUpdateHandler) { if (this.dataUpdateHandler) {
mqttDataManager.removeListener('dataUpdate', this.dataUpdateHandler) mqttDataManager.removeListener('dataUpdate', this.dataUpdateHandler)
@ -378,48 +377,110 @@ export default {
// 停止数据获取定时器 // 停止数据获取定时器
this.stopDataFetching() this.stopDataFetching()
}, },
computed: {
// // 判断网关是否在线
// isGatewayOnline() {
// // 如果温湿度传感器或PM传感器任何一个在线则认为网关在线
// return this.wdisConnected === 1 || this.pmisConnected === 1
// }
},
methods: { methods: {
async init() { async init() {
console.log('📱 开始初始化环境参数页面...')
// 先调用状态接口判断是否在线
try { try {
const isOnline = await this.checkConnectionStatus() const isOnline = await this.checkConnectionStatus();
if (isOnline) { this.isGatewayOnline = isOnline;
console.log('✅ 设备在线,开始更新数据接口') if (isOnline) {
// 获取最新空调温度 // // 获取最新空调温度
this.getLatestAirConditionerTemperature() this.getLatestAirConditionerTemperature()
// 获取最新温湿度数据 // 获取最新温湿度数据
this.getLatestEnvironmentData() this.getLatestEnvironmentData()
// 首次进入系统时创建启动事件 // 首次进入系统时创建启动事件
// this.createStartupEventIfNeeded() // this.createStartupEventIfNeeded()
// 获取温湿度区间设置 // 获取温湿度区间设置
this.loadWsdSettings() this.loadWsdSettings()
} else { }
console.log('⚠️ 设备离线,跳过数据接口更新')
}
} catch (error) { } catch (error) {
console.error('❌ 检查连接状态失败:', error)
// 即使检查失败,也尝试获取数据(容错处理)
this.getLatestAirConditionerTemperature()
this.getLatestEnvironmentData()
this.loadWsdSettings()
} }
// 注意:定时器在 onShow 中启动,避免重复启动
}, },
// 检查连接状态,返回是否在线 // 检查连接状态,返回是否在线
async checkConnectionStatus() { async checkConnectionStatus() {
const res = await statusApi.getConnectionStatus(); try {
console.log('📊 连接状态接口返回:', res) // 1. 首先调用statusApi.getStatus接口判断网关设备是否在线
if (res && typeof res.connected === 'boolean') { const res = await statusApi.getStatus();
const val = res.connected ? 1 : 0 if (res.connected) {
this.wdisConnected = val // 2. 如果网关在线调用statusApi.getConnectionStatus判断空调、PM等设备是否在线
this.sdisConnected = val const connectRes = await statusApi.getConnectionStatus();
this.pmisConnected = val // 3. 更新各设备连接状态
return res.connected // 温湿度传感器状态 (1:连接成功, 0:未连接, 2:异常)
this.wdisConnected = Number(connectRes?.pm25 || 0)
this.sdisConnected = Number(connectRes?.pm25 || 0)
// // PM2.5传感器状态
this.pmisConnected = Number(connectRes?.pm25 || 0)
// // 空调状态
// const acStatus = connectRes.ac || 0
// 设备在线,重置离线提示状态
this.hasShownOfflineAlert = false
return true
} else {
console.log('⚠️ 网关设备离线,所有设备状态设为离线')
// 网关离线,所有设备都设为离线状态
this.wdisConnected = 0
this.sdisConnected = 0
this.pmisConnected = 0
// 如果还没有提示过离线,则显示弹窗并停止定时器
if (!this.hasShownOfflineAlert) {
// this.hasShownOfflineAlert = true
const currentTime = this.formatDateTime(new Date());
const alert = {
content: "网管设备不在线",
category: "设备检查",
alertTime: currentTime,
level: "警告",
action: "设备检查",
actionTime: currentTime,
deviceId: "AC_001"
}
this.logAlert(alert)
// 弹窗提示网关设备不在线
uni.showToast({
title: '网管设备不在线!',
icon: 'none',
duration: 3000
})
// 停止数据获取定时器
this.stopDataFetching()
console.log('🛑 设备离线,已停止数据获取定时器')
}
return false
}
} catch (error) {
console.error('❌ 检查连接状态失败:', error)
// 出错时默认设为离线状态
this.wdisConnected = 0
this.sdisConnected = 0
this.pmisConnected = 0
// 如果还没有提示过离线,则显示弹窗并停止定时器
if (!this.hasShownOfflineAlert) {
this.hasShownOfflineAlert = true
// 停止数据获取定时器
this.stopDataFetching()
console.log('🛑 连接检查失败,已停止数据获取定时器')
}
return false
} }
return false
}, },
navigateToParameterRecord() { navigateToParameterRecord() {
try { try {
uni.switchTab({ url: '/pages/parameter/index' }) uni.switchTab({ url: '/pages/parameter/index' })
@ -427,40 +488,6 @@ export default {
uni.showToast({ title: '页面跳转失败', icon: 'none' }) uni.showToast({ title: '页面跳转失败', icon: 'none' })
} }
}, },
// 首次进入系统时创建启动事件
async createStartupEventIfNeeded() {
// 检查是否已经创建过启动事件
if (this.hasCreatedStartupEvent) {
console.log('✅ 启动事件已存在,跳过创建')
return
}
try {
console.log('🚀 首次进入系统,创建启动事件...')
const currentTime = this.formatDateTime(new Date())
const startupEvent = {
eventType: "设备重启",
eventTime: currentTime,
status: "已完成",
description: "设备正常重启维护",
deviceId: "AC_001"
}
console.log('📤 提交启动事件:', startupEvent)
const response = await eventApi.create(startupEvent)
console.log('✅ 启动事件创建成功:', response)
// 标记已创建启动事件
this.hasCreatedStartupEvent = true
// 可以保存到本地存储,避免刷新页面后重复创建
uni.setStorageSync('hasCreatedStartupEvent', true)
} catch (error) {
console.error('❌ 启动事件创建失败:', error)
}
},
// 获取温度控制状态 // 获取温度控制状态
getTemperatureStatus() { getTemperatureStatus() {
@ -483,7 +510,6 @@ export default {
// 加载温湿度区间设置 // 加载温湿度区间设置
async loadWsdSettings(retryCount = 0, maxRetries = 5) { async loadWsdSettings(retryCount = 0, maxRetries = 5) {
try { try {
console.log(`📊 开始加载温湿度区间设置... (第${retryCount + 1}次尝试)`)
const response = await wsdApi.getById(1) // 获取ID为1的默认设置 const response = await wsdApi.getById(1) // 获取ID为1的默认设置
if (response && response.id) { if (response && response.id) {
@ -500,33 +526,22 @@ export default {
// 同时更新设置弹窗中的临时变量 // 同时更新设置弹窗中的临时变量
this.tempSettings = { ...this.temperatureRange } this.tempSettings = { ...this.temperatureRange }
this.humiditySettings = { ...this.humidityRange } this.humiditySettings = { ...this.humidityRange }
console.log('✅ 温湿度区间设置加载成功:', {
temperature: this.temperatureRange,
humidity: this.humidityRange
})
} else { } else {
throw new Error('响应数据格式不正确') throw new Error('响应数据格式不正确')
} }
} catch (error) { } catch (error) {
console.error(`❌ 温湿度区间设置加载失败 (第${retryCount + 1}次):`, error)
if (retryCount < maxRetries) { if (retryCount < maxRetries) {
// 计算重试延迟时间,递增延迟 // 计算重试延迟时间,递增延迟
const delay = Math.min(1000 * Math.pow(2, retryCount), 10000) // 最大延迟10秒 const delay = Math.min(1000 * Math.pow(2, retryCount), 10000) // 最大延迟10秒
console.log(`🔄 ${delay}ms后进行第${retryCount + 2}次重试...`)
setTimeout(() => { setTimeout(() => {
this.loadWsdSettings(retryCount + 1, maxRetries) this.loadWsdSettings(retryCount + 1, maxRetries)
}, delay) }, delay)
} else { } else {
console.error(`❌ 温湿度区间设置加载失败,已达到最大重试次数(${maxRetries + 1}次)`)
// 使用默认值 // 使用默认值
this.temperatureRange = { min: 0, max: 0 } this.temperatureRange = { min: 0, max: 0 }
this.humidityRange = { min: 0, max: 0 } this.humidityRange = { min: 0, max: 0 }
this.tempSettings = { ...this.temperatureRange } this.tempSettings = { ...this.temperatureRange }
this.humiditySettings = { ...this.humidityRange } this.humiditySettings = { ...this.humidityRange }
console.log('🔄 使用默认温湿度区间设置')
} }
} }
}, },
@ -534,31 +549,21 @@ export default {
// 获取最新空调温湿度参数 // 获取最新空调温湿度参数
async getLatestAirConditionerTemperature(retryCount = 0, maxRetries = 3) { async getLatestAirConditionerTemperature(retryCount = 0, maxRetries = 3) {
try { try {
console.log(`📊 开始获取空调温湿度参数... (第${retryCount + 1}次尝试)`)
const res = await thDataApi.getLatest(); const res = await thDataApi.getLatest();
if (res.status === 'success') { if (res.status === 'success') {
// 从接口获取温度和湿度设定值 // 从接口获取温度和湿度设定值
this.targetTemperature = res.temperature || 0; this.targetTemperature = res.temperature || 0;
this.targetHumidity = res.humidity || 0; this.targetHumidity = res.humidity || 0;
console.log('✅ 空调温湿度参数获取成功:', {
targetTemperature: this.targetTemperature,
targetHumidity: this.targetHumidity
})
} else { } else {
throw new Error('响应状态不正确') throw new Error('响应状态不正确')
} }
} catch (error) { } catch (error) {
console.error(`❌ 获取最新空调温湿度参数失败 (第${retryCount + 1}次):`, error)
if (retryCount < maxRetries) { if (retryCount < maxRetries) {
const delay = 2000 * (retryCount + 1) // 递增延迟: 2s, 4s, 6s const delay = 2000 * (retryCount + 1) // 递增延迟: 2s, 4s, 6s
console.log(`🔄 ${delay}ms后进行第${retryCount + 2}次重试...`)
setTimeout(() => { setTimeout(() => {
this.getLatestAirConditionerTemperature(retryCount + 1, maxRetries) this.getLatestAirConditionerTemperature(retryCount + 1, maxRetries)
}, delay) }, delay)
} else { } else {
console.error(`❌ 空调温湿度参数获取失败,已达到最大重试次数(${maxRetries + 1}次)`)
// 接口失败时使用默认值 // 接口失败时使用默认值
this.targetTemperature = 0; this.targetTemperature = 0;
this.targetHumidity = 0; this.targetHumidity = 0;
@ -572,8 +577,6 @@ export default {
console.log('📊 开始获取最新环境数据...') console.log('📊 开始获取最新环境数据...')
} }
const res = await wsdApi.getLatest(); const res = await wsdApi.getLatest();
console.log('📊 接口返回数据:', res)
if (res && res.status === 'success') { if (res && res.status === 'success') {
// 直接更新页面数据不再依赖MQTT数据格式 // 直接更新页面数据不再依赖MQTT数据格式
const temperature = res.wd; const temperature = res.wd;
@ -601,13 +604,6 @@ export default {
// 更新最后更新时间 // 更新最后更新时间
this.lastUpdate = new Date().toLocaleString('zh-CN') this.lastUpdate = new Date().toLocaleString('zh-CN')
console.log('✅ 环境数据更新成功:', {
temperature: this.temperature,
humidity: this.humidity,
pm25: this.cleanliness,
time: this.lastUpdate
})
// 检查报警条件 // 检查报警条件
this.checkAlertsFromApiData({ this.checkAlertsFromApiData({
temperature: this.temperature, temperature: this.temperature,
@ -619,7 +615,6 @@ export default {
console.error('❌ 获取环境数据失败:', error) console.error('❌ 获取环境数据失败:', error)
// 如果是首次调用失败,进行重试 // 如果是首次调用失败,进行重试
if (!isRetry) { if (!isRetry) {
console.log('🔄 首次获取环境数据失败2秒后重试...')
setTimeout(() => { setTimeout(() => {
this.getLatestEnvironmentData(true) this.getLatestEnvironmentData(true)
}, 2000) }, 2000)
@ -627,18 +622,6 @@ export default {
// 不显示错误提示,避免频繁弹窗 // 不显示错误提示,避免频繁弹窗
} }
}, },
async getStatus() {
// const res = await statusApi.getStatus('HDYDCJ_01_UP');
const res = await statusApi.getConnectionStatus();
console.log('📊 接口返回数据:', res)
if (res && typeof res.connected === 'boolean') {
const val = res.connected ? 1 : 0
this.wdisConnected = val
this.sdisConnected = val
this.pmisConnected = val
}
},
// 启动定时获取环境数据 // 启动定时获取环境数据
startDataFetching() { startDataFetching() {
@ -647,10 +630,13 @@ export default {
clearInterval(this.dataFetchInterval) clearInterval(this.dataFetchInterval)
} }
// 每5秒先检查状态如果在线再获取最新环境数据 // 重置离线提示状态,允许重新检测
this.dataFetchInterval = setInterval(async () => { this.hasShownOfflineAlert = false
// 定义数据获取函数
const fetchData = async () => {
try { try {
const isOnline = await this.checkConnectionStatus() const isOnline = await this.checkConnectionStatus();
if (isOnline) { if (isOnline) {
this.getLatestEnvironmentData() this.getLatestEnvironmentData()
} else { } else {
@ -659,9 +645,15 @@ export default {
} catch (error) { } catch (error) {
console.error('❌ 定时检查状态失败:', error) console.error('❌ 定时检查状态失败:', error)
// 容错处理:即使状态检查失败,也尝试获取数据 // 容错处理:即使状态检查失败,也尝试获取数据
this.getLatestEnvironmentData() // this.getLatestEnvironmentData()
} }
}, 5000) }
// 立即执行一次数据获取
// fetchData();
// 每5秒执行一次数据获取
this.dataFetchInterval = setInterval(fetchData, 5000)
}, },
// 停止定时获取环境数据 // 停止定时获取环境数据
@ -770,8 +762,6 @@ export default {
// 只有温度有变化时才检查温度相关报警 // 只有温度有变化时才检查温度相关报警
if (temperatureChanged) { if (temperatureChanged) {
console.log('📊 检测到温度数据变化,检查温度相关报警')
// 1. 温度报警:使用环境控制设置的区间 // 1. 温度报警:使用环境控制设置的区间
if (temperature !== undefined && temperature !== 0 && this.temperatureRange.min !== 0 && this.temperatureRange.max !== 0) { if (temperature !== undefined && temperature !== 0 && this.temperatureRange.min !== 0 && this.temperatureRange.max !== 0) {
if (temperature < this.temperatureRange.min || temperature > this.temperatureRange.max) { if (temperature < this.temperatureRange.min || temperature > this.temperatureRange.max) {
@ -814,8 +804,6 @@ export default {
// 只有湿度有变化时才检查湿度相关报警 // 只有湿度有变化时才检查湿度相关报警
if (humidityChanged) { if (humidityChanged) {
console.log('📊 检测到湿度数据变化,检查湿度相关报警')
// 2. 湿度报警:使用环境控制设置的区间 // 2. 湿度报警:使用环境控制设置的区间
if (humidity !== undefined && humidity !== 0 && this.humidityRange.min !== 0 && this.humidityRange.max !== 0) { if (humidity !== undefined && humidity !== 0 && this.humidityRange.min !== 0 && this.humidityRange.max !== 0) {
if (humidity < this.humidityRange.min || humidity > this.humidityRange.max) { if (humidity < this.humidityRange.min || humidity > this.humidityRange.max) {
@ -858,7 +846,6 @@ export default {
// PM25相关报警检查如果有的话 // PM25相关报警检查如果有的话
if (pm25Changed) { if (pm25Changed) {
console.log('📊 检测到PM25数据变化')
// 这里可以添加PM25相关的报警逻辑 // 这里可以添加PM25相关的报警逻辑
} }
@ -888,7 +875,6 @@ export default {
if (this.targetTemperature > 16) { if (this.targetTemperature > 16) {
const oldTemp = this.targetTemperature const oldTemp = this.targetTemperature
this.targetTemperature-- this.targetTemperature--
console.log('目标温度降低至:', this.targetTemperature + '°C')
this.showTemperatureChangeToast() this.showTemperatureChangeToast()
// 记录温度调节日志 // 记录温度调节日志
this.logTemperatureAdjustment('降低', oldTemp, this.targetTemperature) this.logTemperatureAdjustment('降低', oldTemp, this.targetTemperature)
@ -979,7 +965,6 @@ export default {
if (this.targetTemperature < 30) { if (this.targetTemperature < 30) {
const oldTemp = this.targetTemperature const oldTemp = this.targetTemperature
this.targetTemperature++ this.targetTemperature++
console.log('目标温度提高至:', this.targetTemperature + '°C')
this.showTemperatureChangeToast() this.showTemperatureChangeToast()
// 记录温度调节日志 // 记录温度调节日志
this.logTemperatureAdjustment('升高', oldTemp, this.targetTemperature) this.logTemperatureAdjustment('升高', oldTemp, this.targetTemperature)
@ -996,7 +981,6 @@ export default {
if (this.targetHumidity > 30) { if (this.targetHumidity > 30) {
const oldHumidity = this.targetHumidity const oldHumidity = this.targetHumidity
this.targetHumidity-- this.targetHumidity--
console.log('目标湿度降低至:', this.targetHumidity + '%')
this.showHumidityChangeToast() this.showHumidityChangeToast()
// 记录湿度调节日志 // 记录湿度调节日志
this.logHumidityAdjustment('降低', oldHumidity, this.targetHumidity) this.logHumidityAdjustment('降低', oldHumidity, this.targetHumidity)
@ -1013,7 +997,6 @@ export default {
if (this.targetHumidity < 80) { if (this.targetHumidity < 80) {
const oldHumidity = this.targetHumidity const oldHumidity = this.targetHumidity
this.targetHumidity++ this.targetHumidity++
console.log('目标湿度提高至:', this.targetHumidity + '%')
this.showHumidityChangeToast() this.showHumidityChangeToast()
// 记录湿度调节日志 // 记录湿度调节日志
this.logHumidityAdjustment('升高', oldHumidity, this.targetHumidity) this.logHumidityAdjustment('升高', oldHumidity, this.targetHumidity)
@ -1142,17 +1125,11 @@ export default {
"TagName": "SDSD", // 使用与WSD设备湿度一致的TagName "TagName": "SDSD", // 使用与WSD设备湿度一致的TagName
"method": "setValue" "method": "setValue"
} }
console.log('🌡️ 发送空调温度参数:', temperatureData)
console.log('💧 发送空调湿度参数:', humidityData)
// 调用发送MQTT数据的方法 // 调用发送MQTT数据的方法
const tempSuccess = sendMqttData(temperatureData) const tempSuccess = sendMqttData(temperatureData)
const humiditySuccess = sendMqttData(humidityData) const humiditySuccess = sendMqttData(humidityData)
if (tempSuccess && humiditySuccess) { if (tempSuccess && humiditySuccess) {
console.log('✅ 空调温湿度参数MQTT发送请求已提交')
// 发送成功后调用提交温湿度数据API // 发送成功后调用提交温湿度数据API
try { try {
await this.submitTemperatureData() await this.submitTemperatureData()
@ -1163,8 +1140,6 @@ export default {
duration: 1500 duration: 1500
}) })
} catch (apiError) { } catch (apiError) {
// MQTT发送成功但接口保存失败
console.warn('⚠️ MQTT发送成功但接口保存失败:', apiError)
uni.showToast({ uni.showToast({
title: 'MQTT已发送接口保存失败', title: 'MQTT已发送接口保存失败',
icon: 'none', icon: 'none',
@ -1173,7 +1148,6 @@ export default {
} }
} else { } else {
console.error('❌ 空调参数MQTT发送失败')
uni.showToast({ uni.showToast({
title: 'MQTT发送失败', title: 'MQTT发送失败',
icon: 'error', icon: 'error',
@ -1181,7 +1155,6 @@ export default {
}) })
} }
} catch (error) { } catch (error) {
console.error('❌ 发送空调参数异常:', error)
uni.showToast({ uni.showToast({
title: '参数设置失败', title: '参数设置失败',
icon: 'error', icon: 'error',
@ -1330,8 +1303,6 @@ export default {
"method": "setValue" "method": "setValue"
} }
console.log(`🔧 发送空调${actionName}指令:`, controlData)
// 调用发送MQTT数据的方法 // 调用发送MQTT数据的方法
const success = sendMqttData(controlData) const success = sendMqttData(controlData)
this.acControlLoading = false; this.acControlLoading = false;
@ -1371,11 +1342,8 @@ export default {
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
source: "manual_setting" // 标识为手动设置 source: "manual_setting" // 标识为手动设置
} }
console.log('📤 提交温湿度数据到接口:', temperatureHumidityData)
const response = await thDataApi.submit(temperatureHumidityData) const response = await thDataApi.submit(temperatureHumidityData)
console.log('✅ 温湿度数据接口提交成功:', response)
} catch (error) { } catch (error) {
console.error('❌ 温湿度数据接口提交失败:', error)
// 接口失败不影响MQTT发送只记录日志 // 接口失败不影响MQTT发送只记录日志
throw error // 重新抛出错误,让调用方知道接口失败了 throw error // 重新抛出错误,让调用方知道接口失败了
} }
@ -1383,7 +1351,6 @@ export default {
// 手动重连MQTT // 手动重连MQTT
manualReconnect() { manualReconnect() {
console.log('🔄 用户手动触发MQTT重连')
uni.showToast({ uni.showToast({
title: '正在重连...', title: '正在重连...',
icon: 'loading', icon: 'loading',
@ -1417,12 +1384,8 @@ export default {
updatedTime: new Date().toISOString() updatedTime: new Date().toISOString()
} }
console.log('📤 提交温湿度区间设置:', wsdData)
// 调用API保存设置 // 调用API保存设置
const response = await wsdApi.update(wsdData) const response = await wsdApi.update(wsdData)
console.log('✅ 温湿度区间设置保存成功:', response)
// 保存设置到本地 // 保存设置到本地
this.temperatureRange = { ...this.tempSettings } this.temperatureRange = { ...this.tempSettings }
this.humidityRange = { ...this.humiditySettings } this.humidityRange = { ...this.humiditySettings }
@ -1441,13 +1404,7 @@ export default {
title: '参数设置已保存', title: '参数设置已保存',
icon: 'success' icon: 'success'
}) })
console.log('保存的温度范围:', this.temperatureRange)
console.log('保存的湿度范围:', this.humidityRange)
} catch (error) { } catch (error) {
console.error('❌ 温湿度区间设置保存失败:', error)
// 显示错误提示 // 显示错误提示
uni.showToast({ uni.showToast({
title: '保存失败,请重试', title: '保存失败,请重试',
@ -1543,6 +1500,12 @@ export default {
background-color: #ccc; background-color: #ccc;
} }
/* 禁用按钮样式 */
button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.parameter-details { .parameter-details {
display: flex; display: flex;
@ -1629,7 +1592,7 @@ export default {
.detail-value { .detail-value {
font-size: 28rpx; font-size: 28rpx;
color: #34495e; // color: #34495e;
font-weight: 600; font-weight: 600;
} }
@ -2025,7 +1988,7 @@ export default {
.info-label { .info-label {
font-size: 26rpx; font-size: 26rpx;
color: #34495e; // color: #34495e;
font-weight: 500; font-weight: 500;
} }

View File

@ -13,7 +13,7 @@
<!-- 应用名称 --> <!-- 应用名称 -->
<view class="app-title"> <view class="app-title">
<text class="title-text">上动</text> <text class="title-text">上动</text>
</view> </view>
</view> </view>
@ -81,8 +81,6 @@ export default {
}) })
return return
} }
console.log('🔒 开始登录...')
// 先登录 // 先登录
try { try {
uni.showLoading({ title: '正在登录...' }) uni.showLoading({ title: '正在登录...' })
@ -90,8 +88,6 @@ export default {
username: this.username || 'admin', username: this.username || 'admin',
password: this.password password: this.password
}) })
console.log('🔒 登录结果:', loginRes)
if (loginRes.success) { if (loginRes.success) {
// 可选:如果返回 token保存以备后续请求使用 // 可选:如果返回 token保存以备后续请求使用
if (loginRes && loginRes.token) { if (loginRes && loginRes.token) {
@ -112,8 +108,6 @@ export default {
// 调用MQTT重连函数 // 调用MQTT重连函数
try { try {
manualReconnect() manualReconnect()
console.log('✅ MQTT重连函数已调用')
// 延迟跳转给MQTT连接一些时间 // 延迟跳转给MQTT连接一些时间
setTimeout(() => { setTimeout(() => {
// 更新loading文本 // 更新loading文本
@ -126,7 +120,6 @@ export default {
uni.switchTab({ uni.switchTab({
url: '/pages/environment/index', url: '/pages/environment/index',
success: () => { success: () => {
console.log('✅ 成功跳转到环境参数页面')
uni.showToast({ uni.showToast({
title: '系统连接成功', title: '系统连接成功',
icon: 'success', icon: 'success',
@ -134,12 +127,10 @@ export default {
}) })
}, },
fail: (err) => { fail: (err) => {
console.error('❌ 跳转到tabbar失败:', err);
// 如果失败尝试使用redirectTo // 如果失败尝试使用redirectTo
uni.redirectTo({ uni.redirectTo({
url: '/pages/environment/index', url: '/pages/environment/index',
success: () => { success: () => {
console.log('✅ 使用redirectTo成功跳转')
uni.showToast({ uni.showToast({
title: '系统连接成功', title: '系统连接成功',
icon: 'success', icon: 'success',
@ -147,7 +138,6 @@ export default {
}) })
}, },
fail: (redirectErr) => { fail: (redirectErr) => {
console.error('❌ redirectTo也失败:', redirectErr)
uni.showToast({ uni.showToast({
title: '页面跳转失败', title: '页面跳转失败',
icon: 'error', icon: 'error',
@ -161,7 +151,6 @@ export default {
}, 300) // 1秒后开始跳转 }, 300) // 1秒后开始跳转
} catch (error) { } catch (error) {
console.error('❌ MQTT重连失败:', error)
uni.hideLoading() uni.hideLoading()
uni.showToast({ uni.showToast({
title: 'MQTT连接失败', title: 'MQTT连接失败',
@ -187,8 +176,6 @@ export default {
}) })
return return
} }
console.log('🔧 用户点击进入系统开始MQTT重连...')
} }
}, },
} }

View File

@ -313,14 +313,11 @@ export default {
} }
}, },
onLoad() { onLoad() {
console.log('参数记录页面加载', new Date().toISOString().split('T')[0])
this.initMqttListener() this.initMqttListener()
// 调用历史数据接口 // 调用历史数据接口
this.getHistoryData() this.getHistoryData()
}, },
onShow() { onShow() {
console.log('📱 参数记录页面显示,触发页面更新')
// 重置时间相关状态 // 重置时间相关状态
this.resetTimeState() this.resetTimeState()
@ -333,7 +330,6 @@ export default {
} }
}, },
onHide() { onHide() {
console.log('📱 参数记录页面隐藏,清除数据缓存')
// 页面隐藏时清除数据,防止缓存 // 页面隐藏时清除数据,防止缓存
this.clearPageData() this.clearPageData()
}, },
@ -349,14 +345,9 @@ export default {
methods: { methods: {
// 重置时间相关状态 // 重置时间相关状态
resetTimeState() { resetTimeState() {
console.log('🔄 重置时间相关状态')
// 页面切换后重置为默认查询模式过去24小时 // 页面切换后重置为默认查询模式过去24小时
this.queryMode = 'default' this.queryMode = 'default'
this.selectedDate = this.getTodayDate() this.selectedDate = this.getTodayDate()
console.log('📅 重置为默认查询模式,日期:', this.selectedDate)
// 强制更新X轴标签 // 强制更新X轴标签
this.$nextTick(() => { this.$nextTick(() => {
this.updateCharts() this.updateCharts()
@ -365,8 +356,6 @@ export default {
// 清除页面数据缓存 // 清除页面数据缓存
clearPageData() { clearPageData() {
console.log('🧹 清除页面数据缓存')
// 清除图表数据 // 清除图表数据
this.temperatureData = new Array(24).fill(0) this.temperatureData = new Array(24).fill(0)
this.humidityData = new Array(24).fill(0) this.humidityData = new Array(24).fill(0)
@ -427,17 +416,6 @@ export default {
const year = today.getFullYear() const year = today.getFullYear()
const month = String(today.getMonth() + 1).padStart(2, '0') const month = String(today.getMonth() + 1).padStart(2, '0')
const day = String(today.getDate()).padStart(2, '0') const day = String(today.getDate()).padStart(2, '0')
console.log('📅 获取今天日期:', {
'原始Date对象': today,
'ISO字符串': today.toISOString(),
'本地字符串': today.toLocaleString(),
'本地日期字符串': today.toLocaleDateString(),
'本地时间字符串': today.toLocaleTimeString(),
'时区偏移': today.getTimezoneOffset(),
'格式化结果': `${year}-${month}-${day}`
})
return `${year}-${month}-${day}` return `${year}-${month}-${day}`
}, },
@ -531,12 +509,6 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
this.updateCharts() this.updateCharts()
}) })
console.log('✅ 图表数据更新完成:', {
temperature: this.temperatureData[dataIndex],
humidity: this.humidityData[dataIndex],
dataIndex: dataIndex
})
} else { } else {
console.log('⚠️ 非WSD设备数据跳过图表更新:', data.deviceType) console.log('⚠️ 非WSD设备数据跳过图表更新:', data.deviceType)
} }
@ -564,7 +536,6 @@ export default {
// 日期选择处理,选择后直接查询 // 日期选择处理,选择后直接查询
onDateChange(e) { onDateChange(e) {
this.selectedDate = e.detail.value this.selectedDate = e.detail.value
console.log('选择的日期:', this.selectedDate)
this.queryMode = 'date' // 切换到按日期查询模式 this.queryMode = 'date' // 切换到按日期查询模式
// 显示加载状态 // 显示加载状态
@ -575,12 +546,6 @@ export default {
// 重新获取历史数据 // 重新获取历史数据
this.getHistoryDataByDate().finally(() => { this.getHistoryDataByDate().finally(() => {
uni.hideLoading() uni.hideLoading()
uni.showToast({
title: '查询成功',
icon: 'success',
duration: 1500
})
}) })
}, },
@ -616,9 +581,6 @@ export default {
startTime: startTime, startTime: startTime,
endTime: endTime endTime: endTime
} }
console.log('📊 请求历史数据(按日期):', params, `${retryCount + 1}次尝试`)
// 增加超时时间到20秒 // 增加超时时间到20秒
const response = await dataHistoryApi.getHistory(params, { timeout: 20000 }) const response = await dataHistoryApi.getHistory(params, { timeout: 20000 })
@ -637,7 +599,6 @@ export default {
// 保存查询事件 // 保存查询事件
await this.createQueryEvent('success', response.length) await this.createQueryEvent('success', response.length)
} else { } else {
console.log('📊 没有历史数据,显示空状态')
// 没有数据时显示空状态 // 没有数据时显示空状态
this.showEmptyState() this.showEmptyState()
@ -655,11 +616,8 @@ export default {
return response return response
} catch (error) { } catch (error) {
console.error('❌ 历史数据获取失败:', error)
// 如果是超时错误且重试次数少于2次则重试 // 如果是超时错误且重试次数少于2次则重试
if (error.message.includes('timeout') && retryCount < 2) { if (error.message.includes('timeout') && retryCount < 2) {
console.log(`🔄 网络超时,正在重试... (${retryCount + 1}/2)`)
uni.showToast({ uni.showToast({
title: `网络超时,重试中...`, title: `网络超时,重试中...`,
icon: 'loading', icon: 'loading',
@ -712,9 +670,6 @@ export default {
startTime: startTime, startTime: startTime,
endTime: endTime endTime: endTime
} }
console.log('📊 请求历史数据过去24小时:', params, `${retryCount + 1}次尝试`)
// 增加超时时间到20秒 // 增加超时时间到20秒
const response = await dataHistoryApi.getHistory(params, { timeout: 20000 }) const response = await dataHistoryApi.getHistory(params, { timeout: 20000 })
@ -733,7 +688,6 @@ export default {
// 保存查询事件 // 保存查询事件
await this.createQueryEvent('success', response.length) await this.createQueryEvent('success', response.length)
} else { } else {
console.log('📊 没有历史数据,显示空状态')
// 没有数据时显示空状态 // 没有数据时显示空状态
this.showEmptyState() this.showEmptyState()
@ -751,11 +705,8 @@ export default {
return response return response
} catch (error) { } catch (error) {
console.error('❌ 历史数据获取失败:', error)
// 如果是超时错误且重试次数少于2次则重试 // 如果是超时错误且重试次数少于2次则重试
if (error.message.includes('timeout') && retryCount < 2) { if (error.message.includes('timeout') && retryCount < 2) {
console.log(`🔄 网络超时,正在重试... (${retryCount + 1}/2)`)
uni.showToast({ uni.showToast({
title: `网络超时,重试中...`, title: `网络超时,重试中...`,
icon: 'loading', icon: 'loading',
@ -795,8 +746,6 @@ export default {
// 使用默认数据 // 使用默认数据
useDefaultData() { useDefaultData() {
console.log('🎨 使用默认数据展示图表')
// 使用预设的示例数据 // 使用预设的示例数据
this.temperatureData = [22, 25, 28, 32, 35, 38, 40, 38, 35, 32, 28, 25, 22, 20, 18, 20, 22, 25, 28, 30, 32, 30, 28, 25] this.temperatureData = [22, 25, 28, 32, 35, 38, 40, 38, 35, 32, 28, 25, 22, 20, 18, 20, 22, 25, 28, 30, 32, 30, 28, 25]
this.humidityData = [45, 50, 55, 60, 65, 70, 75, 70, 65, 60, 55, 50, 45, 40, 35, 40, 45, 50, 55, 60, 65, 60, 55, 50] this.humidityData = [45, 50, 55, 60, 65, 70, 75, 70, 65, 60, 55, 50, 45, 40, 35, 40, 45, 50, 55, 60, 65, 60, 55, 50]
@ -817,8 +766,6 @@ export default {
// 显示空状态 // 显示空状态
showEmptyState() { showEmptyState() {
console.log('🎨 显示空状态默认值为0')
// 设置默认数据为0 // 设置默认数据为0
this.temperatureData = new Array(24).fill(0) this.temperatureData = new Array(24).fill(0)
this.humidityData = new Array(24).fill(0) this.humidityData = new Array(24).fill(0)
@ -830,9 +777,6 @@ export default {
}) })
}, },
processHistoryData(data) { processHistoryData(data) {
console.log('🔄 开始处理历史数据:', data.length, '条记录')
console.log('📊 原始数据示例:', data[0])
// 初始化图表数据 // 初始化图表数据
this.chartData = { this.chartData = {
temperature: [], temperature: [],
@ -874,7 +818,6 @@ export default {
if (dataIndex < 0 || dataIndex >= 24) { if (dataIndex < 0 || dataIndex >= 24) {
console.log(`⚠️ 数据超出范围,跳过 - 索引:${dataIndex}`)
return // 超出范围的数据跳过 return // 超出范围的数据跳过
} }
} }
@ -910,11 +853,6 @@ export default {
} }
}) })
console.log('📈 处理后的图表数据:', {
temperature: this.chartData.temperature.length,
humidity: this.chartData.humidity.length,
pm: this.chartData.pm.length
})
// 重新绘制图表 // 重新绘制图表
this.$nextTick(() => { this.$nextTick(() => {
@ -924,8 +862,6 @@ export default {
// 使用历史数据更新图表 // 使用历史数据更新图表
updateChartsWithHistoryData() { updateChartsWithHistoryData() {
console.log('🎨 使用历史数据更新图表')
const xAxisLabels = this.generateXAxisLabels() const xAxisLabels = this.generateXAxisLabels()
// 处理温度数据 // 处理温度数据

View File

@ -91,12 +91,15 @@ export const wsdApi = {
} }
export const statusApi = { export const statusApi = {
getStatus(topic) { // connected 判断设备端是否连接
return httpService.get('/api/mqtt/subscription/status?topic=HDYDCJ_01_UP') getStatus() {
return httpService.get('/api/emqx/clients/HDYDCJ_01')
}, },
getConnectionStatus() { getConnectionStatus() {
return httpService.get('/api/mqtt/connection/status') // 空调、温湿度、pm 是否在线
// http://110.40.171.179:7999/api/health/latest
return httpService.get('/api/health/latest')
} }
} }