From ee25f1d1f9cafad4f637704b4b82241f8a833fdb Mon Sep 17 00:00:00 2001 From: jmal Date: Sat, 8 Jun 2024 12:59:47 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E9=80=82=E9=85=8D=20onlyoffice=20JWT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/file-api.js | 19 ++++++++++++++- src/components/office/OnlyOfficeEditor.vue | 28 ++++++++++++++++++++-- src/components/preview/OfficePreview.vue | 9 ++++--- src/views/public/share/shareList.vue | 4 +++- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/api/file-api.js b/src/api/file-api.js index bd92775..81e5f8e 100644 --- a/src/api/file-api.js +++ b/src/api/file-api.js @@ -338,5 +338,22 @@ export default { method: 'get', params }) - } + }, + // 获取office jwt + getOfficeJwt: function(data) { + return request({ + url: '/office/signature', + method: 'post', + data + }) + }, + // 获取office jwt + getPublicOfficeJwt: function(params, data) { + return request({ + url: '/public/office/signature', + method: 'post', + params, + data + }) + }, } diff --git a/src/components/office/OnlyOfficeEditor.vue b/src/components/office/OnlyOfficeEditor.vue index d48610c..e02d6c9 100644 --- a/src/components/office/OnlyOfficeEditor.vue +++ b/src/components/office/OnlyOfficeEditor.vue @@ -49,6 +49,10 @@ export default { type: String, default: '' }, + sharer: { + type: String, + default: undefined + }, file: { type: Object, default: function () { @@ -221,11 +225,14 @@ export default { this.$refs.historyPopover.loadHistoryList(this.file.id) }) this.destroyEditor() - this.fileUrl = window.location.origin + fileConfig.previewUrl(this.$store.state.user.name, this.file, this.$store.getters.token) + + const file_username = this.sharer ? this.sharer : this.$store.state.user.name + this.fileUrl = window.location.origin + fileConfig.previewUrl(file_username, this.file, this.$store.getters.token) + this.fileKey = `${new Date(this.file.updateDate).getTime()}-${SparkMD5.hash(this.file.id)}` if (this.readOnly && window.shareId) { this.fileUrl = window.location.origin + fileConfig.publicPreviewUrl(this.file, window.shareId, this.$store.getters.shareToken) + this.fileKey = `${new Date(this.file.updateDate).getTime()}-${SparkMD5.hash(window.shareId)}` } - this.fileKey = `${new Date(this.file.updateDate).getTime()}-${SparkMD5.hash(this.file.id)}` let callbackUrl = fileConfig.officeCallBackUrl(this.$store.getters.token, this.$store.getters.name, this.file.id) @@ -261,6 +268,22 @@ export default { callbackUrl: callbackUrl, } } + + if (this.readOnly && window.shareId) { + const shareToken = this.$store.getters.shareToken ? this.$store.getters.shareToken : 'token' + this.docEditorConfig.editorConfig.callbackUrl = null + api.getPublicOfficeJwt({shareId: window.shareId, shareToken: shareToken}, this.docEditorConfig).then(res => { + this.loadOffice(res.data) + }) + } else { + api.getOfficeJwt(this.docEditorConfig).then(res => { + this.loadOffice(res.data) + }) + } + + }, + loadOffice(token) { + this.docEditorConfig.token = token if (!this.$pc) { this.docEditorConfig.type = 'mobile' } @@ -277,6 +300,7 @@ export default { this.docEditorConfig.editorConfig.user.name = "Visitor_" + visitor } } + this.docEditorConfig.events = { "onAppReady": this.onAppReady, "onDocumentReady": this.onDocumentReady, diff --git a/src/components/preview/OfficePreview.vue b/src/components/preview/OfficePreview.vue index 6dcc55d..7e22b90 100644 --- a/src/components/preview/OfficePreview.vue +++ b/src/components/preview/OfficePreview.vue @@ -19,7 +19,7 @@ - + @@ -30,7 +30,6 @@ import OnlyOfficeEditor from "@/components/office/OnlyOfficeEditor"; import MessageDialog from "@/components/message/MessageDialog"; -import Bus from "@/assets/js/bus"; import fileConfig from "@/utils/file-config"; import PdfPreview from "@/components/office/PdfPreview"; import Drawio from "@/components/office/Drawio"; @@ -56,6 +55,10 @@ export default { type: String, default: undefined }, + sharer: { + type: String, + default: undefined + }, status: { type: Boolean, default: false @@ -207,7 +210,7 @@ export default { this.$message.info('请手动保存') }, /** - * 检查要预览调文件是否为只读 + * 检查要预览的文件是否为只读 * @param file userId */ checkReadOnly(file){ diff --git a/src/views/public/share/shareList.vue b/src/views/public/share/shareList.vue index f708f7c..7bf5f68 100644 --- a/src/views/public/share/shareList.vue +++ b/src/views/public/share/shareList.vue @@ -255,7 +255,7 @@ - +  {{ summaries }} @@ -418,6 +418,7 @@ export default { showUpdateDateItem: this.$pc,// 列表模式下是否显示修改时间 showSizeItem: this.$pc,// 列表模式下是否显示文件大小 sharer: undefined,//分享者信息, + sharerUsername: undefined, loginTitle: '', sharerAvatarUrl: '', netdiskName: 'JmalCloud', @@ -698,6 +699,7 @@ export default { if (this.sharer.netdiskName) { this.netdiskName = this.sharer.netdiskName } + this.sharerUsername = this.sharer.username if (this.sharer.netdiskLogo) { this.netdiskLogo = this.sharer.netdiskLogo }