From 832a41e2688553219b540ca772faeaba16a02088 Mon Sep 17 00:00:00 2001 From: zuoxiao <zuoxiao> Date: 星期五, 22 八月 2025 14:44:23 +0800 Subject: [PATCH] 更新项目配置,提升监测页面功能,新增注肥泵状态管理和故障清除功能;优化样式以增强用户体验和可视化效果。 --- pages/stationMonitor/stationMonitor.js | 495 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 473 insertions(+), 22 deletions(-) diff --git a/pages/stationMonitor/stationMonitor.js b/pages/stationMonitor/stationMonitor.js index df58747..bc5b271 100644 --- a/pages/stationMonitor/stationMonitor.js +++ b/pages/stationMonitor/stationMonitor.js @@ -1,6 +1,7 @@ // pages/stationMonitor/stationMonitor.js const { - get + get, + post } = require('../../api/request.js'); Page({ @@ -951,24 +952,207 @@ 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('鎼呮媽寮�鍏崇姸鎬佷繚鎸佷负寮�鍚�'); }, /** @@ -980,24 +1164,207 @@ 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('娉ㄨ偉寮�鍏崇姸鎬佷繚鎸佷负寮�鍚�'); }, @@ -1045,12 +1412,14 @@ 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; } @@ -1105,11 +1474,11 @@ this.updateCameraUrlLoadingState(camera.id, false, true); // 鏄剧ず閿欒鎻愮ず - wx.showToast({ - title: '瑙嗛鎾斁鍑洪敊', - icon: 'error', - duration: 2000 - }); + // wx.showToast({ + // title: '瑙嗛鎾斁鍑洪敊', + // icon: 'error', + // duration: 2000 + // }); } else { console.error('鏈壘鍒板搴旂殑鎽勫儚澶�:', cameraId); } @@ -1191,5 +1560,87 @@ 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 ? '鎶ヨ' : '姝e父'); + }, + }) \ No newline at end of file -- Gitblit v1.8.0