Bladeren bron

摄像头初步修改和批次农场地块联调

zmj 9 uur geleden
bovenliggende
commit
50d7253bfa
3 gewijzigde bestanden met toevoegingen van 101 en 26 verwijderingen
  1. 58 3
      src/views/base/batch/index.vue
  2. 21 15
      src/views/base/device/device-monitor.vue
  3. 22 8
      src/views/base/device/index.vue

+ 58 - 3
src/views/base/batch/index.vue

@@ -342,7 +342,7 @@
           </el-radio-group>
         </el-form-item>
 
-        
+
         <!-- <el-form-item label="创建时间" prop="createdAt">
           <el-date-picker clearable
             v-model="form.createdAt"
@@ -1078,12 +1078,67 @@ export default {
     handleUpdate(row) {
       this.reset()
       const id = row.id || this.ids
+
+      // 先获取详细信息 - 修正:使用 getBatch 而不是 getSpeciesInfo
       getBatch(id).then(response => {
         this.form = response.data
-        this.open = true
-        this.title = "修改批次管理"
+
+        // 临时存储原始的 fieldId 值
+        const originalFieldId = this.form.fieldId
+
+        // 如果有农场 ID,则获取对应的地块数据
+        if (this.form.farmId != undefined && this.form.farmId != null) {
+          const data = {
+            deptId: this.form.farmId
+          }
+
+          // 清空旧的地块数据,确保重新加载
+          this.fields = []
+          this.loadingFields = true
+
+          MachineNameFieldUserText(data).then(response => {
+            // 确保地块数据的 id 类型一致(转为 Number)
+            this.fields = (response.data.fields || []).map(item => ({
+              ...item,
+              id: Number(item.id)
+            }))
+
+            this.loadingFields = false
+
+            // 使用 $nextTick 确保 fields 数组更新完成后再设置 fieldId
+            this.$nextTick(() => {
+              // 优先使用 API 返回的 fieldId,否则使用原始值
+              // 确保 fieldId 也是 Number 类型,与 options 中的 value 类型一致
+              if (originalFieldId !== null && originalFieldId !== undefined) {
+                this.form.fieldId = Number(originalFieldId)
+              } else if (response.data.fieldId !== undefined && response.data.fieldId !== null) {
+                this.form.fieldId = Number(response.data.fieldId)
+              }
+
+              // 再次使用 $nextTick 确保 fieldId 设置完成后,再打开对话框
+              this.$nextTick(() => {
+                this.open = true
+                this.title = "修改批次管理"
+              })
+            })
+          }).catch(error => {
+            console.error('获取地块数据失败:', error)
+            this.loadingFields = false
+            // 即使获取地块失败,也要打开对话框
+            this.open = true
+            this.title = "修改批次管理"
+          })
+        } else {
+          // 如果没有农场 ID 也打开对话框
+          this.open = true
+          this.title = "修改批次管理"
+        }
+      }).catch(error => {
+        console.error('获取批次信息失败:', error)
+        this.$message.error('获取数据失败')
       })
     },
+// ... existing code ...
     /** 提交按钮 */
     submitForm() {
       this.$refs["form"].validate(valid => {

+ 21 - 15
src/views/base/device/device-monitor.vue

@@ -299,7 +299,7 @@
     </div>
 
     <!-- 摄像头预览对话框 -->
-    <CameraPreview v-model="previewVisible" :camera="currentCamera" />
+    <!-- <CameraPreview v-model="previewVisible" :camera="currentCamera" /> -->
 
     <!-- 单个摄像头全屏模式 -->
     <div v-if="singleCameraFullscreen.show" class="single-camera-fullscreen">
@@ -996,17 +996,18 @@ nextPage() {
             location: '智慧农场六号',
             // previewUrl: 'https://azn.gbdfarm.com/video-proxy/',
             //previewUrl: 'wss://121.4.16.100:443/rtp/34020000001110000001_34020000001320000012.live.flv',
-            previewUrl: 'wss://nxy.gbdfarm.com:9000/rtp/34020000001110000001_34020000001320000012.live.flv',
+            previewUrl: 'wss://azn.gbdfarm.com:443/rtp/34020000001110000001_34020000001320000012.live.flv',
+            //previewUrl: 'wss://azn.gbdfarm.com:443/rtp/34020000001320000001_34020000001320000001.live.flv',
 
             domId: 'camera-1'
           },
           {
             id: 2,
             name: '葡萄园一号摄像头',
-            status: '线',
+            status: '线',
             location: '智慧农场六号',
             //previewUrl: 'http://121.4.16.100:28080/#/play/wasm/' + encodeURIComponent('ws://121.4.16.100:6080/rtp/34020000001320000001.live.flv'),
-            previewUrl: '',
+            previewUrl: 'wss://azn.gbdfarm.com:443/rtp/34020000001320000001_34020000001320000001.live.flv',
             domId: 'camera-2'
           },
           {
@@ -1139,14 +1140,14 @@ initFlvPlayer(cam) {
         hasAudio: false,  // 根据实际流调整
         hasVideo: true
       })
-      
+
       flvPlayer.attachMediaElement(videoElement)
       flvPlayer.load()
       flvPlayer.play()
-      
+
       // 保存播放器实例
       this.$set(this.playerInstances, cam.id, flvPlayer)
-      
+
       console.log(`摄像头 ${cam.id} 播放器初始化成功`)
     } else {
       console.error('浏览器不支持 FLV 播放')
@@ -1606,23 +1607,28 @@ destroyAllPlayers() {
       }
 
     })
-    const query = { deviceId: '34020000001110000001' };
-    const query2 = { deviceId: '34020000001320000001' };
-
-    playback(query).then(response => {
+    // 页面加载时自动开启摄像头播放
+    const deviceIds = ['34020000001110000001', '34020000001320000001']
+
+    deviceIds.forEach(deviceId => {
+      playback({ deviceId }).then(response => {
+        console.log(`设备 ${deviceId} 播放启动成功:`, response)
+      }).catch(error => {
+        console.error(`设备 ${deviceId} 播放启动失败:`, error)
+      })
     })
 
     /* playback(query2).then(response => {
- 
+
       this.iframeSrc = "http://121.4.16.100:28080/#/play/wasm/"+encodeURIComponent(response.msg);
- 
+
     }) */
   },
 
  beforeDestroy() {
   // 清理所有播放器实例
   this.destroyAllPlayers()
-  
+
   // 清理所有轮播定时器
   Object.values(this.carouselTimers).forEach(timer => {
     if (timer) {
@@ -1644,7 +1650,7 @@ destroyAllPlayers() {
     this.chartInstance.dispose()
     this.chartInstance = null
   }
-  
+
   // 停止播放
   const query = { deviceId: '34020000001110000001' }
   const query2 = { deviceId: '34020000001320000001' }

+ 22 - 8
src/views/base/device/index.vue

@@ -1605,7 +1605,7 @@ export default {
       this.activeControllerTab = 'basicInfoController';
       this.iframeSrc = '';
 
-      getDevice(id).then(response => {
+       getDevice(id).then(response => {
         this.formView = response.data
         this.formView.deptName = response.data.dept.deptName
         this.title = "设备详情"
@@ -1614,15 +1614,29 @@ export default {
         if (row.deviceTypeId == 2 && row.status != 0) {
           const query = { deviceId: this.deviceId };
           playback(query).then(res => {
-            // 使用写死的测试地址
-            const videoUrl = "wss://nxy.gbdfarm.com:9000/rtp/34020000001110000001_34020000001320000012.live.flv";
+            // 优先使用接口返回的视频流地址
+            let videoUrl = res.data?.videoUrl || res.videoUrl;
+
+            // 如果接口未返回,则根据设备ID使用备用地址
+            if (!videoUrl) {
+              const videoUrlMap = {
+                '34020000001110000001': 'wss://azn.gbdfarm.com:443/rtp/34020000001110000001_34020000001320000012.live.flv',
+                '34020000001320000001': 'wss://azn.gbdfarm.com:443/rtp/34020000001320000001_34020000001320000001.live.flv'
+              };
+              videoUrl = videoUrlMap[this.deviceId];
+            }
 
-            // 等待对话框打开后再初始化播放器
-            this.$nextTick(() => {
-              this.initFlvPlayer(videoUrl);
-            });
+            if (videoUrl) {
+              // 等待对话框打开后再初始化播放器
+              this.$nextTick(() => {
+                this.initFlvPlayer(videoUrl);
+              });
+            } else {
+              this.$message.warning("未找到可用的视频流地址");
+            }
           }).catch(error => {
-            this.$message.error("摄像头连接失败")
+            console.error('获取视频流失败:', error);
+            this.$message.error("摄像头连接失败");
           });
         }
       })