perf: 适配 onlyoffice JWT

This commit is contained in:
jmal 2024-06-08 12:59:47 +08:00
parent d81dd23f8c
commit ee25f1d1f9
4 changed files with 53 additions and 7 deletions

View File

@ -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
})
},
}

View File

@ -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,

View File

@ -19,7 +19,7 @@
<pdf-preview v-if="fileType === 'pdf'" :file="file" :shareId="shareId" :file-url="fileUrl" @onReady="onReady"></pdf-preview>
<drawio v-else-if="fileType === 'drawio'" v-show="fileReday" :file="file" :shareId="shareId" :read-only="readOnly" @onEdit="onEdit" @onReady="onReady" @onClose="close"></drawio>
<my-mind-editor v-else-if="fileType === 'mind'" :file="file" :shareId="shareId" :read-only="readOnly" @onEdit="onEdit" @onReady="onReady" @onClose="close"></my-mind-editor>
<only-office-editor ref="officeEditor" v-else :file="file" :file-url="fileUrl" :shareId="shareId" :read-only="readOnly" @onEdit="onEdit" @manualSave="manualSave" @onClose="close" @onReady="onReady"></only-office-editor>
<only-office-editor ref="officeEditor" v-else :file="file" :file-url="fileUrl" :shareId="shareId" :sharer="sharer" :read-only="readOnly" @onEdit="onEdit" @manualSave="manualSave" @onClose="close" @onReady="onReady"></only-office-editor>
</div>
</div>
</div>
@ -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){

View File

@ -255,7 +255,7 @@
<image-viewer :fileList="fileList" :shareId="shareId" :file="imagePreviewRow"
:status.sync="imagePreviewVisible"></image-viewer>
<video-preview :file="videoPreviewRow" :shareId="shareId" :status.sync="videoPreviewVisible"></video-preview>
<office-preview :file="officePreviewRow" :shareId="shareId" :status.sync="officePreviewVisible"></office-preview>
<office-preview :file="officePreviewRow" :shareId="shareId" :sharer="sharerUsername" :status.sync="officePreviewVisible"></office-preview>
<el-divider v-if="!linkFailed && !showShareCode" class="grid-divider" content-position="center"><i
class="el-icon-folder-opened"></i>&nbsp;{{ summaries }}
</el-divider>
@ -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
}