✨新增pdf预览器
This commit is contained in:
parent
465f7e942e
commit
44d615df2c
@ -3156,7 +3156,7 @@ export default {
|
|||||||
this.openCompressionVisible = true
|
this.openCompressionVisible = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (row.contentType.indexOf('office') > -1 || row.suffix === 'csv') {
|
if (row.contentType.indexOf('office') > -1 || row.suffix === 'csv' || row.suffix === 'pdf') {
|
||||||
// office文件
|
// office文件
|
||||||
this.officePreviewVisible = true
|
this.officePreviewVisible = true
|
||||||
this.officePreviewRow = row
|
this.officePreviewRow = row
|
||||||
@ -3165,7 +3165,6 @@ export default {
|
|||||||
if (row.suffix === 'pdf') {
|
if (row.suffix === 'pdf') {
|
||||||
// pdf文件
|
// pdf文件
|
||||||
fileConfig.preview(this.$store.state.user.name, row, this.$store.getters.token)
|
fileConfig.preview(this.$store.state.user.name, row, this.$store.getters.token)
|
||||||
this.closeNotPreviewDialogVisible()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.notPreviewDialogVisible = true
|
this.notPreviewDialogVisible = true
|
||||||
|
|||||||
@ -21,6 +21,10 @@ export default {
|
|||||||
return "office_" + Math.round(Math.random() * 10000)
|
return "office_" + Math.round(Math.random() * 10000)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
fileUrl: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
code: {
|
code: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: ''
|
||||||
@ -111,17 +115,13 @@ export default {
|
|||||||
}
|
}
|
||||||
let fileKey = `${new Date(this.file.updateDate).getTime()}-${this.file.id}`
|
let fileKey = `${new Date(this.file.updateDate).getTime()}-${this.file.id}`
|
||||||
|
|
||||||
let url = window.location.origin + fileConfig.previewUrl(this.$store.state.user.name, this.file, this.$store.getters.token)
|
|
||||||
if(this.readOnly){
|
|
||||||
url = window.location.origin + fileConfig.publicPreviewUrl(this.file.id, window.shareId);
|
|
||||||
}
|
|
||||||
let callbackUrl = fileConfig.officeCallBackUrl(this.$store.getters.token, this.file.id)
|
let callbackUrl = fileConfig.officeCallBackUrl(this.$store.getters.token, this.file.id)
|
||||||
const config = {
|
const config = {
|
||||||
"document": {
|
"document": {
|
||||||
"fileType": this.fileType,
|
"fileType": this.fileType,
|
||||||
"key": fileKey,
|
"key": fileKey,
|
||||||
"title": this.file.name,
|
"title": this.file.name,
|
||||||
"url": url,
|
"url": this.fileUrl,
|
||||||
},
|
},
|
||||||
"editorConfig": {
|
"editorConfig": {
|
||||||
"mode": "edit",
|
"mode": "edit",
|
||||||
|
|||||||
74
src/components/office/PdfPreview.vue
Normal file
74
src/components/office/PdfPreview.vue
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<template>
|
||||||
|
<di>
|
||||||
|
<div class="pdf-office">
|
||||||
|
<iframe ref="pdfIframe" :title="file.name" :src="fileUrl" width="100%" height="100%" align="top" frameborder="0"
|
||||||
|
name="PDF Preview"></iframe>
|
||||||
|
</div>
|
||||||
|
</di>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "PdfPreview",
|
||||||
|
props: {
|
||||||
|
id: {
|
||||||
|
type: String,
|
||||||
|
default: () => {
|
||||||
|
return "office_" + Math.round(Math.random() * 10000)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fileUrl: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
file: {
|
||||||
|
type: Object,
|
||||||
|
default: function () {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.iframeLoad();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
iframeLoad() {
|
||||||
|
console.log('loading')
|
||||||
|
const iframe = this.$refs.pdfIframe;
|
||||||
|
if (iframe.attachEvent) {
|
||||||
|
// IE
|
||||||
|
iframe.attachEvent('onload', () => {
|
||||||
|
this.$emit('onReady')
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 非IE
|
||||||
|
iframe.onload = () => {
|
||||||
|
this.$emit('onReady')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.pdf-office {
|
||||||
|
position: absolute;
|
||||||
|
top: 2.5rem;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
display: -webkit-box;
|
||||||
|
display: -ms-flexbox;
|
||||||
|
display: flex;
|
||||||
|
-webkit-box-align: center;
|
||||||
|
-ms-flex-align: center;
|
||||||
|
align-items: center;
|
||||||
|
-webkit-box-pack: center;
|
||||||
|
-ms-flex-pack: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -16,7 +16,8 @@
|
|||||||
<svg-icon class="preview-close" icon-class="close"/>
|
<svg-icon class="preview-close" icon-class="close"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<only-office-editor ref="officeEditor" :file="file" :read-only="readOnly" @onEdit="onEdit" @manualSave="manualSave" @onClose="close" @onReady="onReady"></only-office-editor>
|
<pdf-preview v-if="fileType === 'pdf'" :file="file" :file-url="fileUrl" @onReady="onReady"></pdf-preview>
|
||||||
|
<only-office-editor ref="officeEditor" v-else :file="file" :file-url="fileUrl" :read-only="readOnly" @onEdit="onEdit" @manualSave="manualSave" @onClose="close" @onReady="onReady"></only-office-editor>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -28,10 +29,12 @@
|
|||||||
import OnlyOfficeEditor from "@/components/office/OnlyOfficeEditor";
|
import OnlyOfficeEditor from "@/components/office/OnlyOfficeEditor";
|
||||||
import MessageDialog from "@/components/message/MessageDialog";
|
import MessageDialog from "@/components/message/MessageDialog";
|
||||||
import Bus from "@/assets/js/bus";
|
import Bus from "@/assets/js/bus";
|
||||||
|
import fileConfig from "@/utils/file-config";
|
||||||
|
import PdfPreview from "@/components/office/PdfPreview";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'OfficePreview',
|
name: 'OfficePreview',
|
||||||
components: {MessageDialog, OnlyOfficeEditor},
|
components: {PdfPreview, MessageDialog, OnlyOfficeEditor},
|
||||||
props: {
|
props: {
|
||||||
id: {
|
id: {
|
||||||
type: String,
|
type: String,
|
||||||
@ -56,6 +59,7 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
fileUrl: '',
|
||||||
pc: this.$pc,
|
pc: this.$pc,
|
||||||
show: this.status,
|
show: this.status,
|
||||||
readyShow: false,
|
readyShow: false,
|
||||||
@ -63,8 +67,14 @@ export default {
|
|||||||
isSaveDialogVisible: false,
|
isSaveDialogVisible: false,
|
||||||
saved: true,
|
saved: true,
|
||||||
previewDocument: {},
|
previewDocument: {},
|
||||||
|
delayClosing: {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
fileType() {
|
||||||
|
return this.getType(this.file.suffix)
|
||||||
|
},
|
||||||
|
},
|
||||||
watch: {
|
watch: {
|
||||||
status: function(visible){
|
status: function(visible){
|
||||||
if(visible){
|
if(visible){
|
||||||
@ -73,9 +83,12 @@ export default {
|
|||||||
this.previewDocument = document.querySelector('.preview-block')
|
this.previewDocument = document.querySelector('.preview-block')
|
||||||
})
|
})
|
||||||
this.checkReadOnly(this.file.userId)
|
this.checkReadOnly(this.file.userId)
|
||||||
|
if (this.file.suffix === 'pdf') {
|
||||||
|
this.readyShow = true
|
||||||
|
}
|
||||||
// 3秒后还没加载出来视为加载失败
|
// 3秒后还没加载出来视为加载失败
|
||||||
let that = this
|
let that = this
|
||||||
setTimeout(function () {
|
this.delayClosing = setTimeout(function () {
|
||||||
if (!that.readyShow) {
|
if (!that.readyShow) {
|
||||||
that.readyShow = true
|
that.readyShow = true
|
||||||
Bus.$emit('loadFileFaild')
|
Bus.$emit('loadFileFaild')
|
||||||
@ -85,6 +98,14 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
getType(suffix) {
|
||||||
|
switch (suffix) {
|
||||||
|
case 'pdf':
|
||||||
|
return 'pdf'
|
||||||
|
default:
|
||||||
|
return 'office'
|
||||||
|
}
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* 点击关闭按钮
|
* 点击关闭按钮
|
||||||
*/
|
*/
|
||||||
@ -99,6 +120,7 @@ export default {
|
|||||||
* 执行关闭预览窗口
|
* 执行关闭预览窗口
|
||||||
*/
|
*/
|
||||||
close() {
|
close() {
|
||||||
|
clearTimeout(this.delayClosing)
|
||||||
this.show = false
|
this.show = false
|
||||||
this.readyShow = false
|
this.readyShow = false
|
||||||
this.$emit('update:status', false)
|
this.$emit('update:status', false)
|
||||||
@ -108,14 +130,16 @@ export default {
|
|||||||
*/
|
*/
|
||||||
onReady() {
|
onReady() {
|
||||||
this.saved = true
|
this.saved = true
|
||||||
this.previewDocument.style.zIndex = 9999
|
if (this.fileType === 'office') {
|
||||||
this.readyShow = true
|
this.previewDocument.style.zIndex = 9999
|
||||||
this.$nextTick(() => {
|
this.readyShow = true
|
||||||
let that = this
|
this.$nextTick(() => {
|
||||||
setTimeout(function () {
|
let that = this
|
||||||
that.previewDocument.style.zIndex = 2001
|
setTimeout(function () {
|
||||||
},200)
|
that.previewDocument.style.zIndex = 2001
|
||||||
})
|
},200)
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 编辑回调
|
* 编辑回调
|
||||||
@ -171,6 +195,10 @@ export default {
|
|||||||
closeBar.style.transform = 'rotate(225deg)'
|
closeBar.style.transform = 'rotate(225deg)'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
this.fileUrl = window.location.origin + fileConfig.previewUrl(this.$store.state.user.name, this.file, this.$store.getters.token)
|
||||||
|
if(this.readOnly){
|
||||||
|
this.fileUrl = window.location.origin + fileConfig.publicPreviewUrl(this.file.id, window.shareId);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user