diff --git a/src/components/AlarmRecord.vue b/src/components/AlarmRecord.vue index 6634f19..7e96462 100644 --- a/src/components/AlarmRecord.vue +++ b/src/components/AlarmRecord.vue @@ -1,20 +1,6 @@ @@ -94,12 +71,7 @@ 正在加载更多... - - - - + @@ -138,29 +110,6 @@ const endTime = ref(''); // MQTT报警服务接口(预留) 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) => { try { @@ -193,8 +142,6 @@ const mqttAlarmService = { } } - console.log('📅 查询时间范围:', queryStartTime, '至', queryEndTime); - // 调用分页获取告警接口 const response = await alertApi.getListByCreateTime({ page: page, @@ -268,7 +215,6 @@ const mqttAlarmService = { // 获取实时报警 getRealtimeAlarms: async () => { - console.log('获取实时报警'); try { // 模拟实时报警数据 const contents = ['温度超标', '湿度异常', '压力偏高', '洁净度超标', '设备故障', '通讯中断']; @@ -319,7 +265,6 @@ const mqttAlarmService = { // 确认报警 confirmAlarm: async (alarmId) => { - console.log('确认报警:', alarmId); try { // 模拟确认操作 await new Promise(resolve => setTimeout(resolve, 300)); @@ -340,7 +285,6 @@ const mqttAlarmService = { // 清空报警记录 clearAlarms: async () => { - console.log('清空报警记录'); try { // 模拟清空操作 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; @@ -434,8 +364,6 @@ const onScroll = (e) => { }; const onScrollToLower = () => { - console.log('滚动到底部,尝试加载更多数据'); - // 如果正在加载或没有更多数据,则不处理 if (isLoadingMore.value || !hasMoreData.value) { console.log('正在加载中或无更多数据,跳过'); @@ -457,19 +385,11 @@ const scrollToTop = () => { // 日期选择处理,选择后直接查询 const onDateChange = async (e) => { selectedDate.value = e.detail.value; - console.log('选择的日期:', selectedDate.value); // 自动构建开始和结束时间 if (selectedDate.value) { startTime.value = `${selectedDate.value} 00:00:00`; endTime.value = `${selectedDate.value} 23:59:59`; - console.log('开始时间:', startTime.value); - console.log('结束时间:', endTime.value); - - // 选择日期后直接查询 - console.log('🔍 开始查询报警记录'); - console.log('查询时间范围:', startTime.value, '至', endTime.value); - try { // 重置分页状态 currentPage.value = 0; @@ -478,12 +398,6 @@ const onDateChange = async (e) => { // 使用选择的日期范围查询 await mqttAlarmService.getHistoryAlarms(0, pageSize.value, false); - - uni.showToast({ - title: '查询成功', - icon: 'success', - duration: 1500 - }); } catch (error) { console.error('❌ 查询失败:', error); } diff --git a/src/components/SystemLog.vue b/src/components/SystemLog.vue index 5f90e6e..202b7c3 100644 --- a/src/components/SystemLog.vue +++ b/src/components/SystemLog.vue @@ -173,12 +173,10 @@ const formatDateTime = (dateString) => { const mqttLogService = { // 连接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); @@ -189,14 +187,12 @@ const mqttLogService = { // 订阅日志数据 subscribeLogData: () => { - console.log('订阅系统日志数据'); // 这里后期会实现真实的MQTT日志订阅 return Promise.resolve(); }, // 获取历史日志(分页) getHistoryLogs: async (page = 0, size = 20, isLoadMore = false, queryDate = '') => { - console.log(`📄 加载第${page}页数据,每页${size}条,查询日期:${queryDate}`); try { if (!isLoadMore) { isLoading.value = true; @@ -227,8 +223,6 @@ const mqttLogService = { } } - console.log('📅 查询时间范围:', queryStartTime, '至', queryEndTime); - // 构建查询参数 const params = { page: page, @@ -258,11 +252,7 @@ const mqttLogService = { // 更新分页状态 currentPage.value = page; hasMoreData.value = newLogs.length === size; // 如果返回的数据少于请求的数量,说明没有更多数据 - - console.log(`✅ 第${page}页数据加载完成,共${newLogs.length}条`); - } catch (error) { - console.error('❌ 获取历史日志失败:', error); if (!isLoadMore) { // 首次加载失败时显示空数据 logList.value = []; @@ -277,7 +267,6 @@ const mqttLogService = { // 断开连接 disconnect: () => { - console.log('MQTT日志服务断开连接'); isConnected.value = false; // 这里后期会实现真实的MQTT断开 } @@ -316,14 +305,12 @@ const onScroll = (e) => { }; const onScrollToLower = () => { - console.log('📜 滚动到底部,触发加载更多'); if (isLoadingMore.value || !hasMoreData.value) { console.log('⏸️ 正在加载中或没有更多数据,跳过加载'); return; } const nextPage = currentPage.value + 1; - console.log(`📄 开始加载第${nextPage}页数据`); mqttLogService.getHistoryLogs(nextPage, pageSize.value, true, props.queryDate); }; @@ -335,19 +322,10 @@ const scrollToTop = () => { // 日期选择处理,选择后直接查询 const onDateChange = async (e) => { selectedDate.value = e.detail.value; - console.log('选择的日期:', selectedDate.value); - // 自动构建开始和结束时间 if (selectedDate.value) { startTime.value = `${selectedDate.value} 00:00:00`; endTime.value = `${selectedDate.value} 23:59:59`; - console.log('开始时间:', startTime.value); - console.log('结束时间:', endTime.value); - - // 选择日期后直接查询 - console.log('🔍 开始查询系统日志'); - console.log('查询时间范围:', startTime.value, '至', endTime.value); - try { // 重置分页状态 currentPage.value = 0; @@ -356,12 +334,6 @@ const onDateChange = async (e) => { // 使用选择的日期范围查询 await mqttLogService.getHistoryLogs(0, pageSize.value, false, selectedDate.value); - - uni.showToast({ - title: '查询成功', - icon: 'success', - duration: 1500 - }); } catch (error) { console.error('❌ 查询失败:', error); } @@ -373,12 +345,8 @@ const onDateChange = async (e) => { // 组件生命周期 onMounted(async () => { try { - // 连接MQTT并初始化 - // await mqttLogService.connect(); - // await mqttLogService.subscribeLogData(); await mqttLogService.getHistoryLogs(0, pageSize.value, false, props.queryDate); } catch (error) { - console.error('日志系统初始化失败:', error); uni.showToast({ title: '连接失败', icon: 'error' @@ -388,7 +356,6 @@ onMounted(async () => { // 刷新数据方法 const refreshData = async () => { - console.log('🔄 刷新系统日志数据') try { // 重置分页状态 currentPage.value = 0; @@ -404,7 +371,6 @@ const refreshData = async () => { // 按日期查询方法 const queryByDate = async (queryDate) => { - console.log('📅 按日期查询系统日志:', queryDate) try { // 重置分页状态 currentPage.value = 0; diff --git a/src/manifest.json b/src/manifest.json index 1ab820d..e69b90d 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,5 +1,5 @@ { - "name" : "上动物联", + "name" : "上动智联", "appid" : "__UNI__0B541D7", "description" : "", "versionName" : "1.1.0", diff --git a/src/pages/environment/index.vue b/src/pages/environment/index.vue index 6ce8179..2c6d75f 100644 --- a/src/pages/environment/index.vue +++ b/src/pages/environment/index.vue @@ -95,7 +95,7 @@ class="ac-power-btn" :class="getAcButtonClass()" @click="toggleAirConditioner" - :disabled="!canOperateAc() || acControlLoading" + :disabled="!canOperateAc() || acControlLoading || !isGatewayOnline" > {{ getAcButtonText() }} @@ -110,7 +110,7 @@ - @@ -122,10 +122,11 @@ @input="onTemperatureInput" @blur="onTemperatureBlur" @focus="onTemperatureFocus" + :disabled="!isGatewayOnline" /> °C - @@ -142,7 +143,7 @@ - @@ -154,10 +155,11 @@ @input="onHumidityInput" @blur="onHumidityBlur" @focus="onHumidityFocus" + :disabled="!isGatewayOnline" /> % - @@ -194,7 +196,7 @@ - @@ -253,8 +255,8 @@ - - + + @@ -297,6 +299,7 @@ export default { wdisConnected: 0, sdisConnected: 0, pmisConnected: 0, + isGatewayOnline: false, // 网关是否在线 禁用按钮 connectionStatus: { isConnected: false, lastUpdate: null @@ -329,7 +332,9 @@ export default { humidity: null, pm25: null }, - dataFetchInterval: null + dataFetchInterval: null, + // 是否已经提示过设备离线 + hasShownOfflineAlert: false } }, onLoad() { @@ -345,23 +350,17 @@ export default { this.initMqttListener(); }, onShow() { - console.log('📱 环境参数页面显示,触发页面更新'); this.init(); - // 注意:init() 中已经包含了状态检查,不需要单独调用 getStatus() - // 重新启动定时器 - this.startDataFetching(); - // // 只有在非首次显示时才重新获取最新空调温度 - // if (this.hasCreatedStartupEvent) { - // this.init(); - // } + // 页面显示时重新启动定时器(如果之前被停止了) + if (!this.dataFetchInterval) { + this.startDataFetching(); + } }, onHide() { - console.log('📱 环境参数页面隐藏,停止定时器'); // 页面隐藏时停止定时器 this.stopDataFetching(); }, onUnload() { - console.log('📱 环境参数页面卸载,清理所有资源'); // 页面卸载时移除监听器 if (this.dataUpdateHandler) { mqttDataManager.removeListener('dataUpdate', this.dataUpdateHandler) @@ -378,48 +377,110 @@ export default { // 停止数据获取定时器 this.stopDataFetching() }, + computed: { + // // 判断网关是否在线 + // isGatewayOnline() { + // // 如果温湿度传感器或PM传感器任何一个在线,则认为网关在线 + // return this.wdisConnected === 1 || this.pmisConnected === 1 + // } + }, methods: { async init() { - console.log('📱 开始初始化环境参数页面...') - // 先调用状态接口判断是否在线 try { - const isOnline = await this.checkConnectionStatus() - if (isOnline) { - console.log('✅ 设备在线,开始更新数据接口') - // 获取最新空调温度 - this.getLatestAirConditionerTemperature() - // 获取最新温湿度数据 - this.getLatestEnvironmentData() - // 首次进入系统时创建启动事件 - // this.createStartupEventIfNeeded() - // 获取温湿度区间设置 - this.loadWsdSettings() - } else { - console.log('⚠️ 设备离线,跳过数据接口更新') - } + const isOnline = await this.checkConnectionStatus(); + this.isGatewayOnline = isOnline; + if (isOnline) { + // // 获取最新空调温度 + this.getLatestAirConditionerTemperature() + // 获取最新温湿度数据 + this.getLatestEnvironmentData() + // 首次进入系统时创建启动事件 + // this.createStartupEventIfNeeded() + // 获取温湿度区间设置 + this.loadWsdSettings() + } + } catch (error) { - console.error('❌ 检查连接状态失败:', error) - // 即使检查失败,也尝试获取数据(容错处理) - this.getLatestAirConditionerTemperature() - this.getLatestEnvironmentData() - this.loadWsdSettings() + } - // 注意:定时器在 onShow 中启动,避免重复启动 }, // 检查连接状态,返回是否在线 async checkConnectionStatus() { - 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 - return res.connected + try { + // 1. 首先调用statusApi.getStatus接口判断网关设备是否在线 + const res = await statusApi.getStatus(); + if (res.connected) { + // 2. 如果网关在线,调用statusApi.getConnectionStatus判断空调、PM等设备是否在线 + const connectRes = await statusApi.getConnectionStatus(); + // 3. 更新各设备连接状态 + // 温湿度传感器状态 (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() { try { uni.switchTab({ url: '/pages/parameter/index' }) @@ -427,40 +488,6 @@ export default { 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() { @@ -483,7 +510,6 @@ export default { // 加载温湿度区间设置 async loadWsdSettings(retryCount = 0, maxRetries = 5) { try { - console.log(`📊 开始加载温湿度区间设置... (第${retryCount + 1}次尝试)`) const response = await wsdApi.getById(1) // 获取ID为1的默认设置 if (response && response.id) { @@ -500,33 +526,22 @@ export default { // 同时更新设置弹窗中的临时变量 this.tempSettings = { ...this.temperatureRange } this.humiditySettings = { ...this.humidityRange } - - console.log('✅ 温湿度区间设置加载成功:', { - temperature: this.temperatureRange, - humidity: this.humidityRange - }) } else { throw new Error('响应数据格式不正确') } } catch (error) { - console.error(`❌ 温湿度区间设置加载失败 (第${retryCount + 1}次):`, error) - if (retryCount < maxRetries) { // 计算重试延迟时间,递增延迟 const delay = Math.min(1000 * Math.pow(2, retryCount), 10000) // 最大延迟10秒 - console.log(`🔄 ${delay}ms后进行第${retryCount + 2}次重试...`) - setTimeout(() => { this.loadWsdSettings(retryCount + 1, maxRetries) }, delay) } else { - console.error(`❌ 温湿度区间设置加载失败,已达到最大重试次数(${maxRetries + 1}次)`) // 使用默认值 this.temperatureRange = { min: 0, max: 0 } this.humidityRange = { min: 0, max: 0 } this.tempSettings = { ...this.temperatureRange } this.humiditySettings = { ...this.humidityRange } - console.log('🔄 使用默认温湿度区间设置') } } }, @@ -534,31 +549,21 @@ export default { // 获取最新空调温湿度参数 async getLatestAirConditionerTemperature(retryCount = 0, maxRetries = 3) { try { - console.log(`📊 开始获取空调温湿度参数... (第${retryCount + 1}次尝试)`) const res = await thDataApi.getLatest(); if (res.status === 'success') { // 从接口获取温度和湿度设定值 this.targetTemperature = res.temperature || 0; this.targetHumidity = res.humidity || 0; - console.log('✅ 空调温湿度参数获取成功:', { - targetTemperature: this.targetTemperature, - targetHumidity: this.targetHumidity - }) } else { throw new Error('响应状态不正确') } } catch (error) { - console.error(`❌ 获取最新空调温湿度参数失败 (第${retryCount + 1}次):`, error) - if (retryCount < maxRetries) { const delay = 2000 * (retryCount + 1) // 递增延迟: 2s, 4s, 6s - console.log(`🔄 ${delay}ms后进行第${retryCount + 2}次重试...`) - setTimeout(() => { this.getLatestAirConditionerTemperature(retryCount + 1, maxRetries) }, delay) } else { - console.error(`❌ 空调温湿度参数获取失败,已达到最大重试次数(${maxRetries + 1}次)`) // 接口失败时使用默认值 this.targetTemperature = 0; this.targetHumidity = 0; @@ -572,8 +577,6 @@ export default { console.log('📊 开始获取最新环境数据...') } const res = await wsdApi.getLatest(); - console.log('📊 接口返回数据:', res) - if (res && res.status === 'success') { // 直接更新页面数据,不再依赖MQTT数据格式 const temperature = res.wd; @@ -601,13 +604,6 @@ export default { // 更新最后更新时间 this.lastUpdate = new Date().toLocaleString('zh-CN') - console.log('✅ 环境数据更新成功:', { - temperature: this.temperature, - humidity: this.humidity, - pm25: this.cleanliness, - time: this.lastUpdate - }) - // 检查报警条件 this.checkAlertsFromApiData({ temperature: this.temperature, @@ -619,7 +615,6 @@ export default { console.error('❌ 获取环境数据失败:', error) // 如果是首次调用失败,进行重试 if (!isRetry) { - console.log('🔄 首次获取环境数据失败,2秒后重试...') setTimeout(() => { this.getLatestEnvironmentData(true) }, 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() { @@ -647,10 +630,13 @@ export default { clearInterval(this.dataFetchInterval) } - // 每5秒先检查状态,如果在线再获取最新环境数据 - this.dataFetchInterval = setInterval(async () => { + // 重置离线提示状态,允许重新检测 + this.hasShownOfflineAlert = false + + // 定义数据获取函数 + const fetchData = async () => { try { - const isOnline = await this.checkConnectionStatus() + const isOnline = await this.checkConnectionStatus(); if (isOnline) { this.getLatestEnvironmentData() } else { @@ -659,9 +645,15 @@ export default { } catch (error) { console.error('❌ 定时检查状态失败:', error) // 容错处理:即使状态检查失败,也尝试获取数据 - this.getLatestEnvironmentData() + // this.getLatestEnvironmentData() } - }, 5000) + } + + // 立即执行一次数据获取 + // fetchData(); + + // 每5秒执行一次数据获取 + this.dataFetchInterval = setInterval(fetchData, 5000) }, // 停止定时获取环境数据 @@ -770,8 +762,6 @@ export default { // 只有温度有变化时才检查温度相关报警 if (temperatureChanged) { - console.log('📊 检测到温度数据变化,检查温度相关报警') - // 1. 温度报警:使用环境控制设置的区间 if (temperature !== undefined && temperature !== 0 && this.temperatureRange.min !== 0 && this.temperatureRange.max !== 0) { if (temperature < this.temperatureRange.min || temperature > this.temperatureRange.max) { @@ -814,8 +804,6 @@ export default { // 只有湿度有变化时才检查湿度相关报警 if (humidityChanged) { - console.log('📊 检测到湿度数据变化,检查湿度相关报警') - // 2. 湿度报警:使用环境控制设置的区间 if (humidity !== undefined && humidity !== 0 && this.humidityRange.min !== 0 && this.humidityRange.max !== 0) { if (humidity < this.humidityRange.min || humidity > this.humidityRange.max) { @@ -858,7 +846,6 @@ export default { // PM25相关报警检查(如果有的话) if (pm25Changed) { - console.log('📊 检测到PM25数据变化') // 这里可以添加PM25相关的报警逻辑 } @@ -888,7 +875,6 @@ export default { if (this.targetTemperature > 16) { const oldTemp = this.targetTemperature this.targetTemperature-- - console.log('目标温度降低至:', this.targetTemperature + '°C') this.showTemperatureChangeToast() // 记录温度调节日志 this.logTemperatureAdjustment('降低', oldTemp, this.targetTemperature) @@ -979,7 +965,6 @@ export default { if (this.targetTemperature < 30) { const oldTemp = this.targetTemperature this.targetTemperature++ - console.log('目标温度提高至:', this.targetTemperature + '°C') this.showTemperatureChangeToast() // 记录温度调节日志 this.logTemperatureAdjustment('升高', oldTemp, this.targetTemperature) @@ -996,7 +981,6 @@ export default { if (this.targetHumidity > 30) { const oldHumidity = this.targetHumidity this.targetHumidity-- - console.log('目标湿度降低至:', this.targetHumidity + '%') this.showHumidityChangeToast() // 记录湿度调节日志 this.logHumidityAdjustment('降低', oldHumidity, this.targetHumidity) @@ -1013,7 +997,6 @@ export default { if (this.targetHumidity < 80) { const oldHumidity = this.targetHumidity this.targetHumidity++ - console.log('目标湿度提高至:', this.targetHumidity + '%') this.showHumidityChangeToast() // 记录湿度调节日志 this.logHumidityAdjustment('升高', oldHumidity, this.targetHumidity) @@ -1142,17 +1125,11 @@ export default { "TagName": "SDSD", // 使用与WSD设备湿度一致的TagName "method": "setValue" } - - console.log('🌡️ 发送空调温度参数:', temperatureData) - console.log('💧 发送空调湿度参数:', humidityData) - // 调用发送MQTT数据的方法 const tempSuccess = sendMqttData(temperatureData) const humiditySuccess = sendMqttData(humidityData) if (tempSuccess && humiditySuccess) { - console.log('✅ 空调温湿度参数MQTT发送请求已提交') - // 发送成功后调用提交温湿度数据API try { await this.submitTemperatureData() @@ -1163,8 +1140,6 @@ export default { duration: 1500 }) } catch (apiError) { - // MQTT发送成功,但接口保存失败 - console.warn('⚠️ MQTT发送成功,但接口保存失败:', apiError) uni.showToast({ title: 'MQTT已发送,接口保存失败', icon: 'none', @@ -1173,7 +1148,6 @@ export default { } } else { - console.error('❌ 空调参数MQTT发送失败') uni.showToast({ title: 'MQTT发送失败', icon: 'error', @@ -1181,7 +1155,6 @@ export default { }) } } catch (error) { - console.error('❌ 发送空调参数异常:', error) uni.showToast({ title: '参数设置失败', icon: 'error', @@ -1330,8 +1303,6 @@ export default { "method": "setValue" } - console.log(`🔧 发送空调${actionName}指令:`, controlData) - // 调用发送MQTT数据的方法 const success = sendMqttData(controlData) this.acControlLoading = false; @@ -1371,11 +1342,8 @@ export default { timestamp: new Date().toISOString(), source: "manual_setting" // 标识为手动设置 } - console.log('📤 提交温湿度数据到接口:', temperatureHumidityData) const response = await thDataApi.submit(temperatureHumidityData) - console.log('✅ 温湿度数据接口提交成功:', response) } catch (error) { - console.error('❌ 温湿度数据接口提交失败:', error) // 接口失败不影响MQTT发送,只记录日志 throw error // 重新抛出错误,让调用方知道接口失败了 } @@ -1383,7 +1351,6 @@ export default { // 手动重连MQTT manualReconnect() { - console.log('🔄 用户手动触发MQTT重连') uni.showToast({ title: '正在重连...', icon: 'loading', @@ -1417,12 +1384,8 @@ export default { updatedTime: new Date().toISOString() } - console.log('📤 提交温湿度区间设置:', wsdData) - // 调用API保存设置 const response = await wsdApi.update(wsdData) - console.log('✅ 温湿度区间设置保存成功:', response) - // 保存设置到本地 this.temperatureRange = { ...this.tempSettings } this.humidityRange = { ...this.humiditySettings } @@ -1441,13 +1404,7 @@ export default { title: '参数设置已保存', icon: 'success' }) - - console.log('保存的温度范围:', this.temperatureRange) - console.log('保存的湿度范围:', this.humidityRange) - } catch (error) { - console.error('❌ 温湿度区间设置保存失败:', error) - // 显示错误提示 uni.showToast({ title: '保存失败,请重试', @@ -1543,6 +1500,12 @@ export default { background-color: #ccc; } +/* 禁用按钮样式 */ +button:disabled { + opacity: 0.5; + cursor: not-allowed; +} + .parameter-details { display: flex; @@ -1629,7 +1592,7 @@ export default { .detail-value { font-size: 28rpx; - color: #34495e; + // color: #34495e; font-weight: 600; } @@ -2025,7 +1988,7 @@ export default { .info-label { font-size: 26rpx; - color: #34495e; + // color: #34495e; font-weight: 500; } diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index c612162..bdcee96 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -13,7 +13,7 @@ - 上动物联 + 上动智联 @@ -81,8 +81,6 @@ export default { }) return } - console.log('🔒 开始登录...') - // 先登录 try { uni.showLoading({ title: '正在登录...' }) @@ -90,8 +88,6 @@ export default { username: this.username || 'admin', password: this.password }) - - console.log('🔒 登录结果:', loginRes) if (loginRes.success) { // 可选:如果返回 token,保存以备后续请求使用 if (loginRes && loginRes.token) { @@ -112,8 +108,6 @@ export default { // 调用MQTT重连函数 try { manualReconnect() - console.log('✅ MQTT重连函数已调用') - // 延迟跳转,给MQTT连接一些时间 setTimeout(() => { // 更新loading文本 @@ -126,7 +120,6 @@ export default { uni.switchTab({ url: '/pages/environment/index', success: () => { - console.log('✅ 成功跳转到环境参数页面') uni.showToast({ title: '系统连接成功', icon: 'success', @@ -134,12 +127,10 @@ export default { }) }, fail: (err) => { - console.error('❌ 跳转到tabbar失败:', err); // 如果失败,尝试使用redirectTo uni.redirectTo({ url: '/pages/environment/index', success: () => { - console.log('✅ 使用redirectTo成功跳转') uni.showToast({ title: '系统连接成功', icon: 'success', @@ -147,7 +138,6 @@ export default { }) }, fail: (redirectErr) => { - console.error('❌ redirectTo也失败:', redirectErr) uni.showToast({ title: '页面跳转失败', icon: 'error', @@ -161,7 +151,6 @@ export default { }, 300) // 1秒后开始跳转 } catch (error) { - console.error('❌ MQTT重连失败:', error) uni.hideLoading() uni.showToast({ title: 'MQTT连接失败', @@ -187,8 +176,6 @@ export default { }) return } - - console.log('🔧 用户点击进入系统,开始MQTT重连...') } }, } diff --git a/src/pages/parameter/index.vue b/src/pages/parameter/index.vue index adf010c..7dbf488 100644 --- a/src/pages/parameter/index.vue +++ b/src/pages/parameter/index.vue @@ -313,14 +313,11 @@ export default { } }, onLoad() { - console.log('参数记录页面加载', new Date().toISOString().split('T')[0]) this.initMqttListener() // 调用历史数据接口 this.getHistoryData() }, onShow() { - console.log('📱 参数记录页面显示,触发页面更新') - // 重置时间相关状态 this.resetTimeState() @@ -333,7 +330,6 @@ export default { } }, onHide() { - console.log('📱 参数记录页面隐藏,清除数据缓存') // 页面隐藏时清除数据,防止缓存 this.clearPageData() }, @@ -349,14 +345,9 @@ export default { methods: { // 重置时间相关状态 resetTimeState() { - console.log('🔄 重置时间相关状态') - // 页面切换后重置为默认查询模式(过去24小时) this.queryMode = 'default' this.selectedDate = this.getTodayDate() - - console.log('📅 重置为默认查询模式,日期:', this.selectedDate) - // 强制更新X轴标签 this.$nextTick(() => { this.updateCharts() @@ -365,8 +356,6 @@ export default { // 清除页面数据缓存 clearPageData() { - console.log('🧹 清除页面数据缓存') - // 清除图表数据 this.temperatureData = new Array(24).fill(0) this.humidityData = new Array(24).fill(0) @@ -427,17 +416,6 @@ export default { const year = today.getFullYear() const month = String(today.getMonth() + 1).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}` }, @@ -531,12 +509,6 @@ export default { this.$nextTick(() => { this.updateCharts() }) - - console.log('✅ 图表数据更新完成:', { - temperature: this.temperatureData[dataIndex], - humidity: this.humidityData[dataIndex], - dataIndex: dataIndex - }) } else { console.log('⚠️ 非WSD设备数据,跳过图表更新:', data.deviceType) } @@ -564,7 +536,6 @@ export default { // 日期选择处理,选择后直接查询 onDateChange(e) { this.selectedDate = e.detail.value - console.log('选择的日期:', this.selectedDate) this.queryMode = 'date' // 切换到按日期查询模式 // 显示加载状态 @@ -575,12 +546,6 @@ export default { // 重新获取历史数据 this.getHistoryDataByDate().finally(() => { uni.hideLoading() - - uni.showToast({ - title: '查询成功', - icon: 'success', - duration: 1500 - }) }) }, @@ -616,9 +581,6 @@ export default { startTime: startTime, endTime: endTime } - - console.log('📊 请求历史数据(按日期):', params, `第${retryCount + 1}次尝试`) - // 增加超时时间到20秒 const response = await dataHistoryApi.getHistory(params, { timeout: 20000 }) @@ -637,7 +599,6 @@ export default { // 保存查询事件 await this.createQueryEvent('success', response.length) } else { - console.log('📊 没有历史数据,显示空状态') // 没有数据时显示空状态 this.showEmptyState() @@ -655,11 +616,8 @@ export default { return response } catch (error) { - console.error('❌ 历史数据获取失败:', error) - // 如果是超时错误且重试次数少于2次,则重试 if (error.message.includes('timeout') && retryCount < 2) { - console.log(`🔄 网络超时,正在重试... (${retryCount + 1}/2)`) uni.showToast({ title: `网络超时,重试中...`, icon: 'loading', @@ -712,9 +670,6 @@ export default { startTime: startTime, endTime: endTime } - - console.log('📊 请求历史数据(过去24小时):', params, `第${retryCount + 1}次尝试`) - // 增加超时时间到20秒 const response = await dataHistoryApi.getHistory(params, { timeout: 20000 }) @@ -733,7 +688,6 @@ export default { // 保存查询事件 await this.createQueryEvent('success', response.length) } else { - console.log('📊 没有历史数据,显示空状态') // 没有数据时显示空状态 this.showEmptyState() @@ -751,11 +705,8 @@ export default { return response } catch (error) { - console.error('❌ 历史数据获取失败:', error) - // 如果是超时错误且重试次数少于2次,则重试 if (error.message.includes('timeout') && retryCount < 2) { - console.log(`🔄 网络超时,正在重试... (${retryCount + 1}/2)`) uni.showToast({ title: `网络超时,重试中...`, icon: 'loading', @@ -795,8 +746,6 @@ export default { // 使用默认数据 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.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() { - console.log('🎨 显示空状态,默认值为0') - // 设置默认数据为0 this.temperatureData = new Array(24).fill(0) this.humidityData = new Array(24).fill(0) @@ -830,9 +777,6 @@ export default { }) }, processHistoryData(data) { - console.log('🔄 开始处理历史数据:', data.length, '条记录') - console.log('📊 原始数据示例:', data[0]) - // 初始化图表数据 this.chartData = { temperature: [], @@ -874,7 +818,6 @@ export default { if (dataIndex < 0 || dataIndex >= 24) { - console.log(`⚠️ 数据超出范围,跳过 - 索引:${dataIndex}`) 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(() => { @@ -924,8 +862,6 @@ export default { // 使用历史数据更新图表 updateChartsWithHistoryData() { - console.log('🎨 使用历史数据更新图表') - const xAxisLabels = this.generateXAxisLabels() // 处理温度数据 diff --git a/src/utils/api.js b/src/utils/api.js index 763ef54..c750e25 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -91,12 +91,15 @@ export const wsdApi = { } export const statusApi = { - getStatus(topic) { - return httpService.get('/api/mqtt/subscription/status?topic=HDYDCJ_01_UP') + // connected 判断设备端是否连接 + getStatus() { + return httpService.get('/api/emqx/clients/HDYDCJ_01') }, getConnectionStatus() { - return httpService.get('/api/mqtt/connection/status') + // 空调、温湿度、pm 是否在线 + // http://110.40.171.179:7999/api/health/latest + return httpService.get('/api/health/latest') } }