Pārlūkot izejas kodu

fix(shuHai/devicePhoto): 修复图片跳转定位逻辑,适配event_id参数

1. 新增接收并处理跳转携带的event_id参数
2. 根据event_id定位到对应图片项,找不到则默认使用第一个
3. 修复原逻辑直接取第一张图导致的初始定位偏差问题
4. 优化旧img_id的匹配逻辑,优先匹配传入的旧图片id
allen 3 dienas atpakaļ
vecāks
revīzija
0cd39a63d3
1 mainītis faili ar 12 papildinājumiem un 2 dzēšanām
  1. 12 2
      pages/shuHai/devicePhoto.vue

+ 12 - 2
pages/shuHai/devicePhoto.vue

@@ -229,9 +229,10 @@ export default {
     };
   },
   async onLoad(options) {
-    const {id,img_id,currentYear,addtime} = options
+    const {id,img_id,event_id,currentYear,addtime} = options
     this.device_id = id
     this.imgOld_id = img_id
+    this.event_id = event_id || ''
     this.currentYear = currentYear
     this.addtime = this.formatTime(Number(addtime)*1000);
     this.time_begin = this.addtime;
@@ -250,6 +251,14 @@ export default {
     }
     this.pestList = [];
     await this.getEventList();
+    // 定位到跳转时携带的 event_id,找不到就默认第一个
+    const fileIndex = this.fileList.findIndex(file => file.event_id == this.event_id);
+    this.fileIndex = fileIndex > -1 ? fileIndex : 0;
+    const curFile = this.fileList[this.fileIndex];
+    if (curFile) {
+      this.event_id = curFile.event_id;
+      this.camera_id = curFile.device_id;
+    }
     await this.getPestDict();
     await this.getPestLevelMap();
     await this.getPestList();
@@ -368,7 +377,8 @@ export default {
       this.thumbnails = res?.data || [];
       this.currentImg = {};
       //如果和旧的id相同,就用旧的id不然就用第一个
-      this.img_id = this.thumbnails[0]?.id
+      const oldImg = this.thumbnails.find(item => item.id == this.imgOld_id);
+      this.img_id = oldImg?.id || this.thumbnails[0]?.id || ''
       this.getDevicePhotoDetails();
     },
     formatTime(dateString) {