<template>
<div class="videoShow">
<!--doc,excel-->
<div v-if="docShow || excelShow">
<iframe
class="child"
frameborder="0"
:src="
'/pdf/web/viewer.html?file=http://xx.xx.xx:8080/' +
this.downloadUrl
"
:style="{ width: width, height: height }"
>
<!-- 这里pdf文件预览使用了pdfjs插件,因为是移动端系统,ios自带浏览器是可以解析pdf文件的,但是安卓端浏览器是不能解析pdf文件的,具体用法看最下面的pdfjs在vue项目中使用的链接 -->
</iframe>
</div>
<!--视频-->
<div v-else-if="videoShow">
<h4>{{ fileName }}</h4>
<video
preload="auto"
:height="height"
:width="width"
align="center"
controls="true"
>
<source
:src="'http://xx.xx.xx:8080/' + this.downloadUrl"
type="video/mp4"
/>
</video>
</div>
<!--其他不能预览的-->
<div v-else-if="otherShow">
<h5>can't show</h5>
</div>
</div>
</template>
<script>
import 'video.js/dist/video-js.css'
export default {
// props: { file: {} },
data () {
return {
fileName: '',
downloadUrl: '',
docShow: false,
excelShow: false,
videoShow: false,
// 其他不能预览的
otherShow: false,
// height: window.innerHeight + 'px',
height: '200vh',
width: '100%'
}
},
created () {
// 文件名和文件路径是由上一个页面跳转携带参数跳转过来的
this.fileName = this.$route.params.fileName
this.downloadUrl = this.$route.params.fileAddress
if (
this.fileName.endsWith('docx') ||
this.fileName.endsWith('doc') ||
this.fileName.endsWith('pdf') ||
this.fileName.endsWith('pptx') ||
this.fileName.endsWith('ppt') ||
this.fileName.endsWith('txt')
) {
// doc
this.title = '文档预览'
this.docShow = true
} else if (
this.fileName.endsWith('xlsx') ||
this.fileName.endsWith('xls')
// doc
) {
// excel
this.excelShow = true
} else if (this.fileName.endsWith('mp4') || this.fileName.endsWith('mp3')) {
this.title = '视频预览'
this.videoShow = true
} else {
this.otherShow = true
}
},
methods: {},
}
</script>
<style lang="less" scoped>
.child {
width: 100%;
height: 100%;
border: 0;
}
</style>