Selaa lähdekoodia

fix: test to fix

unknown 8 kuukautta sitten
vanhempi
sitoutus
a1ff054b03
1 muutettua tiedostoa jossa 21 lisäystä ja 31 poistoa
  1. 21 31
      src/views/demo/dataAugmentation/index.vue

+ 21 - 31
src/views/demo/dataAugmentation/index.vue

@@ -48,13 +48,13 @@
     <FormDialog ref="formDialogRef" />
     <ImportExcel ref="dialogRef" />
     <el-dialog v-model="dialogVisible" :title="dialogTitle" width="80%">
-      <div class="image-dialog" v-if="imageIdx > 0">
-        <el-image :src="'data:image/png;base64,' + cacheImages[imageIdx].origin" style="width: 45%"></el-image>
-        <el-image :src="'data:image/png;base64,' + cacheImages[imageIdx].stable" style="width: 45%"></el-image>
+      <div class="image-dialog" v-if="imageIdx >= 0">
+        <el-image :src="cacheImages[imageIdx].origin" style="width: 45%"></el-image>
+        <el-image :src="cacheImages[imageIdx].stable" style="width: 45%"></el-image>
       </div>
       <div class="image-dialog-btn" v-if="imageFps == 0">
-        <el-button type="primary" @click="pre_picture" :disabled="imageIdx <= 1">上一个</el-button>
-        <el-button type="primary" @click="next_picture" :disabled="imageIdx >= fileCount">下一个</el-button>
+        <el-button type="primary" @click="pre_picture" :disabled="imageIdx <= 0">上一个</el-button>
+        <el-button type="primary" @click="next_picture" :disabled="imageIdx >= fileCount - 1">下一个</el-button>
       </div>
     </el-dialog>
   </div>
@@ -94,7 +94,7 @@ const imageBase64List = ref({
 const inFileCount = ref(0)
 const outFileCount = ref(0)
 // 直接缓存所有图片
-const cacheImages = ref({ 0: { origin: '', stable: '' } })
+const cacheImages = ref({})
 const dialogTitle = ref('')
 const fileCount = ref(0)
 const imageFps = ref(0)
@@ -152,20 +152,6 @@ const getTaskType = async () => {
 onMounted(() => {
   getTaskType()
 })
-const changeFps = () => {
-  console.log('changeFps')
-  if (intervalChangeFps.value) {
-    clearInterval(intervalChangeFps.value)
-  }
-
-  if (imageFps.value == 0) {
-    return
-  }
-  imageIdx.value = 1
-  intervalChangeFps.value = setInterval(() => {
-    next_picture()
-  }, 1000 / imageFps.value)
-}
 
 const startDataAugmentation = async (params: any) => {
   const res = await startDataAugmentationApi(params.id)
@@ -189,8 +175,10 @@ const stopDataAugmentation = async (params: any) => {
 
 const loadImageData = async (taskId: string, imageIdx: number) => {
   const res: any = await getCompareImageApi(taskId, imageIdx)
-  imageBase64List.value.origin = res.origin
-  imageBase64List.value.stable = res.stable
+  // imageBase64List.value.origin = res.origin
+  // imageBase64List.value.stable = res.stable
+  cacheImages.value[imageIdx].origin = 'data:image/png;base64,' + res.origin
+  cacheImages.value[imageIdx].stable = 'data:image/png;base64,' + res.stable
 }
 
 const compareDataAugmentation = async (params: any) => {
@@ -211,19 +199,21 @@ const compareDataAugmentation = async (params: any) => {
   fileCount.value = Math.min(inFileCount.value, outFileCount.value)
   for (let idx = 1; idx <= fileCount.value; idx++) {
     dialogTitle.value = '缓存图片中: 第' + idx + '张图片 共' + fileCount.value + '张图片'
-    if (cacheImages.value[idx]) {
+    if (cacheImages.value[idx - 1]) {
       continue
     }
-    const res: any = await getCompareImageApi(taskId.value, idx)
-    cacheImages.value[idx] = {
-      origin: res.origin,
-      stable: res.stable
+    const res: any = await getCompareImageApi(taskId.value, idx - 1)
+    cacheImages.value[idx - 1] = {
+      origin: 'data:image/png;base64,' + res.origin,
+      stable: 'data:image/png;base64,' + res.stable
     }
   }
-  next_picture()
+  console.log(cacheImages.value[0])
+  dialogTitle.value = '预览: 第1张图片 共' + fileCount.value + '张图片'
+  // next_picture()
 }
 const next_picture = async () => {
-  if (imageIdx.value < fileCount.value) {
+  if (imageIdx.value < fileCount.value - 1) {
     if (!cacheImages.value[imageIdx.value + 1]) {
       await loadImageData(taskId.value, imageIdx.value + 1)
     }
@@ -232,13 +222,13 @@ const next_picture = async () => {
   dialogTitle.value = '预览: 第' + imageIdx.value + '张图片 共' + fileCount.value + '张图片'
 }
 const pre_picture = async () => {
-  if (imageIdx.value > 1) {
+  if (imageIdx.value > 0) {
     if (!cacheImages.value[imageIdx.value - 1]) {
       await loadImageData(taskId.value, imageIdx.value - 1)
     }
     imageIdx.value = imageIdx.value - 1
   }
-  dialogTitle.value = '预览: 第' + imageIdx.value + '张图片 共' + fileCount.value + '张图片'
+  dialogTitle.value = '预览: 第' + imageIdx.value + 1 + '张图片 共' + fileCount.value + '张图片'
 }
 
 // ProTable 实例