|
@@ -1,35 +1,12 @@
|
|
|
<template>
|
|
|
<span @click.stop="preView(info)">
|
|
|
<a-icon type="file-search" />
|
|
|
- <slot/>
|
|
|
- <a-modal
|
|
|
- v-model="previewVisible"
|
|
|
- :title="$t('doc.Preview')"
|
|
|
- :width="850"
|
|
|
- :maskClosable="false"
|
|
|
- :okButtonProps="{ style: { display: 'none' } }"
|
|
|
- :cancelButtonProps="{ style: { display: 'none' } }"
|
|
|
- >
|
|
|
- <img :src="previewSrc" alt="" style="width: 100%" v-if="previewType === 'img'" />
|
|
|
- <video controls :src="previewSrc" width="100%" v-if="previewType === 'mp4'"></video>
|
|
|
- <VueOfficeDocx :src="previewSrc" style="height: 100vh" v-if="previewType === 'docx'" />
|
|
|
- <VueOfficeExcel
|
|
|
- :src="previewSrc"
|
|
|
- :options="xlslOptions"
|
|
|
- style="height: 100vh"
|
|
|
- v-if="previewType === 'xlsx' || previewType === 'xls'"
|
|
|
- />
|
|
|
- <iframe :src="previewSrc" width="100%" height="800px" frameborder="1" v-if="previewType === 'pdf'"></iframe>
|
|
|
- </a-modal>
|
|
|
+ <slot />
|
|
|
</span>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import { fileBimView } from '@/api/document/index.js'
|
|
|
-import VueOfficeDocx from '@vue-office/docx'
|
|
|
-import VueOfficeExcel from '@vue-office/excel'
|
|
|
-import '@vue-office/docx/lib/index.css'
|
|
|
-import '@vue-office/excel/lib/index.css'
|
|
|
|
|
|
export default {
|
|
|
name: 'previewFile',
|
|
@@ -38,55 +15,29 @@ export default {
|
|
|
type: Object,
|
|
|
},
|
|
|
},
|
|
|
- components: {
|
|
|
- VueOfficeDocx,
|
|
|
- VueOfficeExcel,
|
|
|
- },
|
|
|
data() {
|
|
|
- return {
|
|
|
- previewVisible: false,
|
|
|
- previewSrc: '',
|
|
|
- previewType: null,
|
|
|
- xlslOptions: {
|
|
|
- xls: false, //预览xlsx文件设为false;预览xls文件设为true
|
|
|
- minColLength: 0,
|
|
|
- minRowLength: 0,
|
|
|
- widthOffset: 10,
|
|
|
- heightOffset: 10,
|
|
|
- },
|
|
|
- }
|
|
|
+ return {}
|
|
|
},
|
|
|
- created() {},
|
|
|
methods: {
|
|
|
async preView(record) {
|
|
|
- if (record.extension === 'pdf' || record.extension === 'docx' || record.extension === 'mp4') {
|
|
|
- this.previewClick(record.download_url, record.extension)
|
|
|
- } else if (['jpg', 'png', 'gif', 'jpeg'].includes(record.extension)) {
|
|
|
- this.previewClick(record.download_url, 'img')
|
|
|
- } else if (record.extension === 'xlsx' || record.extension === 'xls') {
|
|
|
- this.xlslOptions.xls = record.extension === 'xlsx' ? false : true
|
|
|
- this.previewClick(record.download_url, record.extension)
|
|
|
+ if (record.extension === 'pdf') {
|
|
|
+ window.open(record.download_url)
|
|
|
} else if (record.model_preview) {
|
|
|
let {
|
|
|
data: { bim_view },
|
|
|
} = await fileBimView(record.id)
|
|
|
localStorage.setItem(bim_view.lightweightName, JSON.stringify([bim_view]))
|
|
|
window.open(`/modelView?id=${bim_view.lightweightName}`, '_blank')
|
|
|
- }
|
|
|
- },
|
|
|
- previewClick(val, type) {
|
|
|
- if (type === 'pdf') {
|
|
|
- const a = document.createElement('a')
|
|
|
- a.href = val
|
|
|
- a.target = '_blank'
|
|
|
- a.style.display = 'none'
|
|
|
- document.body.appendChild(a)
|
|
|
- a.click() // 点击下载
|
|
|
- document.body.removeChild(a) // 下载完成移除元素
|
|
|
} else {
|
|
|
- this.previewSrc = val
|
|
|
- this.previewVisible = true
|
|
|
- this.previewType = type
|
|
|
+ const { href } = this.$router.resolve({
|
|
|
+ path: '/Preview',
|
|
|
+ query: {
|
|
|
+ id: record.id,
|
|
|
+ extension: record.extension,
|
|
|
+ download_url: record.download_url,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ window.open(href, '_blank')
|
|
|
}
|
|
|
},
|
|
|
},
|