瀏覽代碼

fix: loadDocument 修复同时加载多个文档时获取密码报错

liutian 1 周之前
父節點
當前提交
621518d06a

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

@@ -3009,7 +3009,7 @@ class ComPDFKitViewer {
       this.passwordPrompt.open();
     };
 
-    return await loadingTask.promise.then(() => {
+    return loadingTask.promise.then(() => {
       if (password && !notUpdatePwd) this.#pwd = password
       return password
     }).catch((error) => {

+ 7 - 0
packages/core/src/message_handler.js

@@ -26,6 +26,13 @@ export default class MessageHandler {
         if (data.callback === 'resolve') {
           capability.resolve(data.data);
         } else {
+          console.log({
+            data: {
+              action: data.data.action,
+              data: data.data.data
+            },
+            message: data.reason && data.reason.message
+          })
           throw new Error("Unexpected callback case");
         }
         return;

+ 4 - 2
packages/webview/src/components/Dialogs/CompareSettingDialog.vue

@@ -449,7 +449,8 @@ const comparing = async () => {
         distanceChangedCallback: useDocument.setDistance,
         notUpdatePwd: true
       }
-      await loadDocument(res.url, options)
+      const res = await loadDocument(res.url, options)
+      if (!res) return
       loading.value = false
       
       // useViewer.toggleElement('leftPanel')
@@ -557,7 +558,8 @@ async function uploadPdf (pdf, filename = null, docNum) {
     options.pwd = pwd
   }
   try {
-    await loadDocument(pdf, options, docNum)
+    const res = await loadDocument(pdf, options, docNum)
+    if (!res) return
   } catch (error) {
     console.log(error)
     useViewer.setDownloadError('Loaded')

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

@@ -141,7 +141,9 @@ async function handlePdf (pdf, filename = null) {
     distanceChangedCallback: useDocument.setDistance
   }
   try {
-    const { pwd } = await loadDocument(pdf, options)
+    const res = await loadDocument(pdf, options)
+    if (!res) return
+    const { pwd } = res
     useDocument.setFileHasPwd(!!pwd)
     useDocument.setPassword(pwd)
     useDocument.setCurrentPdfData(pdf, options)

+ 3 - 2
packages/webview/src/components/DocumentEditorHeader/DocumentEditorHeader.vue

@@ -47,10 +47,11 @@ const save = async () => {
 
   const newUrl = await core.saveDocumentEdit()
   const pwd = useDocument.getPassword
-  await core.loadDocument(newUrl, {
+  const res = await core.loadDocument(newUrl, {
     password: pwd
   })
-  
+  if (!res) return
+
   useDocument.setCurrentPdfData(newUrl)
   const totalPages = core.getPagesCount()
   useDocument.setTotalPages(totalPages)