ZaiZai 1 年之前
父節點
當前提交
87d3fdacc9
共有 1 個文件被更改,包括 21 次插入3 次删除
  1. 21 3
      src/plugins/HcPdfSign.js

+ 21 - 3
src/plugins/HcPdfSign.js

@@ -82,7 +82,7 @@ export default class HcPdfSign {
             console.warn('请传入签章图片')
             return false
         }
-        this.signImage(img)
+        this.signImage(img).then()
         //设置回调事件
         if (!isNullES(change)) {
             this.addEventFunc(change)
@@ -147,8 +147,26 @@ export default class HcPdfSign {
     }
 
     //设置签章图片
-    static signImage(url) {
-        this.signImgCss = { url: url, width: 100, height: 26 }
+    static async signImage(url) {
+        const res = await this.getImageSize(url)
+        const scaleFactor = 100 / res.height
+        const newWidth = res.width * scaleFactor
+        console.log(res)
+        console.log(newWidth)
+        this.signImgCss = { url: url, width: newWidth, height: 100 }
+    }
+
+    //获取网络图片的高宽
+    static async getImageSize(url) {
+        return new Promise((resolve) => {
+            let img = new Image()
+            img.onload = function () {
+                let width = img.width
+                let height = img.height
+                resolve({ width, height })
+            }
+            img.src = url
+        })
     }
 
     //创建签章图片