Blame view

antis-ncc-admin/src/views/extend/documentPreview/Detail.vue 1.26 KB
03207d5d   wwk   1
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
  <template>
    <transition name="el-zoom-in-center">
      <div class="NCC-preview-main">
        <div class="NCC-common-page-header">
          <el-page-header @back="goBack" :content="title" />
          <div class="options">
            <el-button @click="goBack()">{{$t('common.cancelButton')}}</el-button>
          </div>
        </div>
        <iframe width="100%" height="100%" :src="url" frameborder="0"></iframe>
      </div>
    </transition>
  </template>
  
  <script>
  import { filePreviewServer } from '@/utils/define'
  import { PreviewFile } from '@/api/extend/documentPreview'
  export default {
    data() {
      return {
        title: '',
        url: ''
      }
    },
    methods: {
      goBack() {
        this.$emit('close')
      },
      init(id, name, type) {
        let Base64 = require('js-base64').Base64;
        this.url = ''
        if (!id) return this.goBack()
        this.title = '文档预览 - ' + name
        PreviewFile(id, type).then(res => {
          if (res.data) {
            if( type === 'localPreview') {
              this.url = `${filePreviewServer}/onlinePreview?url=`+encodeURIComponent(Base64.encode(res.data))
              return
            }
            this.url = res.data
          } else {
            this.$message.warning('文件不存在')
            this.goBack()
          }
        })
      }
    }
  }
  </script>