|
|
|
|
@ -0,0 +1,85 @@
|
|
|
|
|
<template>
|
|
|
|
|
<div id="online-preview-container" class="container">
|
|
|
|
|
<template v-if="type === 'docx'">
|
|
|
|
|
<VueOfficeDocx :src="url" style="height: 100vh;" />
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else-if="type === 'xlsx' || type === 'xls'">
|
|
|
|
|
<VueOfficeExcel :src="url" style="height: 100vh;" />
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else-if="type === 'pdf'">
|
|
|
|
|
<VueOfficePdf :src="url" style="height: 100vh;" />
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else-if="['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg'].indexOf(type) !== -1">
|
|
|
|
|
<el-image ref="elImage" fit="contain" :preview-src-list="[url]" :src="url" style="width: 100vw;height: 100vh;" alt="" @load="loadImg" />
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else>
|
|
|
|
|
<div>
|
|
|
|
|
<h4>文件类型暂不支持在线预览,请下载查看</h4>
|
|
|
|
|
<el-link target="_blank" type="primary" :href="url">点击下载</el-link>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
// 引入VueOfficeDocx组件
|
|
|
|
|
import VueOfficeDocx from '@vue-office/docx'
|
|
|
|
|
// 引入相关样式
|
|
|
|
|
import '@vue-office/docx/lib/index.css'
|
|
|
|
|
// 引入VueOfficeExcel组件
|
|
|
|
|
import VueOfficeExcel from '@vue-office/excel'
|
|
|
|
|
// 引入相关样式
|
|
|
|
|
import '@vue-office/excel/lib/index.css'
|
|
|
|
|
// 引入VueOfficePdf组件
|
|
|
|
|
import VueOfficePdf from '@vue-office/pdf'
|
|
|
|
|
// import { renderAsync } from 'docx-preview'
|
|
|
|
|
export default {
|
|
|
|
|
components: {
|
|
|
|
|
VueOfficeDocx,
|
|
|
|
|
VueOfficePdf,
|
|
|
|
|
VueOfficeExcel
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
url: '',
|
|
|
|
|
type: ''
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {},
|
|
|
|
|
watch: {
|
|
|
|
|
'$route.query': {
|
|
|
|
|
handler(newVal) {
|
|
|
|
|
this.resolveUrl(newVal.url)
|
|
|
|
|
},
|
|
|
|
|
immediate: true
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
loadImg() {
|
|
|
|
|
this.$refs['elImage']?.$el?.children[0].click()
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
document.querySelector('.el-image-viewer__close').style.display = 'none'
|
|
|
|
|
document.querySelector('.el-image__inner').style.display = 'none'
|
|
|
|
|
document.querySelector('.el-image-viewer__mask').style.pointerEvents = 'none'
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
async resolveUrl(url) {
|
|
|
|
|
if (url) {
|
|
|
|
|
try {
|
|
|
|
|
this.url = window.atob(window.decodeURIComponent(this.$route.query.url ?? ''))
|
|
|
|
|
} catch (err) {
|
|
|
|
|
this.url = window.decodeURIComponent(this.$route.query.url ?? '')
|
|
|
|
|
}
|
|
|
|
|
this.type = this.$route.query.type || this.url.split('.').at(-1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
.container {
|
|
|
|
|
height: 100vh;
|
|
|
|
|
width: 100vw;
|
|
|
|
|
}
|
|
|
|
|
</style>
|