Browse Source

add: 支持自动跳转下一个签名;添加未签名标签;

wzl 3 months ago
parent
commit
dc2b5b6198

+ 1 - 0
packages/core/src/form/add_signature_fields.js

@@ -123,6 +123,7 @@ export default class AddSignField {
         pageIndex: this.page,
         date: new Date(),
         rect,
+        isSigned: 0,
       }
 
       let index = 1

+ 29 - 1
packages/core/src/form/signature_fields.js

@@ -38,7 +38,7 @@ export default class SignatureFields extends Base {
     this.endCircle = null
 
     this.ratio = window.devicePixelRatio || 1
-    this.isDigital = 0
+    this.isDigital = false
 
     this.onMousedown = this.handleMouseDown.bind(this)
     this.onMouseup = this.handleMouseUp.bind(this)
@@ -77,6 +77,7 @@ export default class SignatureFields extends Base {
     annotationContainer.style.left = rect.left + 'px'
     annotationContainer.style.width = rect.width + 'px'
     annotationContainer.style.height = rect.height + 'px'
+    annotationContainer.style.overflow = 'hidden'
     this.annotationContainer = annotationContainer
 
     let shapeElement = createElement(
@@ -93,6 +94,30 @@ export default class SignatureFields extends Base {
     )
     this.shapeElement = shapeElement
 
+    if (!this.annotation.isSigned) {
+      let tagElement = createElement(
+        'div',
+        {
+          position: 'absolute',
+          left: 0,
+          top: 0,
+          width: '73px',
+          height: '22px',
+          backgroundColor: '#1460F3',
+          fontSize: '12px',
+          fontWeight: '600',
+          color: 'white',
+          lineHeight: '22px',
+          textAlign: 'center',
+          transformOrigin: '0 0',
+        }
+      )
+      tagElement.innerText = 'SIGN HERE'
+      const scale = Math.min(rect.width / 73, rect.height / 22)
+      tagElement.style.transform = scale < 1 ? `scale(${scale})` : ''
+      this.tagElement = tagElement
+    }
+
     const signature = this.layer.annotationStore.signatures.find(item => item.signaturePtr === this.annotation.signaturePtr)
     if (signature) {
       this.isDigital = signature.isDigital
@@ -100,6 +125,7 @@ export default class SignatureFields extends Base {
     await this.getSignatureImage()
 
     this.annotationContainer.append(this.shapeElement)
+    this.annotationContainer.append(this.tagElement)
     this.annotationContainer.addEventListener('mousedown', this.handleClick.bind(this))
     this.container.append(this.annotationContainer)
 
@@ -795,6 +821,8 @@ export default class SignatureFields extends Base {
   async updateAp(annotPtr) {
     if (this.annotation.annotPtr !== annotPtr && this.annotation.signaturePtr !== annotPtr) return
     this.isDigital = false
+    this.annotation.isSigned = 1
+    this.tagElement.remove()
     await this.getSignatureImage()
   }
 }

+ 22 - 1
packages/core/src/index.js

@@ -315,6 +315,9 @@ class ComPDFKitViewer {
           this.eventBus.dispatch("LoadFont", { fontFamily })
         })
       }
+      if (options.autoJumpNextSign) {
+        this.autoJumpNextSign = options.autoJumpNextSign
+      }
     }
     return verified
   }
@@ -3960,8 +3963,10 @@ class ComPDFKitViewer {
   }
 
   async updateSignatureAp(data) {
-    const { type, pagePtr, rect, annotPtr, imageArray, imageBase64 } = data
+    const { type, pagePtr, rect, annotPtr, imageArray, imageBase64, annotation } = data
 
+    const oldIndex = this.autoJumpNextSign ? Object.values(this.annotations).findIndex(item => item.name === annotation.name) : 0
+    
     if (type) {
       const { content, isDrawOnlyContent = false, isDrowLogo = false, isContentAlginLeft, text, logoBase64, pkcs12Buffer, password, } = data
       const blobData = await this.messageHandler.sendWithPromise('UpdateDigitalSignAp', {
@@ -3995,6 +4000,18 @@ class ComPDFKitViewer {
       this.eventBus.dispatch('updateSignatureFieldAp', annotPtr)
     }
 
+    if (this.autoJumpNextSign) {
+      const annotations = Object.values(this.annotations)
+      const signatureFieldsNotSign = annotations
+      .slice(oldIndex)
+      .concat(annotations.slice(0, oldIndex))
+      .flat()
+      .filter(item => item.type === 'signatureFields' && !item.isSigned)
+
+      const index = signatureFieldsNotSign.findIndex(item => item.name === annotation.name)
+      const nextSign = signatureFieldsNotSign[index + 1]
+      nextSign && this.jumpToAnnotation(nextSign)
+    }
   }
 
   async verifySignature() {
@@ -4379,6 +4396,10 @@ class ComPDFKitViewer {
       this.eventBus._on('annotationChanged', eventHandler)
     })
   }
+
+  setAutoJumpNextSign(value) {
+    this.autoJumpNextSign = value
+  }
 }
 
 class PDFWorker {

+ 2 - 1
packages/core/src/signatures.js

@@ -205,7 +205,8 @@ class Signatures {
         pagePtr,
         rect,
         imageArray,
-        imageBase64
+        imageBase64,
+        annotation
       })
     }
 

+ 2 - 1
packages/core/src/worker/compdfkit_worker.js

@@ -396,6 +396,7 @@ class CPDFWorker {
 
       Module._RemoveAP(annotPtr)
       Module._SetImageStampByStream(annotPtr, 0, imageData.length, 0)
+      Module._SignWithName(annotPtr)
     })
 
     messageHandler.on('TestAddSignature', async (data) => {
@@ -2921,8 +2922,8 @@ function getWidgetAnnotation({
       const signaturePtr = signaturePtrList[i]
       const res = Module._IsSameAnnotDict(signaturePtr, annotPtr)
       if (res) annotation.signaturePtr = signaturePtr
+      annotation.isSigned = Module._IsSigned(annotPtr)
     }
-    
   }
 
   return annotation

+ 4 - 9
packages/webview/src/apis/index.js

@@ -22,6 +22,7 @@ import getToolColor from './getToolColor';
 import getTool from './getTool';
 import getActiveTool from './getActiveTool';
 import cropPagePopup from './cropPagePopup';
+import setAutoJumpNextSign from './setAutoJumpNextSign';
 
 export default () => {
   const { locale } = i18n.global
@@ -36,7 +37,7 @@ export default () => {
   const CORE_NAMESPACE = 'Core';
   const UI_NAMESPACE = 'UI';
   const objForWebViewerCore = {
-    instance: window.instance
+    ...core,
     // Tools: window.Core.Tools,
     // Annotations: window.Core.Annotations,
     // PartRetrievers: window.Core.PartRetrievers,
@@ -63,19 +64,13 @@ export default () => {
     getToolColor: getToolColor(useDocument),
     getTool: getTool(useDocument),
     cropPagePopup: cropPagePopup(viewerStore),
+    setAutoJumpNextSign: setAutoJumpNextSign(useDocument),
   }
-  const documentViewer = core.getDocumentViewer(1);
 
   window.instances = {
     // CORE_NAMESPACE_KEY: CORE_NAMESPACE,
     // UI_NAMESPACE_KEY: UI_NAMESPACE,
-    [CORE_NAMESPACE]: {
-      ...objForWebViewerCore,
-      ...core,
-      documentViewer,
-      // annotationManager: documentViewer.getAnnotationManager(),
-      getDocumentViewers: () => core.getDocumentViewers(),
-    },
+    [CORE_NAMESPACE]: objForWebViewerCore,
     [UI_NAMESPACE]: objForWebViewerUI,
   };
 }

+ 4 - 0
packages/webview/src/apis/setAutoJumpNextSign.js

@@ -0,0 +1,4 @@
+
+export default (useDocument) => (value) => {
+  useDocument.setAutoJumpNextSign(!!value);
+}

+ 1 - 0
packages/webview/src/components/DocumentContainer/DocumentContainer.vue

@@ -269,6 +269,7 @@ window.instance.initOptions = async (options) => {
   if (!options.initialDoc) {
     useViewer.setUpload(false)
   }
+  options.autoJumpNextSign && useDocument.setAutoJumpNextSign(true)
 
   core.addEvent('onPagesUpdated', (data) => {
     const { pageNumber } = data

+ 3 - 1
packages/webview/src/core/index.js

@@ -78,6 +78,7 @@ import eventBus from './eventBus'
 import handleContentEditorPopup from './handleContentEditorPopup'
 import addAnnotationImage from './addAnnotationImage'
 import applyRedactions from './applyRedactions'
+import setAutoJumpNextSign from './setAutoJumpNextSign'
 
 export default {
   getDocumentViewer,
@@ -162,5 +163,6 @@ export default {
   eventBus,
   handleContentEditorPopup,
   addAnnotationImage,
-  applyRedactions
+  applyRedactions,
+  setAutoJumpNextSign
 }

+ 3 - 0
packages/webview/src/core/setAutoJumpNextSign.js

@@ -0,0 +1,3 @@
+import core from '@/core'
+
+export default (value) => core.getDocumentViewer().setAutoJumpNextSign(value)

+ 8 - 0
packages/webview/src/stores/modules/document.js

@@ -158,6 +158,7 @@ export const useDocumentStore = defineStore({
     highlightLink: true,
     highlightForm: true,
     redactionPrompted: false, // redaction首次进入提示
+    autoJumpNextSign: false,
   }),
   getters: {
     getTotalPages () {
@@ -318,6 +319,9 @@ export const useDocumentStore = defineStore({
     getRedactionPrompted () {
       return this.redactionPrompted
     },
+    getAutoJumpNextSign () {
+      return this.autoJumpNextSign
+    },
   },
   actions: {
     resetSetting () {
@@ -522,5 +526,9 @@ export const useDocumentStore = defineStore({
     setRedactionPrompted (val) {
       this.redactionPrompted = val
     },
+    setAutoJumpNextSign (val) {
+      this.autoJumpNextSign = val
+      core.setAutoJumpNextSign(val)
+    },
   }
 })