Pārlūkot izejas kodu

add: UI 新增 closeDocument API

liutian 2 mēneši atpakaļ
vecāks
revīzija
1c74859d0d

+ 4 - 0
packages/core/src/index.js

@@ -644,6 +644,10 @@ class ComPDFKitViewer {
     )
   }
 
+  async closeDocument() {
+    await this.close()
+  }
+
   getSelectedText(pageNumber) {
     if (pageNumber) {
       const page = this.pdfViewer._pages[pageNumber - 1]

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

@@ -261,6 +261,38 @@ window.instances.UI.loadDocument = async (file) => {
   await handlePdf(url, filename)
   useViewer.setUploadLoading(false)
 }
+
+window.instances.UI.closeDocument = async () => {
+  if (isLeftPanelOpen.value) {
+    core.toggleSidebar()
+  }
+  useViewer.$patch({
+    fullMode: false,
+    currentPage: 0,
+    scale: '',
+    themeMode: 'Light',
+    pageMode: 0,
+    scrollMode: 'Vertical',
+    activeTab: 0,
+    searchStatus: false,
+    activeElements: {
+      leftPanel: false,
+      rightPanel: false
+    },
+    activeElementsTab: {
+      leftPanelTab: 'THUMBS',
+      rightPanelTab: 'GENERAL'
+    }
+  })
+  useDocument.resetSetting()
+  core.clearSearchResults()
+  useDocument.setToolState('')
+  useViewer.setActiceToolMode('view')
+
+  useViewer.setUpload(false)
+  useViewer.setUploadLoading(false)
+  await core.closeDocument()
+}
 </script>
 
 <style lang="scss">

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

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

+ 2 - 0
packages/webview/src/core/index.js

@@ -60,6 +60,7 @@ import windowToPage from './windowToPage'
 import addEditorImage from './addEditorImage'
 import flattenPdf from './flattenPdf'
 import setFreetextProperty from './setFreetextProperty'
+import closeDocument from './closeDocument'
 
 export default {
   getDocumentViewer,
@@ -127,4 +128,5 @@ export default {
   addEditorImage,
   flattenPdf,
   setFreetextProperty,
+  closeDocument,
 }