Explorar o código

fix: 优化签章类型尺寸设置,保持原图宽高比等比缩放

xieyong hai 2 semanas
pai
achega
1345742855
Modificáronse 1 ficheiros con 22 adicións e 8 borrados
  1. 22 8
      src/components/addDoc/seal.vue

+ 22 - 8
src/components/addDoc/seal.vue

@@ -5,7 +5,14 @@
         <!-- 右侧: 预览 & Canvas 结果 -->
         <div
           id="captureTarget"
-          style="position: fixed; left: -100000px; top: 0; width: 1240px; min-height: 1754px; background: #ffffff;"
+          style="
+            position: fixed;
+            left: -100000px;
+            top: 0;
+            width: 1240px;
+            min-height: 1754px;
+            background: #ffffff;
+          "
         >
           <div v-html="editableHtml"> </div>
         </div>
@@ -345,14 +352,21 @@
         img.onload = () => {
           console.log('图片加载成功,原始尺寸:', img.width, img.height);
 
-          // 根据签章类型设置尺寸:公用章 120x120,个人章 120x40
+          // 根据签章类型设置最大盒子尺寸,保持原图宽高比等比缩放,避免变形
+          const MAX_W = data.sealType === 'private' ? 280 : 240;
+          const MAX_H = data.sealType === 'private' ? 170 : 240;
+
+          // 原图宽高比(避免 0 除以 0,给个兜底)
+          const ratio = img.width / img.height || 1;
           let width, height;
-          if (data.sealType === 'private') {
-            width = 210;
-            height = 70;
+          if (MAX_W / MAX_H > ratio) {
+            // 盒子比原图更"宽",以高为基准
+            height = MAX_H;
+            width = height * ratio;
           } else {
-            width = 200;
-            height = 200;
+            // 盒子比原图更"窄"(或等比),以宽为基准
+            width = MAX_W;
+            height = width / ratio;
           }
 
           const posX = x - width / 2;
@@ -372,7 +386,7 @@
             imgId: data.imgId,
             imgUrl: data.url,
             version: data.version,
-            name:data.name,
+            name: data.name,
             x: posX,
             y: posY,
             width,