Browse Source

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

liutian 2 weeks ago
parent
commit
0010f8f243

+ 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) => {

+ 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)