From 7f48ad7939773a9bc02aad98dbc5e11a35d132e1 Mon Sep 17 00:00:00 2001 From: zuoxiao <zuoxiao> Date: 星期二, 19 八月 2025 15:42:32 +0800 Subject: [PATCH] 更新项目配置,启用URL检查功能;修改监测页面状态管理逻辑,优化在线状态的判断方式,提升用户体验和代码可读性。 --- pages/stationMonitor/stationMonitor.js | 1476 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 1,077 insertions(+), 399 deletions(-) diff --git a/pages/stationMonitor/stationMonitor.js b/pages/stationMonitor/stationMonitor.js index 73b4fef..df58747 100644 --- a/pages/stationMonitor/stationMonitor.js +++ b/pages/stationMonitor/stationMonitor.js @@ -1,5 +1,7 @@ // pages/stationMonitor/stationMonitor.js -const { get } = require('../../api/request.js'); +const { + get +} = require('../../api/request.js'); Page({ @@ -9,15 +11,120 @@ data: { activeTab: 'weather', // 榛樿閫変腑姘旇薄绔� cameraList: [], - isLoading: false + isLoading: false, + // 姘旇薄绔欑浉鍏虫暟鎹� + weatherStationList: [], + selectedWeatherStationIndex: 0, + currentWeatherStation: null, + // 姘磋偉鏈虹浉鍏虫暟鎹� + fertilizerStationList: [], + selectedFertilizerStationIndex: 0, + currentFertilizerStation: null, + // 鍦熷¥澧掓儏绔欑浉鍏虫暟鎹� + soilStationList: [], + selectedSoilStationIndex: 0, + currentSoilStation: null, + //鎽勫儚澶寸浉鍏� + accessToken: 'at.4l27eilo2x0euquw4yrhjxnz9kvr294l-2dp10mcwig-1nnzr8p-7wp71d2bk', + hslUrl: '', + // 璁惧淇℃伅 + deviceInfo: null, + isRealDevice: false, + deviceSpecificConfig: { + videoHeight: 400, + buttonHeight: 72, + fontSize: 26 + } }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ onLoad(options) { + // 妫�娴嬭澶囩被鍨嬪拰灞忓箷淇℃伅 + this.detectDeviceInfo(); + // 椤甸潰鍔犺浇鏃惰幏鍙栨憚鍍忓ご淇℃伅 this.getCameraList(); + // 鑾峰彇鎵�鏈夎澶囦俊鎭紙姘旇薄绔欍�佸湡澹ゅ鎯呯珯銆佹按鑲ユ満锛� + this.getAllDeviceInfo(); + }, + + /** + * 妫�娴嬭澶囦俊鎭� + */ + detectDeviceInfo() { + try { + const systemInfo = wx.getSystemInfoSync(); + console.log('璁惧淇℃伅:', systemInfo); + + // 妫�娴嬫槸鍚︿负鐪熸満 + const isRealDevice = systemInfo.platform === 'android' || systemInfo.platform === 'ios'; + + // 妫�娴嬪睆骞曞昂瀵� + const screenWidth = systemInfo.screenWidth; + const screenHeight = systemInfo.screenHeight; + const pixelRatio = systemInfo.pixelRatio; + + // 妫�娴嬪井淇$増鏈� + const version = systemInfo.version; + + this.setData({ + deviceInfo: { + platform: systemInfo.platform, + isRealDevice: isRealDevice, + screenWidth: screenWidth, + screenHeight: screenHeight, + pixelRatio: pixelRatio, + version: version, + model: systemInfo.model, + system: systemInfo.system + } + }); + + console.log('璁惧妫�娴嬬粨鏋�:', { + isRealDevice, + screenWidth, + screenHeight, + pixelRatio, + version + }); + + // 鏍规嵁璁惧淇℃伅璋冩暣甯冨眬 + this.adjustLayoutForDevice(); + + } catch (error) { + console.error('鑾峰彇璁惧淇℃伅澶辫触:', error); + } + }, + + /** + * 鏍规嵁璁惧淇℃伅璋冩暣甯冨眬 + */ + adjustLayoutForDevice() { + const { deviceInfo } = this.data; + if (!deviceInfo) return; + + // 鐪熸満鐗规畩澶勭悊 + if (deviceInfo.isRealDevice) { + console.log('妫�娴嬪埌鐪熸満锛屽簲鐢ㄧ壒娈婁紭鍖�'); + + // 鐪熸満涓婂彲鑳介渶瑕佽皟鏁翠竴浜涘弬鏁� + this.setData({ + isRealDevice: true, + // 鍙互鏍规嵁璁惧淇℃伅璋冩暣鍏朵粬鍙傛暟 + deviceSpecificConfig: { + videoHeight: deviceInfo.screenHeight < 700 ? 320 : 400, + buttonHeight: deviceInfo.screenHeight < 700 ? 64 : 72, + fontSize: deviceInfo.pixelRatio > 2 ? 24 : 26 + } + }); + } else { + console.log('妫�娴嬪埌妯℃嫙鍣�'); + this.setData({ + isRealDevice: false + }); + } }, /** @@ -31,7 +138,28 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず */ onShow() { - + console.log('=== 椤甸潰鏄剧ず ==='); + console.log('褰撳墠椤甸潰鏁版嵁:', { + activeTab: this.data.activeTab, + cameraList: this.data.cameraList, + deviceInfo: this.data.deviceInfo, + deviceSpecificConfig: this.data.deviceSpecificConfig + }); + + // 妫�鏌zplayer缁勪欢鐨勭姸鎬� + if (this.data.activeTab === 'camera') { + console.log('鎽勫儚澶撮〉闈㈡縺娲伙紝妫�鏌ョ粍浠剁姸鎬�'); + this.data.cameraList.forEach(camera => { + console.log(`鎽勫儚澶� ${camera.name} 鐘舵��:`, { + id: camera.id, + online: camera.online, + hslUrl: camera.hslUrl, + isLoadingUrl: camera.isLoadingUrl, + urlError: camera.urlError, + isPlaying: camera.isPlaying + }); + }); + } }, /** @@ -52,9 +180,11 @@ * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ onPullDownRefresh() { - // 涓嬫媺鍒锋柊鏃堕噸鏂拌幏鍙栨憚鍍忓ご鍒楄〃 + // 涓嬫媺鍒锋柊鏃堕噸鏂拌幏鍙栨暟鎹� if (this.data.activeTab === 'camera') { this.getCameraList(); + } else if (this.data.activeTab === 'weather' || this.data.activeTab === 'soil' || this.data.activeTab === 'fertilizer') { + this.getAllDeviceInfo(); } wx.stopPullDownRefresh(); }, @@ -82,11 +212,134 @@ this.setData({ activeTab: tab }); - + // 濡傛灉鍒囨崲鍒版憚鍍忓ご閫夐」鍗★紝纭繚鏈夋暟鎹� if (tab === 'camera' && this.data.cameraList.length === 0) { this.getCameraList(); } + + // 濡傛灉鍒囨崲鍒版皵璞$珯閫夐」鍗★紝纭繚鏈夋暟鎹� + if (tab === 'weather' && this.data.weatherStationList.length === 0) { + this.getAllDeviceInfo(); + } + + // 濡傛灉鍒囨崲鍒板湡澹ゅ鎯呯珯閫夐」鍗★紝纭繚鏈夋暟鎹� + if (tab === 'soil' && this.data.soilStationList.length === 0) { + this.getAllDeviceInfo(); + } + + // 濡傛灉鍒囨崲鍒版按鑲ユ満閫夐」鍗★紝纭繚鏈夋暟鎹� + if (tab === 'fertilizer' && this.data.fertilizerStationList.length === 0) { + this.getAllDeviceInfo(); + } + }, + + /** + * 鑾峰彇鎵�鏈夎澶囦俊鎭紙姘旇薄绔欍�佸湡澹ゅ鎯呯珯銆佹按鑲ユ満锛� + */ + getAllDeviceInfo() { + const app = getApp(); + + // 妫�鏌ョ櫥褰曠姸鎬� + if (!app.globalData.isLoggedIn) { + wx.showToast({ + title: '璇峰厛鐧诲綍', + icon: 'error' + }); + return; + } + + console.log('寮�濮嬭皟鐢� /wx/mqtt/allSimple 鎺ュ彛鑾峰彇璁惧淇℃伅'); + + get({url: '/wx/mqtt/allSimple'}) + .then(response => { + console.log('璁惧淇℃伅鎺ュ彛杩斿洖鏁版嵁:', response); + + if (response.success && response.code === '0001') { + const content = response.content; + + // 澶勭悊姘旇薄绔欐暟鎹� + if (content.weathers && content.weathers.length > 0) { + const weatherStations = content.weathers.map(item => ({ + id: item.id, + name: item.name, + no: item.no, + online: true, // 榛樿鍦ㄧ嚎 + location: '鐢樿們鐪佹皯鍕ゅ幙', // 榛樿浣嶇疆 + lastUpdate: new Date().toLocaleString() + })); + + this.setData({ + weatherStationList: weatherStations + }); + + // 榛樿閫夋嫨绗竴涓皵璞$珯 + if (weatherStations.length > 0) { + this.selectWeatherStation(0); + } + } + + // 澶勭悊鍦熷¥澧掓儏绔欐暟鎹� + if (content.soils && content.soils.length > 0) { + const soilStations = content.soils.map(item => ({ + id: item.id, + name: item.name, + no: item.no, + online: true, // 榛樿鍦ㄧ嚎 + location: '鐢樿們鐪佹皯鍕ゅ幙', // 榛樿浣嶇疆 + lastUpdate: new Date().toLocaleString() + })); + + this.setData({ + soilStationList: soilStations + }); + + // 榛樿閫夋嫨绗竴涓湡澹ゅ鎯呯珯 + if (soilStations.length > 0) { + this.selectSoilStation(0); + } + } + + // 澶勭悊姘磋偉鏈烘暟鎹� + if (content.manures && content.manures.length > 0) { + const fertilizerStations = content.manures.map(item => ({ + id: item.id, + name: item.name, + no: item.no, + online: true // 榛樿鍦ㄧ嚎 + })); + + this.setData({ + fertilizerStationList: fertilizerStations + }); + + // 榛樿閫夋嫨绗竴涓按鑲ユ満 + if (fertilizerStations.length > 0) { + this.selectFertilizerStation(0); + } + } + + console.log('璁惧淇℃伅澶勭悊瀹屾垚:', { + weatherStations: this.data.weatherStationList, + soilStations: this.data.soilStationList, + fertilizerStations: this.data.fertilizerStationList + }); + + } else { + console.error('鑾峰彇璁惧淇℃伅澶辫触:', response.msg); + wx.showToast({ + title: response.msg || '鑾峰彇璁惧淇℃伅澶辫触', + icon: 'none' + }); + } + }) + .catch(error => { + console.error('璋冪敤璁惧淇℃伅鎺ュ彛澶辫触:', error); + wx.showToast({ + title: '鑾峰彇璁惧淇℃伅澶辫触', + icon: 'error' + }); + }); }, /** @@ -94,7 +347,7 @@ */ getCameraList() { const app = getApp(); - + // 妫�鏌ョ櫥褰曠姸鎬� if (!app.globalData.isLoggedIn) { wx.showToast({ @@ -108,410 +361,835 @@ isLoading: true }); - // 妯℃嫙鎺ュ彛杩斿洖鏁版嵁 - setTimeout(() => { - const mockResponse = { - "code": "0001", - "content": { - "itemTotal": 4, - "obj": [ - { - "id": "2025070715040300007", - "name": "姘戝嫟01", - "videoUrl4PcLive": "https://open.ys7.com/console/jssdk/pc.html?url=ezopen://open.ys7.com/FX6737162/1.live&accessToken=at.2o04glgs0q36cjugbvddqujz7tqrghx1-1ovr6lmf3k-03pij3c-304ziif7e&themeId=pcLive&env=&date=", - "videoUrl4Security": "https://open.ys7.com/console/jssdk/pc.html?accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&url=ezopen://open.ys7.com/FY4056878/1.live&themeId=security&date=", - "videoUrl4Simple": "https://open.ys7.com/console/jssdk/pc.html?accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&url=ezopen://open.ys7.com/FY4056878/1.live&themeId=simple&date=", - "videoUrl4Standard": "https://open.ys7.com/console/jssdk/pc.html?accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&url=ezopen://open.ys7.com/FY4056878/1.live&themeId=standard&date=" - }, - { - "id": "2025070715040300008", - "name": "姘戝嫟02", - "videoUrl4PcLive": "https://open.ys7.com/console/jssdk/pc.html?url=ezopen://open.ys7.com/FY4056879/1.live&accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&themeId=pcLive&env=&date=", - "videoUrl4Security": "https://open.ys7.com/console/jssdk/pc.html?accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&url=ezopen://open.ys7.com/FY4056879/1.live&themeId=security&date=", - "videoUrl4Simple": "https://open.ys7.com/console/jssdk/pc.html?accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&url=ezopen://open.ys7.com/FY4056879/1.live&themeId=simple&date=", - "videoUrl4Standard": "https://open.ys7.com/console/jssdk/pc.html?accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&url=ezopen://open.ys7.com/FY4056879/1.live&themeId=standard&date=" - }, - { - "id": "2025070715040300009", - "name": "姘戝嫟03", - "videoUrl4PcLive": "https://open.ys7.com/console/jssdk/pc.html?url=ezopen://open.ys7.com/FY4056880/1.live&accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&themeId=pcLive&env=&date=", - "videoUrl4Security": "https://open.ys7.com/console/jssdk/pc.html?accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&url=ezopen://open.ys7.com/FY4056880/1.live&themeId=security&date=", - "videoUrl4Simple": "https://open.ys7.com/console/jssdk/pc.html?accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&url=ezopen://open.ys7.com/FY4056880/1.live&themeId=simple&date=", - "videoUrl4Standard": "https://open.ys7.com/console/jssdk/pc.html?accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&url=ezopen://open.ys7.com/FY4056880/1.live&themeId=standard&date=" - }, - { - "id": "2025070715040300010", - "name": "姘戝嫟04", - "videoUrl4PcLive": "https://open.ys7.com/console/jssdk/pc.html?url=ezopen://open.ys7.com/FY4056881/1.live&accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&themeId=pcLive&env=&date=", - "videoUrl4Security": "https://open.ys7.com/console/jssdk/pc.html?accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&url=ezopen://open.ys7.com/FY4056881/1.live&themeId=security&date=", - "videoUrl4Simple": "https://open.ys7.com/console/jssdk/pc.html?accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&url=ezopen://open.ys7.com/FY4056881/1.live&themeId=simple&date=", - "videoUrl4Standard": "https://open.ys7.com/console/jssdk/pc.html?accessToken=at.87a8u4z04s3gom0o6i0cpgz35kuhu8xh-67xrfkiy90-0nnbl6z-r0v9mckp3&url=ezopen://open.ys7.com/FY4056881/1.live&themeId=standard&date=" - } - ], - "pageCurr": 1, - "pageSize": 4, - "pageTotal": 1 - }, - "msg": "璇锋眰鎴愬姛", - "success": true - }; + // 璋冪敤鐪熷疄鎺ュ彛鑾峰彇鎽勫儚澶村垪琛� + this.getVideoListFromApi(); + }, - console.log('妯℃嫙鎺ュ彛杩斿洖鏁版嵁:', mockResponse); - - if (mockResponse.success && mockResponse.code === '0001') { - // 澶勭悊杩斿洖鐨勬憚鍍忓ご鏁版嵁 - const cameraList = mockResponse.content.obj.map(item => { - // 浠庤悿鐭充簯URL涓彁鍙栬澶囦俊鎭苟鐢熸垚RTMP鍦板潃 - let rtmpUrl = ''; - - if (item.videoUrl4PcLive) { - // 鎻愬彇璁惧搴忓垪鍙峰拰閫氶亾鍙� - const ezopenMatch = item.videoUrl4PcLive.match(/ezopen:\/\/open\.ys7\.com\/([^\/]+)\/(\d+)\.live/); - const tokenMatch = item.videoUrl4PcLive.match(/accessToken=([^&]+)/); + /** + * 浠庢帴鍙h幏鍙栬棰戝垪琛� + */ + getVideoListFromApi() { + console.log('寮�濮嬭皟鐢� /wx/video/all 鎺ュ彛鑾峰彇瑙嗛鍒楄〃'); + + get({url:'/wx/video/all'} ) + .then(response => { + console.log('鎺ュ彛杩斿洖鏁版嵁:', response); + + if (response.success && response.code === '0001') { + // 澶勭悊杩斿洖鐨勬憚鍍忓ご鏁版嵁 + const cameraList = response.content.map(item => { + // 鏍规嵁devNo鐢熸垚RTMP URL + const channelNo = 1; // 榛樿閫氶亾鍙� + const rtmpUrl = `rtmp://open.ys7.com/${item.devNo}/${channelNo}/live`; - if (ezopenMatch && tokenMatch) { - const deviceSerial = ezopenMatch[1]; // 璁惧搴忓垪鍙� - const channelNo = ezopenMatch[2]; // 閫氶亾鍙� - const accessToken = tokenMatch[1]; // 璁块棶浠ょ墝 - - // 鐢熸垚RTMP鍦板潃 - rtmpUrl = `rtmp://open.ys7.com:1935/live/${deviceSerial}/${channelNo}?accessToken=${accessToken}`; - - // 澶囩敤HLS鍦板潃 - const hlsUrl = `https://open.ys7.com:443/live/${deviceSerial}/${channelNo}.m3u8?accessToken=${accessToken}`; - - console.log('鐢熸垚鐨凴TMP鍦板潃:', rtmpUrl); - console.log('鐢熸垚鐨凥LS鍦板潃:', hlsUrl); - } - } + console.log(`鎽勫儚澶� ${item.name} 鐢熸垚RTMP URL:`, rtmpUrl); + + return { + id: item.id, + name: item.name, + onLine: true, // 榛樿鍦ㄧ嚎锛屽疄闄呴」鐩腑鍙兘闇�瑕侀澶栫殑鐘舵�佹鏌� + lastUpdate: new Date().toLocaleString(), // 褰撳墠鏃堕棿浣滀负鏈�鍚庢洿鏂版椂闂� + isPlaying: false, // 瑙嗛鎾斁鐘舵�� + hslUrl: rtmpUrl, // 浣跨敤鐢熸垚鐨凴TMP URL + deviceSerial: item.devNo, // 浣跨敤鎺ュ彛杩斿洖鐨刣evNo + isLoadingUrl: false, // URL鍔犺浇鐘舵�� + urlError: false, // URL鑾峰彇閿欒鐘舵�� + autoPlay: false, // 鑷姩鎾斁鎺у埗 + // 鏂板瀛楁 + lng: item.lng, // 缁忓害 + lat: item.lat, // 绾害 + accessToken: item.accessToken // 璁惧涓撶敤accessToken + }; + }); + + this.setData({ + cameraList: cameraList, + isLoading: false + }); + + console.log('澶勭悊鍚庣殑鎽勫儚澶村垪琛�:', cameraList); - return { - id: item.id, - name: item.name, - online: true, // 榛樿鍦ㄧ嚎锛屽疄闄呴」鐩腑鍙兘闇�瑕侀澶栫殑鐘舵�佹鏌� - thumbnail: '/images/camera-thumb1.jpg', // 榛樿缂╃暐鍥� - lastUpdate: new Date().toLocaleString(), // 褰撳墠鏃堕棿浣滀负鏈�鍚庢洿鏂版椂闂� - isPlaying: false, // 瑙嗛鎾斁鐘舵�� - rtmpUrl: rtmpUrl, // RTMP娴佸湴鍧� - videoUrl4PcLive: item.videoUrl4PcLive, // 鍘熷PC鎾斁鍦板潃 - videoUrl4Security: item.videoUrl4Security, - videoUrl4Simple: item.videoUrl4Simple, - videoUrl4Standard: item.videoUrl4Standard - }; - }); - - this.setData({ - cameraList: cameraList, - isLoading: false - }); - - console.log('澶勭悊鍚庣殑鎽勫儚澶村垪琛�:', cameraList); - } else { - console.error('鑾峰彇鎽勫儚澶村垪琛ㄥけ璐�:', mockResponse.msg); - this.setData({ - isLoading: false - }); - wx.showToast({ - title: mockResponse.msg || '鑾峰彇鎽勫儚澶村垪琛ㄥけ璐�', - icon: 'none' - }); - } - }, 1000); // 妯℃嫙缃戠粶寤惰繜1绉� - }, - - /** - * 鎾斁瑙嗛 - */ - playVideo(e) { - const camera = e.currentTarget.dataset.camera; - console.log('鎾斁鎽勫儚澶�:', camera.name); - - if (!camera.online) { - wx.showToast({ - title: '鎽勫儚澶寸绾�', - icon: 'error' - }); - return; - } - - // 妫�鏌ヨ棰慤RL鏄惁鏈夋晥 - if (!camera.videoUrl4PcLive) { - wx.showToast({ - title: '瑙嗛鍦板潃鏃犳晥', - icon: 'error' - }); - return; - } - - console.log('瑙嗛URL:', camera.videoUrl4PcLive); - - // 鏇存柊瑙嗛鎾斁鐘舵�� - const cameraList = this.data.cameraList.map(item => { - if (item.id === camera.id) { - return { ...item, isPlaying: true }; - } - return item; - }); - - this.setData({ - cameraList: cameraList - }); - - // 寤惰繜涓�涓嬭live-player缁勪欢鏇存柊 - setTimeout(() => { - console.log('寮�濮嬫挱鏀剧洿鎾�:', camera.videoUrl4PcLive); - }, 100); - }, - - /** - * 鏆傚仠瑙嗛 - */ - pauseVideo(e) { - const camera = e.currentTarget.dataset.camera; - console.log('鏆傚仠鎽勫儚澶�:', camera.name); - - // 鏇存柊瑙嗛鎾斁鐘舵�� - const cameraList = this.data.cameraList.map(item => { - if (item.id === camera.id) { - return { ...item, isPlaying: false }; - } - return item; - }); - - this.setData({ - cameraList: cameraList - }); - }, - - /** - * 鍋滄瑙嗛 - */ - stopVideo(e) { - const camera = e.currentTarget.dataset.camera; - console.log('鍋滄鎽勫儚澶�:', camera.name); - - // 鏇存柊瑙嗛鎾斁鐘舵�� - const cameraList = this.data.cameraList.map(item => { - if (item.id === camera.id) { - return { ...item, isPlaying: false }; - } - return item; - }); - - this.setData({ - cameraList: cameraList - }); - }, - - /** - * 娴嬭瘯瑙嗛URL - */ - testVideoUrl(e) { - const camera = e.currentTarget.dataset.camera; - console.log('娴嬭瘯瑙嗛URL:', camera.name); - console.log('鍘熷URL:', camera.videoUrl4PcLive); - console.log('RTMP URL:', camera.rtmpUrl); - - // 鏄剧ずURL淇℃伅 - wx.showModal({ - title: '瑙嗛URL淇℃伅', - content: `鎽勫儚澶�: ${camera.name}\n鍘熷URL: ${camera.videoUrl4PcLive}\nRTMP URL: ${camera.rtmpUrl}`, - showCancel: false, - confirmText: '纭畾' - }); - }, - - /** - * 鐩存挱鎾斁鍣ㄧ姸鎬佸彉鍖� - */ - onLivePlayerStateChange(e) { - const camera = e.currentTarget.dataset.camera; - console.log('鐩存挱鎾斁鍣ㄧ姸鎬佸彉鍖�:', camera.name, e.detail); - - const { code } = e.detail; - - // 鏄剧ず鐘舵�佷俊鎭粰鐢ㄦ埛 - let statusText = ''; - let isPlaying = false; - - switch (code) { - case 2001: - statusText = '宸茬粡杩炴帴鏈嶅姟鍣�'; - break; - case 2002: - statusText = '宸茬粡杩炴帴 RTMP 鏈嶅姟鍣�,寮�濮嬫媺娴�'; - isPlaying = true; - break; - case 2003: - statusText = '缃戠粶鎺ユ敹鍒伴涓棰戞暟鎹寘(IDR)'; - isPlaying = true; - break; - case 2004: - statusText = '瑙嗛鎾斁寮�濮�'; - isPlaying = true; - break; - case 2005: - statusText = '瑙嗛鎾斁杩涘害'; - isPlaying = true; - break; - case 2006: - statusText = '瑙嗛鎾斁缁撴潫'; - isPlaying = false; - break; - case 2007: - statusText = '瑙嗛鎾斁Loading'; - isPlaying = true; - break; - case 2008: - statusText = '瑙g爜鍣ㄥ惎鍔�'; - isPlaying = true; - break; - case 2009: - statusText = '瑙嗛鍒嗚鲸鐜囨敼鍙�'; - isPlaying = true; - break; - case 2101: - statusText = '缃戠粶鏂繛锛屼笖缁忓娆¢噸杩炴姠鏁戞棤鏁�'; - isPlaying = false; - break; - case 2102: - statusText = '鑾峰彇鍔犻�熸媺娴佸湴鍧�澶辫触'; - isPlaying = false; - break; - case 2103: - statusText = '褰撳墠瑙嗛甯цВ鐮佸け璐�'; - isPlaying = false; - break; - case 2104: - statusText = '缃戠粶鏂繛, 宸插惎鍔ㄨ嚜鍔ㄩ噸杩�'; - isPlaying = false; - break; - case 2105: - statusText = '缃戠粶鏉ユ柇杩�, 涓旂粡澶氭閲嶈繛鎶㈡晳鏃犳晥'; - isPlaying = false; - break; - case 2106: - statusText = '缃戠粶鏉ユ柇杩�, 涓旂粡澶氭閲嶈繛鎶㈡晳鏃犳晥'; - isPlaying = false; - break; - default: - statusText = `鏈煡鐘舵�佺爜: ${code}`; - break; - } - - console.log(`鎽勫儚澶� ${camera.name} 鐘舵��: ${statusText}`); - - // 鏇存柊鎾斁鐘舵�� - const cameraList = this.data.cameraList.map(item => { - if (item.id === camera.id) { - return { ...item, isPlaying: isPlaying }; - } - return item; - }); - - this.setData({ - cameraList: cameraList - }); - }, - - /** - * 鐩存挱鎾斁鍣ㄧ綉缁滅姸鎬� - */ - onLivePlayerNetStatus(e) { - const camera = e.currentTarget.dataset.camera; - console.log('鐩存挱鎾斁鍣ㄧ綉缁滅姸鎬�:', camera.name, e.detail); - }, - - /** - * 鐩存挱鎾斁鍣ㄩ敊璇� - */ - onLivePlayerError(e) { - const camera = e.currentTarget.dataset.camera; - console.error('鐩存挱鎾斁鍣ㄩ敊璇�:', camera.name, e.detail); - - wx.showToast({ - title: '鐩存挱鎾斁澶辫触', - icon: 'error' - }); - - // 鏇存柊鎾斁鐘舵�� - const cameraList = this.data.cameraList.map(item => { - if (item.id === camera.id) { - return { ...item, isPlaying: false }; - } - return item; - }); - - this.setData({ - cameraList: cameraList - }); - }, - - /** - * 鍏ㄥ睆鎾斁瑙嗛 - */ - fullscreenVideo(e) { - const camera = e.currentTarget.dataset.camera; - console.log('鍏ㄥ睆鎾斁:', camera.name); - - if (!camera.online) { - wx.showToast({ - title: '鎽勫儚澶寸绾�', - icon: 'error' - }); - return; - } - - // 浣跨敤PC鐩存挱URL杩涜鍏ㄥ睆鎾斁 - if (camera.videoUrl4PcLive) { - console.log('鍏ㄥ睆瑙嗛URL:', camera.videoUrl4PcLive); - - wx.showModal({ - title: '鍏ㄥ睆鎾斁', - content: `鍗冲皢鍏ㄥ睆鎾斁 ${camera.name} 鐨勮棰戞祦`, - confirmText: '寮�濮嬫挱鏀�', - success: (res) => { - if (res.confirm) { - // 杩欓噷鍙互璺宠浆鍒板叏灞忚棰戞挱鏀鹃〉闈� - wx.showToast({ - title: '姝e湪鍔犺浇鍏ㄥ睆瑙嗛...', - icon: 'loading' - }); - - // 妯℃嫙鍏ㄥ睆瑙嗛鍔犺浇 - setTimeout(() => { - wx.showToast({ - title: '鍏ㄥ睆鎾斁涓�', - icon: 'success' - }); - }, 1500); - } + // 鐢变簬鐜板湪鐩存帴浣跨敤RTMP URL锛屼笉闇�瑕佸啀璋冪敤钀ょ煶浜慉PI鑾峰彇鎾斁鍦板潃 + // this.batchGetHlsUrls(cameraList); + } else { + console.error('鑾峰彇鎽勫儚澶村垪琛ㄥけ璐�:', response.msg); + this.setData({ + isLoading: false + }); + wx.showToast({ + title: response.msg || '鑾峰彇鎽勫儚澶村垪琛ㄥけ璐�', + icon: 'none' + }); } + }) + .catch(error => { + console.error('璋冪敤鎺ュ彛澶辫触:', error); + this.setData({ + isLoading: false + }); + }); + }, + + + + + + + + + + + /** + * 鑾峰彇姘旇薄绔欏垪琛紙鍏煎鎬ф柟娉曪紝鐜板湪璋冪敤缁熶竴鎺ュ彛锛� + */ + getWeatherStationList() { + console.log('鑾峰彇姘旇薄绔欏垪琛紙璋冪敤缁熶竴鎺ュ彛锛�'); + this.getAllDeviceInfo(); + }, + + /** + * 閫夋嫨姘旇薄绔� + */ + selectWeatherStation(index) { + const weatherStation = this.data.weatherStationList[index]; + if (!weatherStation) return; + + console.log('閫夋嫨姘旇薄绔�:', weatherStation.name); + + // 鑾峰彇璇ユ皵璞$珯鐨勮缁嗘暟鎹� + this.getWeatherStationData(weatherStation.id); + + this.setData({ + selectedWeatherStationIndex: index + }); + }, + + /** + * 鑾峰彇姘旇薄绔欒缁嗘暟鎹� + */ + getWeatherStationData(stationId) { + console.log('鑾峰彇姘旇薄绔欐暟鎹�:', stationId); + + // 璋冪敤鐪熷疄鎺ュ彛鑾峰彇姘旇薄绔欒缁嗕俊鎭� + this.getWeatherLastData(stationId); + }, + + /** + * 璋冪敤 /wx/mqttLast/oneWeatherLast 鎺ュ彛鑾峰彇姘旇薄绔欒缁嗕俊鎭� + */ + getWeatherLastData(weatherId) { + console.log('寮�濮嬭皟鐢� /wx/mqttLast/oneWeatherLast 鎺ュ彛鑾峰彇姘旇薄绔欒缁嗕俊鎭�'); + console.log('姘旇薄绔橧D:', weatherId); + + get({url: `/wx/mqttLast/oneWeatherLast?weatherId=${weatherId}`}) + .then(response => { + console.log('姘旇薄绔欒缁嗕俊鎭帴鍙h繑鍥炴暟鎹�:', response); + + if (response.success && response.code === '0001') { + const content = response.content; + + // 澶勭悊鎺ュ彛杩斿洖鐨勬皵璞$珯鏁版嵁 + const weatherData = { + id: content.id, + weatherId: content.weatherId, + weatherName: content.weatherName || '姘旇薄绔�', + dt: content.dt, + // 姘旇薄鏁版嵁 + temperature: content.airTemperature, // 绌烘皵娓╁害 + humidity: content.airHumidity, // 绌烘皵婀垮害 + uv: content.ultraviolet, // 绱绾� + light: content.lightIntensity, // 鍏夌収寮哄害 + rainfall: content.rainfall, // 闆ㄩ噺 + windSpeed: content.windSpeed, // 椋庨�� + windDirection: content.windDirectionStr, // 椋庡悜鎻忚堪 + windDirectionAngle: content.windDirection, // 椋庡悜瑙掑害 + // 鍦ㄧ嚎鐘舵�� + onLine: content.onLine, + // 鏍煎紡鍖栨樉绀烘暟鎹� + lastUpdate: content.dt || new Date().toLocaleString() + }; + + this.setData({ + currentWeatherStation: weatherData + }); + + console.log('澶勭悊鍚庣殑姘旇薄绔欐暟鎹�:', weatherData); + + } else { + console.error('鑾峰彇姘旇薄绔欒缁嗕俊鎭け璐�:', response.msg); + wx.showToast({ + title: response.msg || '鑾峰彇姘旇薄绔欒缁嗕俊鎭け璐�', + icon: 'none' + }); + + // 濡傛灉鎺ュ彛璋冪敤澶辫触锛屼娇鐢ㄦā鎷熸暟鎹綔涓哄閫� + this.setMockWeatherData(stationId); + } + }) + .catch(error => { + console.error('璋冪敤姘旇薄绔欒缁嗕俊鎭帴鍙eけ璐�:', error); + wx.showToast({ + title: '鑾峰彇姘旇薄绔欒缁嗕俊鎭け璐�', + icon: 'error' + }); + + // 濡傛灉鎺ュ彛璋冪敤澶辫触锛屼娇鐢ㄦā鎷熸暟鎹綔涓哄閫� + this.setMockWeatherData(stationId); + }); + }, + + /** + * 璁剧疆妯℃嫙姘旇薄绔欐暟鎹紙浣滀负鎺ュ彛璋冪敤澶辫触鐨勫閫夋柟妗堬級 + */ + setMockWeatherData(stationId) { + console.log('浣跨敤妯℃嫙姘旇薄绔欐暟鎹�:', stationId); + + const mockWeatherData = { + id: stationId, + weatherId: stationId, + weatherName: '姘旇薄绔�', + dt: new Date().toLocaleString(), + temperature: 0.0, + humidity: 0.0, + uv: 0, + light: 0, + rainfall: 0.00, + windSpeed: 0.00, + windDirection: '鍖�', + windDirectionAngle: 0, + onLine: false, + online: true, + lastUpdate: new Date().toLocaleString() + }; + + this.setData({ + currentWeatherStation: mockWeatherData + }); + }, + + + + /** + * 姘旇薄绔欓�夋嫨鏀瑰彉 + */ + onWeatherStationChange(e) { + const index = e.detail.value; + this.selectWeatherStation(index); + }, + + /** + * 鍒锋柊姘旇薄鏁版嵁 + */ + refreshWeatherData() { + if (!this.data.currentWeatherStation) { + wx.showToast({ + title: '璇峰厛閫夋嫨姘旇薄绔�', + icon: 'none' + }); + return; + } + + console.log('鍒锋柊姘旇薄鏁版嵁'); + + wx.showLoading({ + title: '鍒锋柊涓�...' + }); + + // 閲嶆柊璋冪敤鎺ュ彛鑾峰彇鏈�鏂版暟鎹� + this.getWeatherLastData(this.data.currentWeatherStation.weatherId || this.data.currentWeatherStation.id); + + wx.hideLoading(); + wx.showToast({ + title: '鍒锋柊鎴愬姛', + icon: 'success' + }); + }, + + /** + * 閫夋嫨鍦熷¥澧掓儏绔� + */ + selectSoilStation(index) { + const soilStation = this.data.soilStationList[index]; + if (!soilStation) return; + + console.log('閫夋嫨鍦熷¥澧掓儏绔�:', soilStation.name); + + // 鑾峰彇璇ュ湡澹ゅ鎯呯珯鐨勮缁嗘暟鎹� + this.getSoilStationData(soilStation.id); + + this.setData({ + selectedSoilStationIndex: index + }); + }, + + /** + * 鑾峰彇鍦熷¥澧掓儏绔欒缁嗘暟鎹� + */ + getSoilStationData(stationId) { + console.log('鑾峰彇鍦熷¥澧掓儏绔欐暟鎹�:', stationId); + + // 璋冪敤鐪熷疄鎺ュ彛鑾峰彇鍦熷¥澧掓儏绔欒缁嗕俊鎭� + this.getSoilLastData(stationId); + }, + + /** + * 璋冪敤 /wx/mqttLast/oneSoilLast 鎺ュ彛鑾峰彇鍦熷¥澧掓儏绔欒缁嗕俊鎭� + */ + getSoilLastData(soilId) { + console.log('寮�濮嬭皟鐢� /wx/mqttLast/oneSoilLast 鎺ュ彛鑾峰彇鍦熷¥澧掓儏绔欒缁嗕俊鎭�'); + console.log('鍦熷¥澧掓儏绔橧D:', soilId); + + get({url: `/wx/mqttLast/oneSoilLast?soilId=${soilId}`}) + .then(response => { + console.log('鍦熷¥澧掓儏绔欒缁嗕俊鎭帴鍙h繑鍥炴暟鎹�:', response); + + if (response.success && response.code === '0001') { + const content = response.content; + + // 澶勭悊鎺ュ彛杩斿洖鐨勫湡澹ゅ鎯呯珯鏁版嵁 + const soilData = { + id: content.id, + soilId: content.soilId, + soilName: content.soilName || '鍦熷¥澧掓儏绔�', + dt: content.dt, + // 5灞傚湡澹ゆ箍搴︽暟鎹� + soilHumidity1: content.soilHumidity1, + soilHumidity2: content.soilHumidity2, + soilHumidity3: content.soilHumidity3, + soilHumidity4: content.soilHumidity4, + soilHumidity5: content.soilHumidity5, + // 5灞傚湡澹ゆ俯搴︽暟鎹� + soilTemperature1: content.soilTemperature1, + soilTemperature2: content.soilTemperature2, + soilTemperature3: content.soilTemperature3, + soilTemperature4: content.soilTemperature4, + soilTemperature5: content.soilTemperature5, + // 鍦ㄧ嚎鐘舵�� + onLine: content.onLine, + // 璁$畻鍦ㄧ嚎鐘舵�� + online: content.onLine === 1, + // 鏍煎紡鍖栨樉绀烘暟鎹� + lastUpdate: content.dt || new Date().toLocaleString() + }; + + this.setData({ + currentSoilStation: soilData + }); + + console.log('澶勭悊鍚庣殑鍦熷¥澧掓儏绔欐暟鎹�:', soilData); + + } else { + console.error('鑾峰彇鍦熷¥澧掓儏绔欒缁嗕俊鎭け璐�:', response.msg); + wx.showToast({ + title: response.msg || '鑾峰彇鍦熷¥澧掓儏绔欒缁嗕俊鎭け璐�', + icon: 'none' + }); + + // 濡傛灉鎺ュ彛璋冪敤澶辫触锛屼娇鐢ㄦā鎷熸暟鎹綔涓哄閫� + this.setMockSoilData(stationId); + } + }) + .catch(error => { + console.error('璋冪敤鍦熷¥澧掓儏绔欒缁嗕俊鎭帴鍙eけ璐�:', error); + wx.showToast({ + title: '鑾峰彇鍦熷¥澧掓儏绔欒缁嗕俊鎭け璐�', + icon: 'error' + }); + + // 濡傛灉鎺ュ彛璋冪敤澶辫触锛屼娇鐢ㄦā鎷熸暟鎹綔涓哄閫� + this.setMockSoilData(stationId); + }); + }, + + /** + * 璁剧疆妯℃嫙鍦熷¥澧掓儏绔欐暟鎹紙浣滀负鎺ュ彛璋冪敤澶辫触鐨勫閫夋柟妗堬級 + */ + setMockSoilData(stationId) { + console.log('浣跨敤妯℃嫙鍦熷¥澧掓儏绔欐暟鎹�:', stationId); + + const mockSoilData = { + id: stationId, + soilId: stationId, + soilName: '鍦熷¥澧掓儏绔�', + dt: new Date().toLocaleString(), + // 5灞傚湡澹ゆ箍搴︽暟鎹� + soilHumidity1: 0.00, + soilHumidity2: 0.00, + soilHumidity3: 0.00, + soilHumidity4: 0.00, + soilHumidity5: 0.00, + // 5灞傚湡澹ゆ俯搴︽暟鎹� + soilTemperature1: 0.00, + soilTemperature2: 0.00, + soilTemperature3: 0.00, + soilTemperature4: 0.00, + soilTemperature5: 0.00, + // 鍦ㄧ嚎鐘舵�� + onLine: false, + lastUpdate: new Date().toLocaleString() + }; + + this.setData({ + currentSoilStation: mockSoilData + }); + }, + + /** + * 鍦熷¥澧掓儏绔欓�夋嫨鏀瑰彉 + */ + onSoilStationChange(e) { + const index = e.detail.value; + this.selectSoilStation(index); + }, + + /** + * 鍒锋柊鍦熷¥澧掓儏鏁版嵁 + */ + refreshSoilData() { + if (!this.data.currentSoilStation) { + wx.showToast({ + title: '璇峰厛閫夋嫨鍦熷¥澧掓儏绔�', + icon: 'none' + }); + return; + } + + console.log('鍒锋柊鍦熷¥澧掓儏鏁版嵁'); + + wx.showLoading({ + title: '鍒锋柊涓�...' + }); + + // 閲嶆柊璋冪敤鎺ュ彛鑾峰彇鏈�鏂版暟鎹� + this.getSoilLastData(this.data.currentSoilStation.soilId || this.data.currentSoilStation.id); + + wx.hideLoading(); + wx.showToast({ + title: '鍒锋柊鎴愬姛', + icon: 'success' + }); + }, + + /** + * 鑾峰彇姘磋偉鏈哄垪琛紙鍏煎鎬ф柟娉曪紝鐜板湪璋冪敤缁熶竴鎺ュ彛锛� + */ + getFertilizerStationList() { + console.log('鑾峰彇姘磋偉鏈哄垪琛紙璋冪敤缁熶竴鎺ュ彛锛�'); + this.getAllDeviceInfo(); + }, + + /** + * 閫夋嫨姘磋偉鏈� + */ + selectFertilizerStation(index) { + const fertilizerStation = this.data.fertilizerStationList[index]; + if (!fertilizerStation) return; + + console.log('閫夋嫨姘磋偉鏈�:', fertilizerStation.name); + + // 鑾峰彇璇ユ按鑲ユ満鐨勮缁嗘暟鎹� + this.getFertilizerStationData(fertilizerStation.id); + + this.setData({ + selectedFertilizerStationIndex: index + }); + }, + + /** + * 鑾峰彇姘磋偉鏈鸿缁嗘暟鎹� + */ + getFertilizerStationData(stationId) { + console.log('鑾峰彇姘磋偉鏈烘暟鎹�:', stationId); + + // 璋冪敤鐪熷疄鎺ュ彛鑾峰彇姘磋偉鏈鸿缁嗕俊鎭� + this.getManureLastData(stationId); + }, + + /** + * 璋冪敤 /wx/mqttLast/oneManureLast 鎺ュ彛鑾峰彇姘磋偉鏈鸿缁嗕俊鎭� + */ + getManureLastData(manureId) { + console.log('寮�濮嬭皟鐢� /wx/mqttLast/oneManureLast 鎺ュ彛鑾峰彇姘磋偉鏈鸿缁嗕俊鎭�'); + console.log('姘磋偉鏈篒D:', manureId); + + get({url: `/wx/mqttLast/oneManureLast?manureId=${manureId}`}) + .then(response => { + console.log('姘磋偉鏈鸿缁嗕俊鎭帴鍙h繑鍥炴暟鎹�:', response); + + if (response.success && response.code === '0001') { + const content = response.content; + + // 澶勭悊鎺ュ彛杩斿洖鐨勬按鑲ユ満鏁版嵁 + const fertilizerData = { + id: content.id, + manureId: content.manureId, + manureName: content.manureName || '姘磋偉鏈�', + dt: content.dt, + alarm: content.alarm, + // 鎼呮媽杩愯鐘舵�� + stirRunning1: content.stirRunning1, + // 娉ㄨ偉杩愯鐘舵�� + injectRunning: content.injectRunning, + // 娴侀噺鍜屾椂闂存暟鎹� + manureFlow: content.manureFlow, + manureTime: content.manureTime, + stirTime: content.stirTime, + stirDuration: content.stirDuration, + injectDuration: content.injectDuration, + // 鍦ㄧ嚎鐘舵�� + onLine: content.onLine, + // 璁$畻杩愯鐘舵�� + mixingEnabled: content.stirRunning1 === 1, + fertilizingEnabled: content.injectRunning === 1, + // 鏍煎紡鍖栨樉绀烘暟鎹� + lastUpdate: content.dt || new Date().toLocaleString() + }; + + this.setData({ + currentFertilizerStation: fertilizerData + }); + + console.log('澶勭悊鍚庣殑姘磋偉鏈烘暟鎹�:', fertilizerData); + + } else { + console.error('鑾峰彇姘磋偉鏈鸿缁嗕俊鎭け璐�:', response.msg); + wx.showToast({ + title: response.msg || '鑾峰彇姘磋偉鏈鸿缁嗕俊鎭け璐�', + icon: 'none' + }); + + // 濡傛灉鎺ュ彛璋冪敤澶辫触锛屼娇鐢ㄦā鎷熸暟鎹綔涓哄閫� + this.setMockFertilizerData(stationId); + } + }) + .catch(error => { + console.error('璋冪敤姘磋偉鏈鸿缁嗕俊鎭帴鍙eけ璐�:', error); + wx.showToast({ + title: '鑾峰彇姘磋偉鏈鸿缁嗕俊鎭け璐�', + icon: 'error' + }); + + // 濡傛灉鎺ュ彛璋冪敤澶辫触锛屼娇鐢ㄦā鎷熸暟鎹綔涓哄閫� + this.setMockFertilizerData(stationId); + }); + }, + + /** + * 璁剧疆妯℃嫙姘磋偉鏈烘暟鎹紙浣滀负鎺ュ彛璋冪敤澶辫触鐨勫閫夋柟妗堬級 + */ + setMockFertilizerData(stationId) { + console.log('浣跨敤妯℃嫙姘磋偉鏈烘暟鎹�:', stationId); + + const mockFertilizerData = { + id: stationId, + manureId: stationId, + manureName: '姘磋偉鏈�', + dt: new Date().toLocaleString(), + alarm: 0, + stirRunning1: 0, + injectRunning: 0, + manureFlow: 0.00, + manureTime: 0, + stirTime: 0, + stirDuration: 300, + injectDuration: 300, + onLine: false, + mixingEnabled: false, + fertilizingEnabled: false, + lastUpdate: new Date().toLocaleString() + }; + + this.setData({ + currentFertilizerStation: mockFertilizerData + }); + }, + + + + /** + * 姘磋偉鏈洪�夋嫨鏀瑰彉 + */ + onFertilizerStationChange(e) { + const index = e.detail.value; + this.selectFertilizerStation(index); + }, + + /** + * 鍒锋柊姘磋偉鏈烘暟鎹� + */ + refreshFertilizerData() { + if (!this.data.currentFertilizerStation) { + wx.showToast({ + title: '璇峰厛閫夋嫨姘磋偉鏈�', + icon: 'none' + }); + return; + } + + console.log('鍒锋柊姘磋偉鏈烘暟鎹�'); + + wx.showLoading({ + title: '鍒锋柊涓�...' + }); + + // 閲嶆柊璋冪敤鎺ュ彛鑾峰彇鏈�鏂版暟鎹� + this.getManureLastData(this.data.currentFertilizerStation.manureId || this.data.currentFertilizerStation.id); + + wx.hideLoading(); + wx.showToast({ + title: '鍒锋柊鎴愬姛', + icon: 'success' + }); + }, + + /** + * 鍒囨崲鎼呮媽寮�鍏� + */ + toggleMixing(e) { + const enabled = e.detail.value; + console.log('鎼呮媽寮�鍏�:', enabled ? '寮�鍚�' : '鍏抽棴'); + + if (!this.data.currentFertilizerStation) return; + + // 鏇存柊鎼呮媽鐘舵�� + const currentStation = { + ...this.data.currentFertilizerStation + }; + currentStation.mixingEnabled = enabled; + + // 鏇存柊鍏蜂綋鐨勬悈鎷岃繍琛岀姸鎬侊紙杩欓噷鍋囪鍙帶鍒剁涓�涓悈鎷屽櫒锛� + currentStation.stirRunning1 = enabled ? 1 : 0; + + this.setData({ + currentFertilizerStation: currentStation + }); + + // 鏄剧ず鎿嶄綔缁撴灉 + wx.showToast({ + title: enabled ? '鎼呮媽宸插紑鍚�' : '鎼呮媽宸插叧闂�', + icon: 'success' + }); + }, + + /** + * 鍒囨崲娉ㄨ偉寮�鍏� + */ + toggleFertilizing(e) { + const enabled = e.detail.value; + console.log('娉ㄨ偉寮�鍏�:', enabled ? '寮�鍚�' : '鍏抽棴'); + + if (!this.data.currentFertilizerStation) return; + + // 鏇存柊娉ㄨ偉鐘舵�� + const currentStation = { + ...this.data.currentFertilizerStation + }; + currentStation.fertilizingEnabled = enabled; + + // 鏇存柊娉ㄨ偉杩愯鐘舵�� + currentStation.injectRunning = enabled ? 1 : 0; + + this.setData({ + currentFertilizerStation: currentStation + }); + + // 鏄剧ず鎿嶄綔缁撴灉 + wx.showToast({ + title: enabled ? '娉ㄨ偉宸插紑鍚�' : '娉ㄨ偉宸插叧闂�', + icon: 'success' + }); + }, + + + + + + + /** + * 鎵嬪姩閲嶈瘯鑾峰彇鎾斁鍦板潃 + */ + retryGetHlsUrl(e) { + const camera = e.currentTarget.dataset.camera; + if (!camera) { + console.error('閲嶈瘯澶辫触锛氭憚鍍忓ご淇℃伅涓嶅畬鏁�'); + wx.showToast({ + title: '鎽勫儚澶翠俊鎭笉瀹屾暣', + icon: 'error' + }); + return; + } + + console.log('=== 鎵嬪姩閲嶈瘯鑾峰彇鎾斁鍦板潃 ==='); + console.log(`鎽勫儚澶�: ${camera.name}, ID: ${camera.id}`); + console.log('褰撳墠鐘舵��:', { + online: camera.online, + hslUrl: camera.hslUrl, + isLoadingUrl: camera.isLoadingUrl, + urlError: camera.urlError + }); + + // 閲嶇疆閿欒鐘舵�佸苟閲嶆柊鑾峰彇 + this.updateCameraUrlLoadingState(camera.id, false, false); + this.getHlsUrlForCamera(camera); + }, + + /** + * 鏇存柊鎽勫儚澶碪RL鍔犺浇鐘舵�� + */ + updateCameraUrlLoadingState(cameraId, isLoading, hasError) { + console.log('=== 鏇存柊鎽勫儚澶碪RL鍔犺浇鐘舵�� ==='); + console.log('鍙傛暟:', { cameraId, isLoading, hasError }); + + const cameraList = this.data.cameraList.map(item => { + if (item.id === cameraId) { + const updatedItem = { + ...item, + isLoadingUrl: isLoading, + urlError: hasError + }; + console.log(`鎽勫儚澶� ${cameraId} 鐘舵�佹洿鏂�:`, { + name: updatedItem.name, + isLoadingUrl: updatedItem.isLoadingUrl, + urlError: updatedItem.urlError + }); + return updatedItem; + } + return item; + }); + + this.setData({ + cameraList: cameraList + }); + + console.log('鐘舵�佹洿鏂板畬鎴愶紝褰撳墠鎽勫儚澶村垪琛�:', cameraList); + }, + + /** + * 涓哄崟涓憚鍍忓ご鑾峰彇HLS鎾斁鍦板潃 + */ + getHlsUrlForCamera(camera) { + if (!camera || !camera.deviceSerial) { + console.error('鎽勫儚澶翠俊鎭笉瀹屾暣:', camera); + return; + } + + console.log('=== 鑾峰彇鎾斁鍦板潃寮�濮� ==='); + console.log(`鎽勫儚澶�: ${camera.name}, ID: ${camera.id}, 璁惧搴忓垪鍙�: ${camera.deviceSerial}`); + console.log('褰撳墠accessToken:', this.data.accessToken); + + // 鏇存柊鍔犺浇鐘舵�� + this.updateCameraUrlLoadingState(camera.id, true, false); + + // 璋冪敤钀ょ煶浜慉PI鑾峰彇鎾斁鍦板潃 + this.getHlsUrl(this.data.accessToken, camera.deviceSerial, camera.id); + }, + + /** + * ezplayer閿欒澶勭悊 + */ + handleError(e) { + console.log('=== ezplayer 閿欒澶勭悊 ==='); + console.log('閿欒浜嬩欢璇︽儏:', e); + console.log('閿欒璇︽儏:', e.detail); + + // 鑾峰彇鎽勫儚澶翠俊鎭� + const cameraId = e.currentTarget.id; + console.log('鍑洪敊鐨勬憚鍍忓ごID:', cameraId); + + // 鏌ユ壘瀵瑰簲鐨勬憚鍍忓ご + const camera = this.data.cameraList.find(item => `ezplayer-${item.id}` === cameraId); + if (camera) { + console.log('鍑洪敊鐨勬憚鍍忓ご淇℃伅:', camera); + + // 鏇存柊閿欒鐘舵�� + this.updateCameraUrlLoadingState(camera.id, false, true); + + // 鏄剧ず閿欒鎻愮ず + wx.showToast({ + title: '瑙嗛鎾斁鍑洪敊', + icon: 'error', + duration: 2000 }); } else { - wx.showToast({ - title: '鍏ㄥ睆瑙嗛鍦板潃鏃犳晥', - icon: 'error' - }); + console.error('鏈壘鍒板搴旂殑鎽勫儚澶�:', cameraId); } }, /** - * 鎽勫儚澶磋缃� + * ezplayer鎺у埗浜嬩欢 */ - cameraSettings(e) { - const camera = e.currentTarget.dataset.camera; - console.log('鎽勫儚澶磋缃�:', camera.name); + onControlEvent(e) { + console.log('=== ezplayer 鎺у埗浜嬩欢 ==='); + console.log('鎺у埗浜嬩欢璇︽儏:', e); + console.log('浜嬩欢绫诲瀷:', e.type); + console.log('浜嬩欢鏁版嵁:', e.detail); - wx.showActionSheet({ - itemList: ['浜戝彴鎺у埗', '褰曞儚璁剧疆', '鐢昏川璋冭妭', '鎶ヨ璁剧疆'], - success: (res) => { - const actions = ['浜戝彴鎺у埗', '褰曞儚璁剧疆', '鐢昏川璋冭妭', '鎶ヨ璁剧疆']; - wx.showToast({ - title: `${actions[res.tapIndex]}鍔熻兘寮�鍙戜腑`, - icon: 'none' - }); + // 鑾峰彇鎽勫儚澶翠俊鎭� + const cameraId = e.currentTarget.id; + console.log('浜嬩欢鏉ユ簮鎽勫儚澶碔D:', cameraId); + + // 鏌ユ壘瀵瑰簲鐨勬憚鍍忓ご + const camera = this.data.cameraList.find(item => `ezplayer-${item.id}` === cameraId); + if (camera) { + console.log('浜嬩欢鏉ユ簮鎽勫儚澶翠俊鎭�:', camera); + + // 鏍规嵁浜嬩欢绫诲瀷澶勭悊 + switch (e.type) { + case 'play': + console.log('瑙嗛寮�濮嬫挱鏀�'); + + break; + case 'pause': + console.log('瑙嗛鏆傚仠鎾斁'); + + break; + case 'ended': + console.log('瑙嗛鎾斁缁撴潫'); + + break; + case 'error': + console.log('瑙嗛鎾斁閿欒'); + this.updateCameraUrlLoadingState(camera.id, false, true); + break; + default: + console.log('鏈煡浜嬩欢绫诲瀷:', e.type); } + } else { + console.error('鏈壘鍒板搴旂殑鎽勫儚澶�:', cameraId); + } + }, + + + + + /** + * 鏇存柊鎽勫儚澶存挱鏀剧姸鎬� + */ + updateCameraPlayState(cameraId, isPlaying) { + console.log('=== 鏇存柊鎽勫儚澶存挱鏀剧姸鎬� ==='); + console.log('鍙傛暟:', { cameraId, isPlaying }); + + const cameraList = this.data.cameraList.map(item => { + if (item.id === cameraId) { + const updatedItem = { + ...item, + isPlaying: isPlaying + }; + console.log(`鎽勫儚澶� ${cameraId} 鎾斁鐘舵�佹洿鏂�:`, { + name: updatedItem.name, + isPlaying: updatedItem.isPlaying + }); + return updatedItem; + } + return item; }); - } -}) \ No newline at end of file + + this.setData({ + cameraList: cameraList + }); + + console.log('鎾斁鐘舵�佹洿鏂板畬鎴�'); + }, + + +}) \ No newline at end of file -- Gitblit v1.8.0