소스 검색

add: UI 新增 closeDocument API

liutian 2 달 전
부모
커밋
6ce7639e57

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

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

@@ -49,7 +49,7 @@
   <PreventDialog />
   <MeasurePop />
   <div v-if="loading && loadingPercent < 100" class="loading-state">{{ $t('loading') }}...</div>
-  <div v-show="!load && loadingPercent <= 0 && activePanelTab !== 'COMPARISON' && ['compare', 'view'].includes(toolMode)" class="upload-container">
+  <div v-show="!load && loadingPercent <= 0 && showUploadButton && activePanelTab !== 'COMPARISON' && ['compare', 'view'].includes(toolMode)" class="upload-container">
     <input id="fileInput" type="file" accept=".pdf" @change="handleUpload" />
     <label for="fileInput">{{ $t('upload') }}</label>
   </div>
@@ -85,6 +85,7 @@ const topSpace = computed(() => {
 })
 const loading = computed(() => useViewer.getUploadLoading && useViewer.getUpload)
 const activePanelTab = computed(() => useViewer.getActiveElementTab('leftPanelTab'))
+const showUploadButton = computed(() => useViewer.getShowUploadButton)
 const load = computed(() => useViewer.getUpload)
 
 async function handleUpload(evt) {
@@ -173,6 +174,9 @@ window.instance.initOptions = async (options) => {
   // const res = await initConfig({
   //   license: 'NjY0ZGE0N2ZhYTBiZQ=='
   // })
+  if (showUploadButton in options) {
+    useViewer.setShowUploadButton(options.showUploadButton)
+  }
   const webviewerMode = !!(options && options.webviewerServer) ? options.webviewerServer : 'Standalone'
   useViewer.setWebviewerMode(webviewerMode)
   if (!res) return
@@ -261,6 +265,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,
 }

+ 10 - 3
packages/webview/src/stores/modules/viewer.js

@@ -350,7 +350,8 @@ export const useViewerStore = defineStore({
     upload: true, // 未上传文件的upload按钮
     uploadLoading: false, // 上传中的loading效果
     compareMode: 'content',
-    contentEditorType: 'text'
+    contentEditorType: 'text',
+    showUploadButton: true,
   }),
   getters: {
     getLanguage () {
@@ -445,7 +446,10 @@ export const useViewerStore = defineStore({
     },
     getContentEditorType () {
       return this.contentEditorType
-    }
+    },
+    getShowUploadButton () {
+      return this.showUploadButton
+    },
   },
   actions: {
     resetSetting () {
@@ -609,6 +613,9 @@ export const useViewerStore = defineStore({
     },
     setContentEditorType (type) {
       this.contentEditorType = type
-    }
+    },
+    setShowUploadButton (bool) {
+      this.showUploadButton = bool
+    },
   }
 })