1、文件预览弹窗组件
<template>
<!-- 公司组件库的弹窗组件,和element的弹窗组件用法一样 -->
<sc-tf-dialog-base
ref="scTfDialog"
class="prod-dialog"
:cancelBtnText="'关闭'"
dialog-name="文件预览"
:fullscreen="magnify"
:height="magnify ? '90vh' : '550px'"
:show-confirm-button="false"
@beforeClose="closeDialog"
>
<template #title>
<div class="file-title">
<div>文件预览</div>
<div>
<sp-icon
:type="magnify ? 'restore' : 'magnify'"
color="#8998AC"
style="margin-right: 10px"
@click.native="magnify = !magnify"
fontSize="25"
></sp-icon>
</div>
</div>
</template>
<!-- iframe嵌入预览文件的网页 -->
<iframe class="prism-player" :src="origin + url" width="100%" height="100%"></iframe>
</sc-tf-dialog-base>
</template>
<script>
export default {
data() {
return {
magnify: false
}
},
props: {
config: {
type: Object,
default: () => ({})
},
url: {
type: String,
default: ''
},
origin: {
type: String,
default:
process.env.NODE_ENV === 'development'
? `${process.env.VUE_APP_PREVIWE_URL}/onlinePreview?url=`
: `http://${window.location.hostname}:${process.env.VUE_APP_PREVIWE_URLNEW}/onlinePreview?url=`
},
close: {
type: Function
}
},
components: {},
created() {
this.$nextTick(() => {
console.log(this.url)
this.$refs['scTfDialog'].showDialog()
})
},
methods: {
closeDialog() {
if (this.close) {
this.close()
}
}
}
}
</script>
<style lang="stylus" scoped>
</style>
2、自定义vue插件挂载调用文件预览功能的方法
import filePreviewPopup from './FilePreviewPopup.vue'
import { Base64 } from 'js-base64'
import Vue from 'vue'
const handleVedioBox = (url) => {
const FileViewerConstructor = Vue.extend(filePreviewPopup)
const instance = new FileViewerConstructor({
url: url
})
instance.url = encodeURIComponent(Base64.encode(url))
document.body.appendChild(instance.$mount().$el)
instance.close = () => {
document.body.removeChild(instance.$mount().$el)
}
}
const install = function (Vue) {
Vue.prototype.$filePreviewPopup = handleVedioBox
}
export default { install }