Pārlūkot izejas kodu

签章图片大小修改

duy 8 mēneši atpakaļ
vecāks
revīzija
4d2150c75c

+ 23 - 15
src/plugins/HcPdfSign.js

@@ -24,8 +24,10 @@ export default class HcPdfSign {
      * @param {Function} options.change 回调函数
      * @param {Function} options.load 加载完成回调函数
      * @param {boolean} options.isShowYinzhang 是否显示印章
+     * @param {number} options.width 签章图片的宽度
+     * @param {number} options.height 签章图片的高度
      */
-    static createPdf({ ele, url, img, change, load, isShowYinzhang }) {
+    static createPdf({ ele, url, img, change, load, isShowYinzhang, width, height }) {
         this.initVarNull()
         const dom = this.getDomElement(ele)
         if (!dom) return false
@@ -41,7 +43,7 @@ export default class HcPdfSign {
             console.warn('请传入签章图片')
             return false
         }
-        this.signImage(img)
+        this.signImage(img, width, height)
 
         if (!isNullES(change)) {
             this.addEventFunc(change)
@@ -162,19 +164,23 @@ export default class HcPdfSign {
     }
 
     // 设置签章图片
-    static async signImage(url) {
-        const res = await this.getImageSize(url)
-        if (res.width === res.height) {
-            this.signImgCss = { url: url, width: 170, height: 170 }
-        } else if (res.width > res.height) {
-            const scaleFactor = 30 / res.height
-            const newWidth = res.width * scaleFactor
-            this.signImgCss = { url: url, width: newWidth, height: 30 }
-        } else {
-            const scaleFactor = 170 / res.height
-            const newWidth = res.width * scaleFactor
-            this.signImgCss = { url: url, width: newWidth, height: 170 }
-        }
+    static async signImage(url, width, height) {
+        // const res = await this.getImageSize(url)
+        // if (res.width === res.height) {
+        //     this.signImgCss = { url: url, width: 170, height: 170 }
+        // } else if (res.width > res.height) {
+        //     const scaleFactor = 30 / res.height
+        //     const newWidth = res.width * scaleFactor
+        //     this.signImgCss = { url: url, width: newWidth, height: 30 }
+        // } else {
+        //     const scaleFactor = 170 / res.height
+        //     const newWidth = res.width * scaleFactor
+        //     this.signImgCss = { url: url, width: newWidth, height: 170 }
+        // }
+        this.signImgCss = { url: url, width: width, height: height }
+      
+        
+        
     }
 
     // 获取网络图片的高宽
@@ -517,6 +523,8 @@ export default class HcPdfSign {
 
     // 创建签名图片元素
     static createSignImgElement(item) {
+        console.log(item, 'createSignImgElement')
+        
         const signImg = document.createElement('img')
         signImg.setAttribute('id', item.id)
         signImg.src = item.url

+ 25 - 1
src/views/tasks/components/hc-pdf1.vue

@@ -27,6 +27,14 @@ const props = defineProps({
         type: Array,
         default: () => ([]),
     },
+    imgHeight:{
+        type: [Number, String],
+        default: '',
+    },
+    imgWidth:{
+        type: [Number, String],
+        default: '',
+    },
 })
 
 //事件
@@ -35,7 +43,21 @@ const pdf = ref(props.src)
 const uuid = getRandom(6)
 const signImg = ref(props.sign)
 const loading = ref(false)
+const imgWidth = ref(props.imgWidth)
+const imgHeight = ref(props.imgHeight)
+
 
+//监听
+watch(() => [
+props.imgWidth, props.imgHeight,
+], ([width, height]) => {
+    imgWidth.value = width
+    imgHeight.value = height
+
+    if (width && height) {
+        getPdf()
+    }
+})
 //监听PDFurl
 watch(() => props.src, (src) => {
     if (src) {
@@ -66,7 +88,7 @@ onMounted(()=> {
 
 //设置PDF签章实例
 const getPdf = () => {
-    if (!pdf.value) {
+    if (!pdf.value ) {
         noPdfUrl()
         return false
     }
@@ -74,6 +96,8 @@ const getPdf = () => {
         ele: 'pdf-view-' + uuid, //挂载元素的id
         url: pdf.value, //pdf的url地址
         img: signImg.value, //签章图片的url地址
+        width: imgWidth.value, //签章图片的宽度
+        height: imgHeight.value, //签章图片的宽度
         //加载完成
         load: () => {
             //恢复签章记录

+ 5 - 1
src/views/tasks/hc-data.vue

@@ -42,7 +42,7 @@
                 <div v-if="batchPdfUrl" class="flex-iframe">
                     <!-- <HcPdf :src="batchPdfUrl" @change="changeSealStrategy" /> -->
                     <template v-if="sbTableKey === 'key1'">
-                        <HcSignPdf v-if="pdfItem.pdfUrl" :batch="isBatch" :dom="pdfItem.hcSignImageArr" :sign="logoName" :src="pdfItem.pdfUrl" @change="pdfChange" />
+                        <HcSignPdf v-if="pdfItem.pdfUrl" :batch="isBatch" :dom="pdfItem.hcSignImageArr" :sign="logoName" :src="pdfItem.pdfUrl" :img-width="imgWidth" :img-height="imgHeight" @change="pdfChange" />
                     </template>
                     <hc-pdfs v-else :src="pdfItem.pdfUrl" />
                 </div>
@@ -187,11 +187,15 @@ const taskReviewColumns = ref([
 const pdfItem = ref({})
 const pdfIndex = ref(-1)
 const logoName = ref('')
+const imgWidth = ref()
+const imgHeight = ref()
 //获取用户信息
 const queryCurrentUserData = async () => {
     const { error, code, data } = await userApi.queryCurrentUserData()
     if (!error && code === 200) {
         logoName.value = data?.signatureUrl || ''
+        imgWidth.value = data?.wide
+        imgHeight.value = data?.high
     } else {
         logoName.value = ''
     }