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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<template>
  <a-spin :spinning="spinning" style="height: 100%">
    <!--<template v-if="currentDocumentInfo.docSuffix==='pdf'">-->
    <!--<iframe :src="pdfUrl" frameborder="0"-->
    <!--style="width: 100%;height: calc(100% - 5px)"></iframe>-->
    <!--</template>-->
 
    <template>
      <textarea id="ncFileInfo" style="resize:none;width:100%;height: 100%"></textarea>
    </template>
  </a-spin>
</template>
 
<script>
  import dncApi from '@/api/dnc'
 
  export default {
    name: 'FilePreview',
    components: {},
    props: {
      currentDocumentInfo: {
        type: Object
      }
    },
    data() {
      return {
        spinning: false,
        pdfUrl: ''
      }
    },
    methods: {
      getFilePreviewByApi() {
        const { docId, docSuffix } = this.currentDocumentInfo
        console.log('currentDocumentInfo', this.currentDocumentInfo)
        // if (docSuffix !== 'pdf') {
        //   document.getElementById('ncFileInfo').innerHTML = ''
        //   dncApi.getFilePreviewApi(docId)
        //     .then(res => {
        //       console.log('res----------------------------', res)
        //       if (res.success && res.list) {
        //         let str = ''
        //         res.list.forEach((val, k) => {
        //           str += val
        //           if (k != res.list.length - 1) {
        //             str += '\n'
        //           }
        //         })
        //         document.getElementById('ncFileInfo').innerHTML = str
        //       } else {
        //         this.$notification.error({
        //           message: '消息',
        //           description: res.message
        //         })
        //       }
        //     })
        // } else {
        //   dncApi.getPdfFilePreviewApi(docId)
        //     .then(res => {
        //       let url = window.URL.createObjectURL(new Blob([res], { type: 'application/zip' }))
        //       this.pdfUrl = './static/pdf/web/viewer.html?file=' + encodeURIComponent(url)
        //       console.log('url===========================', url)
        //       console.log('pdfUrl===========================', this.pdfUrl)
        //     })
        // }
        this.spinning = true
        document.getElementById('ncFileInfo').innerHTML = ''
        dncApi.getFilePreviewApi(docId)
          .then(res => {
            console.log('res----------------------------', res)
            if (res.success && res.list) {
              let str = ''
              res.list.forEach((val, k) => {
                str += val
                if (k != res.list.length - 1) {
                  str += '\n'
                }
              })
              document.getElementById('ncFileInfo').innerHTML = str
            } else {
              this.$notification.error({
                message: '消息',
                description: res.message
              })
            }
          })
          .finally(() => {
            this.spinning = false
          })
      },
    }
  }
</script>
 
<style scoped>
  /deep/ .ant-spin-container {
    height: 100%;
  }
</style>