wwf
16 小时以前 e1b028d486713eaf55aaf35fbf334aa568059c0d
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
99
100
<template>
  <div>
    <el-row align="middle" justify="center" @click="previewFile(index)" class="cursor-p">
      <slot>
        <el-row style="flex-wrap: nowrap;">
          <Icon class="mr-1" icon="uis:paperclip" width="20" height="18"  style="color:#007AFF;flex-shrink: 0;" />
          <span style="color:#007AFF">{{ name }}</span>
        </el-row>
      </slot>
    </el-row>
    <div>
      
    </div>
    <ElImageViewer
      v-if="showImageViewer"
      :url-list="filterPreviewImgList"
      :initial-index="initialPreviewImgIndex"
      teleported
      @close="showImageViewer=false"
    >
    </ElImageViewer>
 
    <el-dialog 
      v-model="pdfPreviewFlag" 
      top="5vh"
      :append-to-body="true"
    >
      <div style="height: 84vh;">
        <PdfPreview v-if="previewUrl&&pdfPreviewFlag" :url="previewUrl"></PdfPreview>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import { getFileUrlType } from '@/utils/tool.js'
import PdfPreview from '@/views/components/PdfPreview.vue'
 
export default {
  components: {
    PdfPreview
  },
  data() {
    return {
      initialPreviewImgIndex: 0,
      showImageViewer: false,
      pdfPreviewFlag: false,
      previewUrl: ''
    }
  },
  props: {
    list: {
      type: Array,
      default: () => {
        return []
      }
    },
    name: {
      type: String,
      default: ""
    },
    url: {
      type: String,
      default: ""
    },
    index: {
      type: Number,
      default: 0
    }
  },
  computed: {
    filterPreviewImgList() {
      let list = this.list.map(ele => ele.url?.includes('http') ? ele.url : this.$qxueyou.qxyRes + ele.url )
      return list
    },
  },
  methods: {
    previewFile() {
      const fileObj = this.list[this.index] || {}
      const url = fileObj.url || this.url
      const type = getFileUrlType(url)
      if (type == 'img') {
        this.initialPreviewImgIndex = this.index
        this.showImageViewer = true
      } else if (type == 'pdf') {
        this.pdfPreviewFlag = true
        this.previewUrl = url ?.includes('http') ? url : this.$qxueyou.qxyRes + url
      } else {
        this.$messageBox.confirm('该类型文件暂不支持在线预览,是否下载?', '提示', 
        { confirmButtonText: '确定', cancelButtonText: '取消', type: '' }).then(res => {
          if (res == 'confirm') {
            window.open(url ?.includes('http') ? url : this.$qxueyou.qxyRes + url)
          }
        })
        
      }
    },
  }
}
</script>