Browse Source

fix: 左边栏隐藏图层;get方法返回值替换;修改文案;修改文档对比结果下载文件名;浏览器设置语言;

wzl 1 year ago
parent
commit
ed57b8dd39

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

@@ -2043,13 +2043,13 @@ class ComPDFKitViewer {
       })
       })
       if (data.type === 1) {
       if (data.type === 1) {
         return [{
         return [{
-          filename: 'oldFile.pdf',
+          filename: data.leftFile.name.replace(/(\.pdf)/, `_${this.$t('compare.byComPDFKit')}.pdf`),
           url: URL.createObjectURL(res[0])
           url: URL.createObjectURL(res[0])
         }, {
         }, {
-          filename: 'newFile.pdf',
+          filename: data.rightFile.name.replace(/(\.pdf)/, `_${this.$t('compare.byComPDFKit')}.pdf`),
           url: URL.createObjectURL(res[1])
           url: URL.createObjectURL(res[1])
         }, {
         }, {
-          filename: 'mergeFile.pdf',
+          filename: this.$t('compare.byComPDFKit') + '.pdf',
           url: URL.createObjectURL(res[2])
           url: URL.createObjectURL(res[2])
         }
         }
         ]
         ]

+ 14 - 14
packages/core/src/worker/compdfkit_worker.js

@@ -1450,8 +1450,8 @@ function getAnnotation({
         A: FontDa.A
         A: FontDa.A
       }
       }
 
 
-      const rawFreetextContent = Module._GetFreeTextContent(annotPtr)
-      const freetextContent = UTF8ToString(rawFreetextContent)
+      Module._GetFreeTextContent(annotPtr)
+      const freetextContent = U8StringData
       annotation.content = freetextContent
       annotation.content = freetextContent
 
 
       RGBColor = {}
       RGBColor = {}
@@ -1623,8 +1623,8 @@ function getWidgetAnnotation({
   const borderStyleType = Module._GetWidgetBorderStyle(annotPtr)
   const borderStyleType = Module._GetWidgetBorderStyle(annotPtr)
   annotation.borderStyle = BorderStyleString[borderStyleType]
   annotation.borderStyle = BorderStyleString[borderStyleType]
 
 
-  const rawFieldName = Module._GetWidgetFieldName(annotPtr)
-  const fieldName = UTF8ToString(rawFieldName)
+  Module._GetWidgetFieldName(annotPtr)
+  const fieldName = U8StringData
   annotation.fieldName = fieldName
   annotation.fieldName = fieldName
 
 
   const borderWidth = Module._GetAnnotBorderWidth(annotPtr)
   const borderWidth = Module._GetAnnotBorderWidth(annotPtr)
@@ -1673,8 +1673,8 @@ function getWidgetAnnotation({
       return null
       return null
     }
     }
 
 
-    const rawContent = Module._GetTextFieldContent(annotPtr)
-    const content = UTF8ToString(rawContent)
+    Module._GetTextFieldContent(annotPtr)
+    const content = U8StringData
     annotation.content = content
     annotation.content = content
 
 
     const isMultiLine = Module._IsMultiLine(annotPtr)
     const isMultiLine = Module._IsMultiLine(annotPtr)
@@ -1702,22 +1702,22 @@ function getWidgetAnnotation({
   }
   }
 
 
   if (type === 0) {
   if (type === 0) {
-    const rawTitle = Module._GetButtonTitle(annotPtr)
-    const title = UTF8ToString(rawTitle)
+    Module._GetButtonTitle(annotPtr)
+    const title = U8StringData
     annotation.title = title
     annotation.title = title
 
 
     const actionType = Module._GetBtnActionType(annotPtr)
     const actionType = Module._GetBtnActionType(annotPtr)
 
 
-    const rawActionName = Module._GetBtnActionNamedAction(annotPtr)
-    const actionName = UTF8ToString(rawActionName)
+    Module._GetBtnActionNamedAction(annotPtr)
+    const actionName = U8StringData
     annotation.actionName = actionName
     annotation.actionName = actionName
     if (actionType === 1) {
     if (actionType === 1) {
       const destPage = Module._GetBtnActionDestPage(doc, annotPtr)
       const destPage = Module._GetBtnActionDestPage(doc, annotPtr)
       annotation.destPage = destPage + 1
       annotation.destPage = destPage + 1
 
 
     } else if (actionType === 6) {
     } else if (actionType === 6) {
-      const rawActionURI = Module._GetBtnActionURI(annotPtr)
-      const actionURI = UTF8ToString(rawActionURI)
+      Module._GetBtnActionURI(annotPtr)
+      const actionURI = U8StringData
       annotation.url = actionURI
       annotation.url = actionURI
     }
     }
     annotation.actionType = actionType
     annotation.actionType = actionType
@@ -1754,8 +1754,8 @@ function getWidgetAnnotation({
     Module._GetWidgetItems(annotPtr)
     Module._GetWidgetItems(annotPtr)
     annotation.items = WidgetItemsArray
     annotation.items = WidgetItemsArray
 
 
-    const rawSelectedValue = Module._GetItemsSelectedValue(annotPtr)
-    const selectedValue = UTF8ToString(rawSelectedValue)
+    Module._GetItemsSelectedValue(annotPtr)
+    const selectedValue = U8StringData
     if (selectedValue) {
     if (selectedValue) {
       for (let i = 0; i < WidgetItemsArray.length; i++) {
       for (let i = 0; i < WidgetItemsArray.length; i++) {
         if (WidgetItemsArray[i].Value === selectedValue) {
         if (WidgetItemsArray[i].Value === selectedValue) {

+ 5 - 2
packages/webview/locales/en.json

@@ -154,7 +154,8 @@
 
 
   "prevent": {
   "prevent": {
     "title": "Not Available in Server-Backed",
     "title": "Not Available in Server-Backed",
-    "description": "Content Editor is only available on Standalone. Change to Standalone to edit PDF content."
+    "description": "Content Editor is only available on Standalone. Change to Standalone to edit PDF content.",
+    "standalone": "Standalone"
   },
   },
 
 
   "passwordDialog": {
   "passwordDialog": {
@@ -251,7 +252,9 @@
 
 
     "printSetting": "Print Setting",
     "printSetting": "Print Setting",
     "printOldFile": "Print the comparison result of the old file",
     "printOldFile": "Print the comparison result of the old file",
-    "printNewFile": "Print the comparison result of the new file"
+    "printNewFile": "Print the comparison result of the new file",
+
+    "byComPDFKit": "Comparison Results by ComPDFKit"
   },
   },
 
 
   "editorPanel": {
   "editorPanel": {

+ 5 - 2
packages/webview/locales/zh-CN.json

@@ -154,7 +154,8 @@
 
 
   "prevent": {
   "prevent": {
     "title": "不可用",
     "title": "不可用",
-    "description": "在线版不支持内容编辑,请切换到离线版模式使用内容编辑。"
+    "description": "在线版不支持内容编辑,请切换到离线版(Standalone)模式使用内容编辑。",
+    "standalone": "离线版"
   },
   },
 
 
   "passwordDialog": {
   "passwordDialog": {
@@ -251,7 +252,9 @@
 
 
     "printSetting": "打印文件选择",
     "printSetting": "打印文件选择",
     "printOldFile": "打印旧文档的对比结果文件",
     "printOldFile": "打印旧文档的对比结果文件",
-    "printNewFile": "打印新文档的对比结果文件"
+    "printNewFile": "打印新文档的对比结果文件",
+
+    "byComPDFKit": "由ComPDFKit提供对比"
   },
   },
 
 
   "editorPanel": {
   "editorPanel": {

+ 1 - 0
packages/webview/package.json

@@ -14,6 +14,7 @@
     "@vueuse/integrations": "^9.5.0",
     "@vueuse/integrations": "^9.5.0",
     "axios": "^0.27.2",
     "axios": "^0.27.2",
     "dayjs": "^1.11.6",
     "dayjs": "^1.11.6",
+    "file-saver": "^2.0.5",
     "pinia": "^2.0.36",
     "pinia": "^2.0.36",
     "vue": "^3.2.41",
     "vue": "^3.2.41",
     "vue-i18n": "9"
     "vue-i18n": "9"

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

@@ -139,21 +139,24 @@ watch(() => toolMode.value, (newValue, oldValue) => {
 // 点击选择文件上传
 // 点击选择文件上传
 const uploadFile = async (e, flag) => {
 const uploadFile = async (e, flag) => {
   if (!e.target.files[0]) return
   if (!e.target.files[0]) return
+
   let url = URL.createObjectURL(e.target.files[0])
   let url = URL.createObjectURL(e.target.files[0])
   const pass = await core.checkPassword(url)
   const pass = await core.checkPassword(url)
   if (pass === false) {
   if (pass === false) {
     e.target.value = ''
     e.target.value = ''
     return
     return
   }
   }
+
+  const filename = e.target.files[0].name
   if (flag === 'old') {
   if (flag === 'old') {
     useDocument.setCompareFiles('oldFile', e.target.files[0])
     useDocument.setCompareFiles('oldFile', e.target.files[0])
     useDocument.setCompareFiles('oldFilePassword', pass)
     useDocument.setCompareFiles('oldFilePassword', pass)
-    handleUpload(url, 2)
+    handleUpload(url, filename, 2)
   }
   }
   if (flag === 'new') {
   if (flag === 'new') {
     useDocument.setCompareFiles('newFile', e.target.files[0])
     useDocument.setCompareFiles('newFile', e.target.files[0])
     useDocument.setCompareFiles('newFilePassword', pass)
     useDocument.setCompareFiles('newFilePassword', pass)
-    handleUpload(url, 3)
+    handleUpload(url, filename, 3)
   }
   }
 }
 }
 
 
@@ -187,15 +190,16 @@ const handleDrop = async (e, flag) => {
     return
     return
   }
   }
 
 
+  const filename = files[0].name
   if (flag === 'old') {
   if (flag === 'old') {
     useDocument.setCompareFiles('oldFile', files[0])
     useDocument.setCompareFiles('oldFile', files[0])
     useDocument.setCompareFiles('oldFilePassword', pass)
     useDocument.setCompareFiles('oldFilePassword', pass)
-    handleUpload(url, 2)
+    handleUpload(url, filename, 2)
   }
   }
   if (flag === 'new') {
   if (flag === 'new') {
     useDocument.setCompareFiles('newFile', files[0])
     useDocument.setCompareFiles('newFile', files[0])
     useDocument.setCompareFiles('newFilePassword', pass)
     useDocument.setCompareFiles('newFilePassword', pass)
-    handleUpload(url, 3)
+    handleUpload(url, filename, 3)
   }
   }
 }
 }
 
 
@@ -250,15 +254,15 @@ const clearDocumentViewer = () => {
 }
 }
 
 
 // 上传文件
 // 上传文件
-async function handleUpload (url, docNum) {
+async function handleUpload (url, filename, docNum) {
   useViewer.setUpload(true)
   useViewer.setUpload(true)
   useViewer.setUploadLoading(true)
   useViewer.setUploadLoading(true)
-  await handlePdf(url, null, docNum)
+  await handlePdf(url, filename, docNum)
   useViewer.setUploadLoading(false)
   useViewer.setUploadLoading(false)
 }
 }
 
 
 // 预览pdf
 // 预览pdf
-async function handlePdf (pdf, filename = null, docNum) {
+async function handlePdf (pdf, filename, docNum) {
   let pwd = null
   let pwd = null
   if (docNum === 2) {
   if (docNum === 2) {
     pwd = useDocument.getCompareFile('oldFilePassword')
     pwd = useDocument.getCompareFile('oldFilePassword')

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

@@ -441,7 +441,7 @@ const comparing = async () => {
       useDocument.resetSetting()
       useDocument.resetSetting()
 
 
       const options = {
       const options = {
-        filename: instance.$i18n.locale !== 'en' ? '由ComPDFKit提供对比.pdf' : 'Comparison Results by ComPDFKit.pdf',
+        filename: t('compare.byComPDFKit') + '.pdf',
         progress: useDocument.setLoadingProgress,
         progress: useDocument.setLoadingProgress,
         pageChangedCallback: useViewer.setCurrentPage,
         pageChangedCallback: useViewer.setCurrentPage,
         scaleChangedCallback: useViewer.setCurrentScale,
         scaleChangedCallback: useViewer.setCurrentScale,

+ 4 - 3
packages/webview/src/components/Dialogs/DownloadSettingDialog.vue

@@ -25,8 +25,7 @@
 import { ref, computed, watch } from 'vue'
 import { ref, computed, watch } from 'vue'
 import { useViewerStore } from '@/stores/modules/viewer'
 import { useViewerStore } from '@/stores/modules/viewer'
 import { useDocumentStore } from '@/stores/modules/document'
 import { useDocumentStore } from '@/stores/modules/document'
-import core from '@/core'
-const { download } = core
+import { saveAs } from 'file-saver';
 
 
 const useViewer = useViewerStore()
 const useViewer = useViewerStore()
 const useDocument = useDocumentStore()
 const useDocument = useDocumentStore()
@@ -52,7 +51,9 @@ const handleFlatten = async () => {
   closeDialog()
   closeDialog()
   useViewer.setDownloading(true)
   useViewer.setDownloading(true)
   try {
   try {
-    await download(true, data)
+    data.forEach(file => {
+      saveAs(file.url, file.filename)
+    })
     useViewer.setDownloading(false)
     useViewer.setDownloading(false)
   } catch (error) {
   } catch (error) {
     console.log(error)
     console.log(error)

+ 1 - 0
packages/webview/src/components/Dialogs/LanguageDialog.vue

@@ -45,6 +45,7 @@
 
 
   const handleLanguage = () => {
   const handleLanguage = () => {
     locale.value = selectedLanguage.value
     locale.value = selectedLanguage.value
+    window.localStorage.setItem('language', selectedLanguage.value)
     useViewer.closeElement('languageDialog')
     useViewer.closeElement('languageDialog')
   }
   }
 </script>
 </script>

+ 0 - 84
packages/webview/src/components/EditModal/EditModal.vue

@@ -1,84 +0,0 @@
-<template>
-  <div v-if="showDialog" class="edit-dialog">
-    <div class="edit">
-      <div class="close"><Close @click="closeDialog" /></div>
-      <div class="warning"><Warning /></div>
-      <div class="title">Not Available in Offline</div>
-      <div class="des">Content Editor is only supported on PSPDFKit for Web Standalone. Change your deployment to view the example.</div>
-      <div class="button" @click="submit">OK</div>
-    </div>
-  </div>
-</template>
-
-<script setup>
-  import { ref } from 'vue'
-
-  let showDialog = ref(false)
-  const closeDialog = () => {
-    showDialog.value = false
-  }
-  const submit = () => {
-    showDialog.value = false
-  }
-</script>
-
-<style scoped lang="scss">
-.edit-dialog {
-  width: 100vw;
-  height: 100vh;
-  display: flex;
-  align-items: center;
-  justify-content: center;
-  z-index: 3;
-  .edit {
-    width: 284px;
-    background-color: var(--c-side-bg);
-    padding: 16px 16px 40px;
-    box-shadow: 0px 4px 32px 0px #8195C852;
-    .close {
-      text-align: right;
-      font-size: 0;
-      svg {
-        width: 12px;
-        height: 12px;
-        cursor: pointer;
-      }
-    }
-    .warning {
-      margin-top: 12px;
-      text-align: center;
-      font-size: 0;
-    }
-    .title {
-      margin-top: 16px;
-      font-size: 16px;
-      font-weight: 700;
-      line-height: 24px;
-      color: var(--c-right-side-header-text);
-      text-align: center;
-    }
-    .des {
-      margin-top: 8px;
-      font-size: 14px;
-      line-height: 16px;
-      color: var(--c-edit-text);
-      text-align: center;
-    }
-    .button {
-      width: 220px;
-      margin: 0 auto;
-      margin-top: 24px;
-      line-height: 40px;
-      border-radius: 4px;
-      background: var(--c-header-text-theme-active);
-      font-size: 14px;
-      font-weight: 700;
-      color: #FFFFFF;
-      cursor: pointer;
-      &:hover {
-        background-color: rgba(20, 96, 243, 0.8);
-      }
-    }
-  }
-}
-</style>

+ 1 - 0
packages/webview/src/components/EditToolbar/EditToolBar.vue

@@ -52,6 +52,7 @@
     width: 120px;
     width: 120px;
     display: flex;
     display: flex;
     align-items: center;
     align-items: center;
+    font-family: Helvetica;
     font-size: 12px;
     font-size: 12px;
     font-weight: 400;
     font-weight: 400;
     line-height: 16px;
     line-height: 16px;

+ 1 - 0
packages/webview/src/components/LeftPanel/LeftPanelTabs.vue

@@ -31,6 +31,7 @@
   </Button>
   </Button>
   <Button
   <Button
     :className="activePanelTab === 'LAYER' ? 'active' : ''"
     :className="activePanelTab === 'LAYER' ? 'active' : ''"
+    v-if="activeLeftPanel && activePanelTab === 'LAYER'"
     img="icon-view-layers"
     img="icon-view-layers"
     :title="$t('leftPanel.layers')"
     :title="$t('leftPanel.layers')"
     dataElement="Layers"
     dataElement="Layers"

+ 1 - 1
packages/webview/src/components/RightPanel/RightPanel.vue

@@ -420,7 +420,7 @@
         Value: editItem.value,
         Value: editItem.value,
         String: editItem.value
         String: editItem.value
       })
       })
-    }
+    } else return
     selectedItemIndex.value = null
     selectedItemIndex.value = null
     useDocument.setPropertyPanel({'item': editItem.value})
     useDocument.setPropertyPanel({'item': editItem.value})
     editItem.value = ''
     editItem.value = ''

+ 2 - 1
packages/webview/src/main.js

@@ -8,11 +8,12 @@ import { setupStore } from '@/stores'
 
 
 import './assets/main.scss'
 import './assets/main.scss'
 
 
+const language = window.localStorage.getItem('language') || window.navigator.language
 
 
 const i18n = createI18n({
 const i18n = createI18n({
   // something vue-i18n options here ...
   // something vue-i18n options here ...
   legacy: false,
   legacy: false,
-  locale: 'zh-CN',
+  locale: language === 'zh-CN' ? 'zh-CN' : 'en',
   fallbackLocale: 'en',
   fallbackLocale: 'en',
   messages: {
   messages: {
     en,
     en,