Blame view

ant-design-vue-jeecg/src/views/jeecg/modules/PdfPreviewModal.vue 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<template>
  <div style="display: none">
    <iframe
      :id="id"
      :src="url"
      frameborder="0"
      width="100%"
      height="550px"
      scrolling="auto">
    </iframe>
  </div>
</template>

<script>
  import Vue from 'vue'
  import { ACCESS_TOKEN } from "@/store/mutation-types"

  export default {
    name: "PdfPreviewModal",
    data () {
      return {
        url:  window._CONFIG['pdfDomainURL'],
        id:"pdfPreviewIframe",
        headers:{}
      }
    },
    created () {
      const token = Vue.ls.get(ACCESS_TOKEN);
      this.headers = {"X-Access-Token":token}
    },
    computed:{

    },
    mounted(){
      window.addEventListener('message', this.handleScanFileMessage);
    },
    methods: {
      handleScanFileMessage (event) {
        // 根据上面制定的结构来解析iframe内部发回来的数据
        const data = event.data;
         console.log(data);
      },

      previewFiles (title,token) {
        var iframe = document.getElementById("pdfPreviewIframe");
        var json = {"title":title,"token":token};
        iframe.contentWindow.postMessage(json, "*");
      },

    }
  }
</script>

<style scoped>

</style>