perf:pdf预览器
This commit is contained in:
parent
44d615df2c
commit
f233143d50
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "jmal-cloud-view",
|
"name": "jmal-cloud-view",
|
||||||
"version": "2.2.40",
|
"version": "2.2.41",
|
||||||
"description": "jmalcloud",
|
"description": "jmalcloud",
|
||||||
"author": "Jmal <zhushilun084@163.com>",
|
"author": "Jmal <zhushilun084@163.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@ -3162,11 +3162,6 @@ export default {
|
|||||||
this.officePreviewRow = row
|
this.officePreviewRow = row
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (row.suffix === 'pdf') {
|
|
||||||
// pdf文件
|
|
||||||
fileConfig.preview(this.$store.state.user.name, row, this.$store.getters.token)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.notPreviewDialogVisible = true
|
this.notPreviewDialogVisible = true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<di>
|
<div>
|
||||||
<div class="pdf-office">
|
<div class="pdf-office">
|
||||||
<iframe ref="pdfIframe" :title="file.name" :src="fileUrl" width="100%" height="100%" align="top" frameborder="0"
|
<iframe ref="pdfIframe" name="PDF Preview" :title="file.name" :src="fileUrl"></iframe>
|
||||||
name="PDF Preview"></iframe>
|
|
||||||
</div>
|
</div>
|
||||||
</di>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -37,17 +36,17 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
iframeLoad() {
|
iframeLoad() {
|
||||||
console.log('loading')
|
|
||||||
const iframe = this.$refs.pdfIframe;
|
const iframe = this.$refs.pdfIframe;
|
||||||
|
const that = this
|
||||||
if (iframe.attachEvent) {
|
if (iframe.attachEvent) {
|
||||||
// IE
|
// IE
|
||||||
iframe.attachEvent('onload', () => {
|
iframe.attachEvent('onload', () => {
|
||||||
this.$emit('onReady')
|
that.$emit('onReady')
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 非IE
|
// 非IE
|
||||||
iframe.onload = () => {
|
iframe.onload = () => {
|
||||||
this.$emit('onReady')
|
that.$emit('onReady')
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,5 +69,10 @@ export default {
|
|||||||
-webkit-box-pack: center;
|
-webkit-box-pack: center;
|
||||||
-ms-flex-pack: center;
|
-ms-flex-pack: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
iframe {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -75,6 +75,17 @@ export default {
|
|||||||
return this.getType(this.file.suffix)
|
return this.getType(this.file.suffix)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
mounted() {
|
||||||
|
let that = this;
|
||||||
|
this.$nextTick(function () {
|
||||||
|
document.addEventListener('keyup', function (e) {
|
||||||
|
// 监听ESC键
|
||||||
|
if (e.code === 'Escape') {
|
||||||
|
that.beforeClose()
|
||||||
|
}
|
||||||
|
}, false)
|
||||||
|
})
|
||||||
|
},
|
||||||
watch: {
|
watch: {
|
||||||
status: function(visible){
|
status: function(visible){
|
||||||
if(visible){
|
if(visible){
|
||||||
@ -83,9 +94,6 @@ 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
|
||||||
this.delayClosing = setTimeout(function () {
|
this.delayClosing = setTimeout(function () {
|
||||||
@ -129,10 +137,11 @@ export default {
|
|||||||
* 文件内容已经加载好了
|
* 文件内容已经加载好了
|
||||||
*/
|
*/
|
||||||
onReady() {
|
onReady() {
|
||||||
|
console.log('onReady')
|
||||||
this.saved = true
|
this.saved = true
|
||||||
|
this.readyShow = true
|
||||||
if (this.fileType === 'office') {
|
if (this.fileType === 'office') {
|
||||||
this.previewDocument.style.zIndex = 9999
|
this.previewDocument.style.zIndex = 9999
|
||||||
this.readyShow = true
|
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
let that = this
|
let that = this
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
@ -146,7 +155,6 @@ export default {
|
|||||||
* @param saved 是否已经保存
|
* @param saved 是否已经保存
|
||||||
*/
|
*/
|
||||||
onEdit(saved) {
|
onEdit(saved) {
|
||||||
console.log('onEdit', saved)
|
|
||||||
this.saved = saved
|
this.saved = saved
|
||||||
if(saved){
|
if(saved){
|
||||||
window.onbeforeunload = function(e){
|
window.onbeforeunload = function(e){
|
||||||
@ -168,7 +176,6 @@ export default {
|
|||||||
*/
|
*/
|
||||||
saveAndClose() {
|
saveAndClose() {
|
||||||
// 通知插件保存
|
// 通知插件保存
|
||||||
console.log('saveAndClose')
|
|
||||||
Bus.$emit('previewSaveAndClose')
|
Bus.$emit('previewSaveAndClose')
|
||||||
this.isSaveDialogVisible = false
|
this.isSaveDialogVisible = false
|
||||||
},
|
},
|
||||||
@ -186,7 +193,7 @@ export default {
|
|||||||
if(this.$store.state.user.token && this.$store.state.user.userId === fileUserId){
|
if(this.$store.state.user.token && this.$store.state.user.userId === fileUserId){
|
||||||
this.readOnly = false
|
this.readOnly = false
|
||||||
}
|
}
|
||||||
if (!this.$pc) {
|
if (!this.$pc && this.fileType === 'office') {
|
||||||
this.readOnly = true
|
this.readOnly = true
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
const closeBar = document.querySelector('.office-preview .close-bar');
|
const closeBar = document.querySelector('.office-preview .close-bar');
|
||||||
|
|||||||
@ -17,16 +17,11 @@ export default {
|
|||||||
},
|
},
|
||||||
// 预览文件的url
|
// 预览文件的url
|
||||||
previewUrl: function(username, file, token) {
|
previewUrl: function(username, file, token) {
|
||||||
let path = "/"
|
let fileUrl = `${this.baseUrl}/file/${username}${encodeURI(file.path)}${encodeURI(file.name)}`
|
||||||
if (file.path.length > 1) {
|
|
||||||
path = encodeURI(file.path.substr(1, file.path.length - 2))
|
|
||||||
}
|
|
||||||
const filename = encodeURI(file.name);
|
|
||||||
if (token) {
|
if (token) {
|
||||||
return `${this.baseUrl}/file/${username}/${path}/${filename}?jmal-token=${token}`
|
return `${fileUrl}?jmal-token=${token}`
|
||||||
} else {
|
|
||||||
return `${this.baseUrl}/file/${username}/${path}/${filename}`
|
|
||||||
}
|
}
|
||||||
|
return fileUrl
|
||||||
},
|
},
|
||||||
// mardown里上传图片后的图片预览地址
|
// mardown里上传图片后的图片预览地址
|
||||||
mardownPreviewUrl: function (path){
|
mardownPreviewUrl: function (path){
|
||||||
@ -40,7 +35,7 @@ export default {
|
|||||||
// 下载文件
|
// 下载文件
|
||||||
download: function(username, file, token) {
|
download: function(username, file, token) {
|
||||||
fileApi.isAllowDownload().then(() => {
|
fileApi.isAllowDownload().then(() => {
|
||||||
let url = `${this.baseUrl}/file/${username}${encodeURI(file.path)}${encodeURI(file.name)}?jmal-token=${token}&o=download`
|
let url = this.previewUrl(username, file, token) + '&o=download'
|
||||||
window.open(url, '_self')
|
window.open(url, '_self')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user