| | |
| | | // pages/stationMonitor/stationMonitor.js |
| | | const { |
| | | get |
| | | get, |
| | | post |
| | | } = require('../../api/request.js'); |
| | | |
| | | Page({ |
| | |
| | | |
| | | if (!this.data.currentFertilizerStation) return; |
| | | |
| | | // 更新搅拌状态 |
| | | // 如果用户开启搅拌,调用启动接口 |
| | | if (enabled) { |
| | | this.startStirring(); |
| | | } else { |
| | | // 关闭搅拌时调用停止接口 |
| | | this.stopStirring(); |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * 启动搅拌 |
| | | */ |
| | | startStirring() { |
| | | const currentStation = this.data.currentFertilizerStation; |
| | | if (!currentStation) return; |
| | | |
| | | console.log('开始调用启动搅拌接口'); |
| | | |
| | | // 显示loading状态 |
| | | wx.showLoading({ |
| | | title: '启动搅拌中...', |
| | | mask: true |
| | | }); |
| | | |
| | | // 调用启动搅拌接口 |
| | | post({ |
| | | url: '/wx/mqttStir/start', |
| | | data: { |
| | | manureId: currentStation.manureId || currentStation.id, |
| | | operator: getApp().globalData.operator |
| | | }, |
| | | isShowLoding: false // 我们自己控制loading状态 |
| | | }) |
| | | .then(response => { |
| | | console.log('启动搅拌接口返回:', response); |
| | | |
| | | // 隐藏loading |
| | | wx.hideLoading(); |
| | | |
| | | if (response.success && response.code === '0001') { |
| | | // 接口调用成功,更新搅拌状态 |
| | | this.updateMixingStatus(true); |
| | | |
| | | // 显示成功提示 |
| | | wx.showToast({ |
| | | title: '搅拌启动成功', |
| | | icon: 'success', |
| | | duration: 2000 |
| | | }); |
| | | } else { |
| | | // 接口调用失败,重置开关状态 |
| | | console.error('启动搅拌失败:', response.msg); |
| | | this.resetMixingSwitch(); |
| | | wx.showToast({ |
| | | title: response.msg || '启动搅拌失败', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | } |
| | | }) |
| | | .catch(error => { |
| | | console.error('调用启动搅拌接口失败:', error); |
| | | |
| | | // 隐藏loading |
| | | wx.hideLoading(); |
| | | |
| | | // 接口调用失败,重置开关状态 |
| | | this.resetMixingSwitch(); |
| | | |
| | | // 显示错误提示 |
| | | wx.showToast({ |
| | | title: '启动搅拌失败,请重试', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 更新搅拌状态 |
| | | */ |
| | | updateMixingStatus(enabled) { |
| | | const currentStation = { |
| | | ...this.data.currentFertilizerStation |
| | | }; |
| | | currentStation.mixingEnabled = enabled; |
| | | |
| | | // 更新具体的搅拌运行状态(这里假设只控制第一个搅拌器) |
| | | currentStation.mixingEnabled = enabled; |
| | | currentStation.stirRunning1 = enabled ? 1 : 0; |
| | | |
| | | this.setData({ |
| | | currentFertilizerStation: currentStation |
| | | }); |
| | | |
| | | // 显示操作结果 |
| | | wx.showToast({ |
| | | title: enabled ? '搅拌已开启' : '搅拌已关闭', |
| | | icon: 'success' |
| | | console.log('搅拌状态已更新:', enabled ? '开启' : '关闭'); |
| | | }, |
| | | |
| | | /** |
| | | * 重置搅拌开关状态(接口调用失败时使用) |
| | | */ |
| | | resetMixingSwitch() { |
| | | const currentStation = { |
| | | ...this.data.currentFertilizerStation |
| | | }; |
| | | |
| | | // 重置为关闭状态 |
| | | currentStation.mixingEnabled = false; |
| | | currentStation.stirRunning1 = 0; |
| | | |
| | | this.setData({ |
| | | currentFertilizerStation: currentStation |
| | | }); |
| | | |
| | | console.log('搅拌开关状态已重置为关闭'); |
| | | }, |
| | | |
| | | /** |
| | | * 停止搅拌 |
| | | */ |
| | | stopStirring() { |
| | | const currentStation = this.data.currentFertilizerStation; |
| | | if (!currentStation) return; |
| | | |
| | | console.log('开始调用停止搅拌接口'); |
| | | |
| | | // 显示loading状态 |
| | | wx.showLoading({ |
| | | title: '停止搅拌中...', |
| | | mask: true |
| | | }); |
| | | |
| | | // 调用停止搅拌接口 |
| | | post({ |
| | | url: '/wx/mqttStir/stop', |
| | | data: { |
| | | manureId: currentStation.manureId || currentStation.id, |
| | | operator: getApp().globalData.operator |
| | | }, |
| | | isShowLoding: false // 我们自己控制loading状态 |
| | | }) |
| | | .then(response => { |
| | | console.log('停止搅拌接口返回:', response); |
| | | |
| | | // 隐藏loading |
| | | wx.hideLoading(); |
| | | |
| | | if (response.success && response.code === '0001') { |
| | | // 接口调用成功,更新搅拌状态 |
| | | this.updateMixingStatus(false); |
| | | |
| | | // 显示成功提示 |
| | | wx.showToast({ |
| | | title: '搅拌停止成功', |
| | | icon: 'success', |
| | | duration: 2000 |
| | | }); |
| | | } else { |
| | | // 接口调用失败,保持开启状态 |
| | | console.error('停止搅拌失败:', response.msg); |
| | | this.keepMixingSwitchOn(); |
| | | wx.showToast({ |
| | | title: response.msg || '停止搅拌失败', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | } |
| | | }) |
| | | .catch(error => { |
| | | console.error('调用停止搅拌接口失败:', error); |
| | | |
| | | // 隐藏loading |
| | | wx.hideLoading(); |
| | | |
| | | // 接口调用失败,保持开启状态 |
| | | this.keepMixingSwitchOn(); |
| | | |
| | | // 显示错误提示 |
| | | wx.showToast({ |
| | | title: '停止搅拌失败,请重试', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 保持搅拌开关为开启状态(停止失败时使用) |
| | | */ |
| | | keepMixingSwitchOn() { |
| | | const currentStation = { |
| | | ...this.data.currentFertilizerStation |
| | | }; |
| | | |
| | | // 保持为开启状态 |
| | | currentStation.mixingEnabled = true; |
| | | currentStation.stirRunning1 = 1; |
| | | |
| | | this.setData({ |
| | | currentFertilizerStation: currentStation |
| | | }); |
| | | |
| | | console.log('搅拌开关状态保持为开启'); |
| | | }, |
| | | |
| | | /** |
| | |
| | | |
| | | if (!this.data.currentFertilizerStation) return; |
| | | |
| | | // 更新注肥状态 |
| | | // 如果用户开启注肥,调用启动接口 |
| | | if (enabled) { |
| | | this.startInjecting(); |
| | | } else { |
| | | // 关闭注肥时调用停止接口 |
| | | this.stopInjecting(); |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * 启动注肥 |
| | | */ |
| | | startInjecting() { |
| | | const currentStation = this.data.currentFertilizerStation; |
| | | if (!currentStation) return; |
| | | |
| | | console.log('开始调用启动注肥接口'); |
| | | |
| | | // 显示loading状态 |
| | | wx.showLoading({ |
| | | title: '启动注肥中...', |
| | | mask: true |
| | | }); |
| | | |
| | | // 调用启动注肥接口 |
| | | post({ |
| | | url: '/wx/mqttInject/start', |
| | | data: { |
| | | manureId: currentStation.manureId || currentStation.id, |
| | | operator: getApp().globalData.operator |
| | | }, |
| | | isShowLoding: false // 我们自己控制loading状态 |
| | | }) |
| | | .then(response => { |
| | | console.log('启动注肥接口返回:', response); |
| | | |
| | | // 隐藏loading |
| | | wx.hideLoading(); |
| | | |
| | | if (response.success && response.code === '0001') { |
| | | // 接口调用成功,更新注肥状态 |
| | | this.updateInjectingStatus(true); |
| | | |
| | | // 显示成功提示 |
| | | wx.showToast({ |
| | | title: '注肥启动成功', |
| | | icon: 'success', |
| | | duration: 2000 |
| | | }); |
| | | } else { |
| | | // 接口调用失败,重置开关状态 |
| | | console.error('启动注肥失败:', response.msg); |
| | | this.resetInjectingSwitch(); |
| | | wx.showToast({ |
| | | title: response.msg || '启动注肥失败', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | } |
| | | }) |
| | | .catch(error => { |
| | | console.error('调用启动注肥接口失败:', error); |
| | | |
| | | // 隐藏loading |
| | | wx.hideLoading(); |
| | | |
| | | // 接口调用失败,重置开关状态 |
| | | this.resetInjectingSwitch(); |
| | | |
| | | // 显示错误提示 |
| | | wx.showToast({ |
| | | title: '启动注肥失败,请重试', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 更新注肥状态 |
| | | */ |
| | | updateInjectingStatus(enabled) { |
| | | const currentStation = { |
| | | ...this.data.currentFertilizerStation |
| | | }; |
| | | currentStation.fertilizingEnabled = enabled; |
| | | |
| | | // 更新注肥运行状态 |
| | | currentStation.fertilizingEnabled = enabled; |
| | | currentStation.injectRunning = enabled ? 1 : 0; |
| | | |
| | | this.setData({ |
| | | currentFertilizerStation: currentStation |
| | | }); |
| | | |
| | | // 显示操作结果 |
| | | wx.showToast({ |
| | | title: enabled ? '注肥已开启' : '注肥已关闭', |
| | | icon: 'success' |
| | | console.log('注肥状态已更新:', enabled ? '开启' : '关闭'); |
| | | }, |
| | | |
| | | /** |
| | | * 重置注肥开关状态(接口调用失败时使用) |
| | | */ |
| | | resetInjectingSwitch() { |
| | | const currentStation = { |
| | | ...this.data.currentFertilizerStation |
| | | }; |
| | | |
| | | // 重置为关闭状态 |
| | | currentStation.fertilizingEnabled = false; |
| | | currentStation.injectRunning = 0; |
| | | |
| | | this.setData({ |
| | | currentFertilizerStation: currentStation |
| | | }); |
| | | |
| | | console.log('注肥开关状态已重置为关闭'); |
| | | }, |
| | | |
| | | /** |
| | | * 停止注肥 |
| | | */ |
| | | stopInjecting() { |
| | | const currentStation = this.data.currentFertilizerStation; |
| | | if (!currentStation) return; |
| | | |
| | | console.log('开始调用停止注肥接口'); |
| | | |
| | | // 显示loading状态 |
| | | wx.showLoading({ |
| | | title: '停止注肥中...', |
| | | mask: true |
| | | }); |
| | | |
| | | // 调用停止注肥接口 |
| | | post({ |
| | | url: '/wx/mqttInject/stop', |
| | | data: { |
| | | manureId: currentStation.manureId || currentStation.id, |
| | | operator: getApp().globalData.operator |
| | | }, |
| | | isShowLoding: false // 我们自己控制loading状态 |
| | | }) |
| | | .then(response => { |
| | | console.log('停止注肥接口返回:', response); |
| | | |
| | | // 隐藏loading |
| | | wx.hideLoading(); |
| | | |
| | | if (response.success && response.code === '0001') { |
| | | // 接口调用成功,更新注肥状态 |
| | | this.updateInjectingStatus(false); |
| | | |
| | | // 显示成功提示 |
| | | wx.showToast({ |
| | | title: '注肥停止成功', |
| | | icon: 'success', |
| | | duration: 2000 |
| | | }); |
| | | } else { |
| | | // 接口调用失败,保持开启状态 |
| | | console.error('停止注肥失败:', response.msg); |
| | | this.keepInjectingSwitchOn(); |
| | | wx.showToast({ |
| | | title: response.msg || '停止注肥失败', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | } |
| | | }) |
| | | .catch(error => { |
| | | console.error('调用停止注肥接口失败:', error); |
| | | |
| | | // 隐藏loading |
| | | wx.hideLoading(); |
| | | |
| | | // 接口调用失败,保持开启状态 |
| | | this.keepInjectingSwitchOn(); |
| | | |
| | | // 显示错误提示 |
| | | wx.showToast({ |
| | | title: '停止注肥失败,请重试', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 保持注肥开关为开启状态(停止失败时使用) |
| | | */ |
| | | keepInjectingSwitchOn() { |
| | | const currentStation = { |
| | | ...this.data.currentFertilizerStation |
| | | }; |
| | | |
| | | // 保持为开启状态 |
| | | currentStation.fertilizingEnabled = true; |
| | | currentStation.injectRunning = 1; |
| | | |
| | | this.setData({ |
| | | currentFertilizerStation: currentStation |
| | | }); |
| | | |
| | | console.log('注肥开关状态保持为开启'); |
| | | }, |
| | | |
| | | |
| | |
| | | const updatedItem = { |
| | | ...item, |
| | | isLoadingUrl: isLoading, |
| | | urlError: hasError |
| | | urlError: hasError, |
| | | onLine:false |
| | | }; |
| | | console.log(`摄像头 ${cameraId} 状态更新:`, { |
| | | name: updatedItem.name, |
| | | isLoadingUrl: updatedItem.isLoadingUrl, |
| | | urlError: updatedItem.urlError |
| | | urlError: updatedItem.urlError, |
| | | onLine:false |
| | | }); |
| | | return updatedItem; |
| | | } |
| | |
| | | this.updateCameraUrlLoadingState(camera.id, false, true); |
| | | |
| | | // 显示错误提示 |
| | | wx.showToast({ |
| | | title: '视频播放出错', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | // wx.showToast({ |
| | | // title: '视频播放出错', |
| | | // icon: 'error', |
| | | // duration: 2000 |
| | | // }); |
| | | } else { |
| | | console.error('未找到对应的摄像头:', cameraId); |
| | | } |
| | |
| | | console.log('播放状态更新完成'); |
| | | }, |
| | | |
| | | /** |
| | | * 清除故障 |
| | | */ |
| | | clearAlarm() { |
| | | const currentStation = this.data.currentFertilizerStation; |
| | | if (!currentStation) return; |
| | | |
| | | console.log('开始调用清除故障接口'); |
| | | |
| | | // 显示loading状态 |
| | | wx.showLoading({ |
| | | title: '清除故障中...', |
| | | mask: true |
| | | }); |
| | | |
| | | // 调用清除故障接口 |
| | | post({ |
| | | url: '/wx/mqttFault/clear', |
| | | data: { |
| | | manureId: currentStation.manureId || currentStation.id, |
| | | operator: getApp().globalData.operator |
| | | }, |
| | | isShowLoding: false // 我们自己控制loading状态 |
| | | }) |
| | | .then(response => { |
| | | console.log('消除报警接口返回:', response); |
| | | |
| | | // 隐藏loading |
| | | wx.hideLoading(); |
| | | |
| | | if (response.success && response.code === '0001') { |
| | | // 接口调用成功,更新报警状态 |
| | | this.updateAlarmStatus(0); |
| | | |
| | | // 显示成功提示 |
| | | wx.showToast({ |
| | | title: '故障清除成功', |
| | | icon: 'success', |
| | | duration: 2000 |
| | | }); |
| | | } else { |
| | | // 接口调用失败 |
| | | console.error('清除故障失败:', response.msg); |
| | | wx.showToast({ |
| | | title: response.msg || '清除故障失败', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | } |
| | | }) |
| | | .catch(error => { |
| | | console.error('调用清除故障接口失败:', error); |
| | | |
| | | // 隐藏loading |
| | | wx.hideLoading(); |
| | | |
| | | // 显示错误提示 |
| | | wx.showToast({ |
| | | title: '清除故障失败,请重试', |
| | | icon: 'error', |
| | | duration: 2000 |
| | | }); |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 更新报警状态 |
| | | */ |
| | | updateAlarmStatus(alarmStatus) { |
| | | const currentStation = { |
| | | ...this.data.currentFertilizerStation |
| | | }; |
| | | |
| | | currentStation.alarm = alarmStatus; |
| | | |
| | | this.setData({ |
| | | currentFertilizerStation: currentStation |
| | | }); |
| | | |
| | | console.log('报警状态已更新:', alarmStatus === 1 ? '报警' : '正常'); |
| | | }, |
| | | |
| | | |
| | | }) |