Browse Source

feat: 裁切图配置兼容比例格式数据

chenhao 2 years ago
parent
commit
f879d83f27
1 changed files with 15 additions and 1 deletions
  1. 15 1
      src/features/mark/CommonMarkBody.vue

+ 15 - 1
src/features/mark/CommonMarkBody.vue

@@ -45,7 +45,13 @@
       {{ markStatus }}
       <div class="double-triangle"></div>
     </div>
-    <ZoomPaper v-if="store.isScanImage && store.currentTask && sliceImagesWithTrackList.length" />
+    <ZoomPaper
+      v-if="
+        store.isScanImage &&
+        store.currentTask &&
+        sliceImagesWithTrackList.length
+      "
+    />
 
     <!-- 非启用功能 -->
     <div class="kb-circle tw-hidden">
@@ -196,6 +202,14 @@ async function processSliceConfig() {
     const url = store.currentTask.sliceUrls[sliceConfig.i - 1];
     const image = await loadImage(url);
     images[sliceConfig.i] = image;
+    const { x, y, w, h } = sliceConfig;
+    if (x < 1 && y < 1 && w < 1 && h < 1) {
+      sliceConfig.x = (image.naturalWidth * x) / 100;
+      sliceConfig.y = (image.naturalHeight * y) / 100;
+      sliceConfig.w = (image.naturalWidth * (w - x)) / 100;
+      sliceConfig.h = (image.naturalHeight * (h - y)) / 100;
+    }
+
     if (sliceConfig.w === 0 && sliceConfig.h === 0) {
       // 选择整图时,w/h 为0
       sliceConfig.w = image.naturalWidth;