Эх сурвалжийг харах

[task-1141] 附件预览调整为新标签页显示

cfort 2 жил өмнө
parent
commit
ee7bdf5174

+ 13 - 2
src/components/ibps-file-viewer/index.vue

@@ -135,9 +135,20 @@
                     this.fileUrl = this.url
                     this.fileType = 'image'
                 } else if(flag && pdfType.includes(this.fileExt)){
-                    this.fileType = 'pdf'
+                    // this.fileType = 'pdf'
                     this.$nextTick(() => {
-                        this.$refs.viewer.load(this.url)
+                        // this.$refs.viewer.load(this.url)
+                        const newTab = window.open()
+                        const link = newTab.document.createElement('link')
+                        link.rel = 'shortcut icon'
+                        link.type = 'image/x-icon'
+                        link.href = 'favicon.ico'
+                        // newTab.document.write('<link rel="icon" type="image/x-icon" href="favicon.ico">')
+                        newTab.document.write(`<title>文件预览页-${this.title}</title>`)
+                        newTab.document.write('<style>body { margin: 0px; }</style>')
+                        newTab.document.head.appendChild(link)
+                        newTab.document.write(`<iframe src="${this.$baseUrl}lib/pdfjs-dist/web/viewer.html?file=${encodeURIComponent(this.url)}" style="width:100%; height:100%;" frameborder="0";>`)
+                        this.closeDialog()
                     })
 
                 } else {

+ 27 - 32
src/components/ibps-file-viewer/pdf/index.vue

@@ -1,41 +1,36 @@
 <template>
-  <div
-    class="pdf"
-    :style="{
-      height: height
-    }"
-  >
-    <iframe v-if="pdfUrl" :src="pdfUrl" frameborder="0" style="width: 100%; height: 100%" />
-  </div>
+    <div class="pdf" :style="{height: height}">
+        <iframe v-if="pdfUrl" :src="pdfUrl" frameborder="0" style="width: 100%; height: 100%" />
+    </div>
 </template>
 <script>
 export default {
-  data() {
-    return {
-      pdfUrl: null,
-      height: '450px'
-    }
-  },
-  mounted() {
-    this.height = this.getDialogHeightHeight()
-    window.addEventListener('resize', this.handleDialogHeightResize)
-  },
-  methods: {
-    load(url) {
-      this.pdfUrl = null
-      url = encodeURIComponent(url)
-      this.pdfUrl = `${this.$baseUrl}lib/pdfjs-dist/web/viewer.html?file=${url}`
-    },
-    loadData(data) {
-      this.pdfUrl = null
-      this.pdfUrl = `${this.$baseUrl}lib/pdfjs-dist/web/viewer.html?file=${data}`
+    data () {
+        return {
+            pdfUrl: null,
+            height: '450px'
+        }
     },
-    handleDialogHeightResize() {
-      this.height = this.getDialogHeightHeight()
+    mounted () {
+        this.height = this.getDialogHeightHeight()
+        window.addEventListener('resize', this.handleDialogHeightResize)
     },
-    getDialogHeightHeight() {
-      return ((document.documentElement.clientHeight || document.body.clientHeight) - 60) + 'px'
+    methods: {
+        load (url) {
+            this.pdfUrl = null
+            url = encodeURIComponent(url)
+            this.pdfUrl = `${this.$baseUrl}lib/pdfjs-dist/web/viewer.html?file=${url}&newWindow=true`
+        },
+        loadData (data) {
+            this.pdfUrl = null
+            this.pdfUrl = `${this.$baseUrl}lib/pdfjs-dist/web/viewer.html?file=${data}`
+        },
+        handleDialogHeightResize () {
+            this.height = this.getDialogHeightHeight()
+        },
+        getDialogHeightHeight () {
+            return ((document.documentElement.clientHeight || document.body.clientHeight) - 60) + 'px'
+        }
     }
-  }
 }
 </script>