Explorar el Código

fix: 三轮测试修复

wzl hace 1 año
padre
commit
12257b0b09

+ 12 - 7
packages/core/src/index.js

@@ -342,6 +342,7 @@ class ComPDFKitViewer {
     annotationStore.annotationsAll = null
     annotationStore.selectedName = null
     this.fontFileInited = false
+    this.saveAction = null
     const parameters = {
       cMapUrl: CMAP_URL,
       cMapPacked: true,
@@ -2700,7 +2701,7 @@ class ComPDFKitViewer {
     }
   }
 
-  async checkPassword(file) {
+  async checkPassword(file, notUpdatePwd = false) {
     const parameters = {
       cMapUrl: CMAP_URL,
       cMapPacked: true,
@@ -2717,16 +2718,18 @@ class ComPDFKitViewer {
     }
     const loadingTask = getDocument(parameters)
     this.pdfLoadingTask = loadingTask
-    this.#pwd = ''
-    const getPwd = (pwd) => this.#pwd = pwd
+    let password = ''
+    const getPwd = (pwd) => password = pwd
     loadingTask.onPassword = (updateCallback, reason) => {
       this.passwordPrompt.setUpdateCallback(updateCallback, reason, getPwd);
       this.passwordPrompt.open();
     };
 
     return await loadingTask.promise.then(() => {
-      if (this.#pwd) return this.#pwd
-      return ''
+      if (password) {
+        if (!notUpdatePwd) this.#pwd = password
+        return password
+      }
     }).catch((error) => {
       return false
     })
@@ -2785,7 +2788,7 @@ class ComPDFKitViewer {
     if (!this.docEditorCopy) {
       const doc = await this.messageHandler.sendWithPromise('createEditorDoc', {
         doc: this.doc,
-        password: this.#oldPwd
+        password: this.#oldPwd || this.#pwd
       });
       const pages = await this.getPages(doc);
 
@@ -2871,9 +2874,10 @@ class ComPDFKitViewer {
         return
       }
 
+      if (this.saveAction === 'remove') this.#pwd = ''
       const blobData = await this.messageHandler.sendWithPromise('SaveDocumentByStream', {
         doc,
-        saveType: 2,
+        saveType: this.saveAction === 'remove' ? 3 : 2,
         password: this.#pwd,
         oldPassword: this.#oldPwd
       })
@@ -2882,6 +2886,7 @@ class ComPDFKitViewer {
       if (op === 'saveAs') return { blobData, filename }
 
       const newUrl = URL.createObjectURL(blobData)
+      if (this.saveAction === 'set' && this.#oldPwd !== this.#pwd) this.#oldPwd = this.#pwd
       await this.loadDocument(newUrl, { filename, notUpdatePwd: true })
       await clearDocument()
       return newUrl

+ 1 - 1
packages/webview/src/components/Dialogs/InsertPageSettingDialog.vue

@@ -187,7 +187,7 @@ const handleFile = async (e) => {
   if (!e.target.files[0]) return
 
   let url = URL.createObjectURL(e.target.files[0])
-  const pass = await core.checkPassword(url)
+  const pass = await core.checkPassword(url, true)
   if (pass === false) {
     e.target.value = ''
     return

+ 11 - 7
packages/webview/src/components/DocumentEditorContainer/DocumentEditorContainer.vue

@@ -52,11 +52,10 @@
         }"
         ref="imgBoxEl"
       >
-        <div class="img-box">
-          <img v-if="item.img" :src="item.img" @click="selectPage(index)" :style="`transform: rotate(${rotationToAngle(item.rotation)}deg);`" />
+        <div class="img-box" @click="selectPage(index)">
+          <img v-if="item.img" :src="item.img" :style="`transform: rotate(${rotationToAngle(item.rotation)}deg);`" />
           <div v-else-if="item.type === 'blank'"
             :class="{ 'blank-page': item.type === 'blank' }"
-            @click="selectPage(index)"
             :style="{ 'transform': 'rotate(' + rotationToAngle(item.rotation) + 'deg)', 'width': blankPageScaleSize(item.size).width + 'px', 'height': blankPageScaleSize(item.size).height + 'px' }">
           </div>
         </div>
@@ -76,6 +75,7 @@ import { ref, onMounted, reactive, onUnmounted, computed } from 'vue'
 import { useViewerStore } from '@/stores/modules/viewer'
 import { useDocumentStore } from '@/stores/modules/document'
 import core from '@/core'
+import { isMobileDevice } from '@/helpers/device'
 
 const { Sortable } = defineProps(['Sortable'])
 
@@ -98,7 +98,6 @@ const docEditorContainer = ref(null)
 
 const ratio = window.devicePixelRatio || 1
 const isMobileWidth = window.innerWidth < 768
-const isMobileDevice = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
 let timer = null
 
 onMounted(() => {
@@ -109,7 +108,7 @@ onMounted(() => {
     dragClass: "sortable-drag",
     sort: false,
     forceFallback: true,
-    fallbackTolerance: 20,
+    fallbackTolerance: isMobileDevice ? 0 : 20,
     onStart: dragStart,
     onEnd: dragEnd,
     delay: isMobileDevice ? 200 : 0
@@ -311,7 +310,7 @@ const replacePage = () => {
     const startIndex = selectedPageList[0]
 
     let url = URL.createObjectURL(file)
-    const pass = await core.checkPassword(url)
+    const pass = await core.checkPassword(url, true)
     if (pass === false) return
 
     handleInsertPage({
@@ -581,6 +580,7 @@ const handleAutoScroll = (clientY) => {
 
 <style lang="scss">
 .document-editor-container {
+  margin-top: 44px;
   width: 100%;
   background-color: var(--c-doc-editor-bg);
   overflow: auto;
@@ -590,6 +590,7 @@ const handleAutoScroll = (clientY) => {
     display: flex;
     align-items: center;
     justify-content: center;
+    margin-top: -44px;
     width: 100%;
     height: 44px;
     z-index: 71;
@@ -616,7 +617,6 @@ const handleAutoScroll = (clientY) => {
   }
 
   .page-container {
-    margin-top: 44px;
     padding-bottom: 30px;
     display: flex;
     flex-flow: wrap;
@@ -640,6 +640,10 @@ const handleAutoScroll = (clientY) => {
         width: 100%;
         height: calc(100% - 24px);
 
+        img {
+          pointer-events: none;
+        }
+
         img,
         .blank-page {
           max-width: 100%;

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

@@ -43,6 +43,7 @@ const save = async () => {
   useViewer.setActiceToolMode('view')
   useViewer.setUpload(false)
   useViewer.setUploadLoading(true)
+  const oldScale = useViewer.getScale
 
   const { newUrl } = await core.saveDocumentEdit()
   
@@ -53,6 +54,8 @@ const save = async () => {
   useViewer.setCurrentPage(1)
   core.switchScrollMode(scrollMode.value === 'Vertical' ? 0 : 1)
   core.switchSpreadMode(pageMode.value)
+  useViewer.setCurrentScale(oldScale / 100)
+  core.scaleChanged(oldScale / 100)
 
   useViewer.setUploadLoading(false)
   useViewer.setUpload(true)

+ 1 - 1
packages/webview/src/core/checkPassword.js

@@ -1,3 +1,3 @@
 import core from '@/core'
 
-export default (file) => core.getDocumentViewer().checkPassword(file)
+export default (file, notUpdatePwd) => core.getDocumentViewer().checkPassword(file, notUpdatePwd)