From 6f9d0c85ab4ee7cf002aae4930afdabcb624c0f4 Mon Sep 17 00:00:00 2001 From: jmal Date: Sun, 14 Aug 2022 12:26:51 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96office=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ShowFile/ShowFile.vue | 37 +++++++++++--- src/components/message/MessageDialog.vue | 59 +++++++++++++++++----- src/components/office/OnlyOfficeEditor.vue | 7 ++- src/components/preview/OfficePreview.vue | 39 +++++++++++--- src/utils/file-config.js | 6 ++- src/utils/web.js | 8 +-- 6 files changed, 122 insertions(+), 34 deletions(-) diff --git a/src/components/ShowFile/ShowFile.vue b/src/components/ShowFile/ShowFile.vue index 5393d9b..c637bc8 100644 --- a/src/components/ShowFile/ShowFile.vue +++ b/src/components/ShowFile/ShowFile.vue @@ -441,6 +441,7 @@ { + }) + Bus.$on('loadFileReady', () => { + this.closeNotPreviewDialogVisible() + }) + Bus.$on('loadFileFaild', () => { + console.log('loadFileFaild') + this.notPreviewDialogVisible = true + this.$nextTick(() => { + this.notPreviewDialogLoading = false + }) }) Bus.$on('clickMore', (rows) => { this.$refs.fileListTable.tableSelectData = rows @@ -3127,27 +3139,39 @@ export default { this.$emit("selectedFile", selectFile) return } + this.notPreviewDialogVisible = true + this.notPreviewDialogLoading = true if (row.contentType.startsWith('image')) { // 图片 this.imagePreviewVisible = true this.imagePreviewRow = row + this.closeNotPreviewDialogVisible() return } if (suffix.simText.includes(row.suffix)) { // 文本文件 this.textPreviewRow = row this.textPreviewVisible = true + this.closeNotPreviewDialogVisible() return } if (row.contentType.indexOf('video') > -1) { // 视频文件 this.videoPreviewVisible = true this.videoPreviewRow = row + this.closeNotPreviewDialogVisible() return } if (row.contentType.indexOf('audio') > -1) { // 音频文件 Bus.$emit('onAddAudio', row, this.audioCoverUrl) + this.closeNotPreviewDialogVisible() + return + } + if (suffix.compressedFile.includes(row.suffix)) { + // 压缩文件 + this.openCompressionVisible = true + this.closeNotPreviewDialogVisible() return } if (row.contentType.indexOf('office') > -1 || row.suffix === 'csv') { @@ -3159,17 +3183,18 @@ export default { if (row.suffix === 'pdf') { // pdf文件 fileConfig.preview(this.$store.state.user.name, row, this.$store.getters.token) + this.closeNotPreviewDialogVisible() return } - if (suffix.compressedFile.includes(row.suffix)) { - // 压缩文件 - this.openCompressionVisible = true - return - } - // 其他文件 + this.notPreviewDialogLoading = false this.notPreviewDialogVisible = true } }, + closeNotPreviewDialogVisible() { + // 其他文件 + this.notPreviewDialogVisible = false + this.notPreviewDialogLoading = false + }, // 强行使用文本编辑器打开 forciblyOpen(file) { this.textPreviewRow = file diff --git a/src/components/message/MessageDialog.vue b/src/components/message/MessageDialog.vue index 629cf33..7ff430d 100644 --- a/src/components/message/MessageDialog.vue +++ b/src/components/message/MessageDialog.vue @@ -1,19 +1,23 @@ @@ -25,12 +29,24 @@ type: String, default: '' }, + modal: { + type: Boolean, + default: function () { + return true + } + }, show: { type: Boolean, default: function () { return false } }, + loading: { + type: Boolean, + default: function () { + return false + } + }, content: { type: String, default: '' @@ -81,8 +97,20 @@ } diff --git a/src/components/office/OnlyOfficeEditor.vue b/src/components/office/OnlyOfficeEditor.vue index ec8fbcd..a2590e9 100644 --- a/src/components/office/OnlyOfficeEditor.vue +++ b/src/components/office/OnlyOfficeEditor.vue @@ -60,9 +60,11 @@ export default { if (!id) { return } - $J.loadScript($J.apiUrl("http://imac/office/web-apps/apps/api/documents/api.js"), (e) => { + let officeApiUrl = fileConfig.officeApiUrl() + $J.loadScript($J.apiUrl(officeApiUrl), (e) => { if (e !== null) { - $J.modalAlert("组件加载失败!") + this.$emit('onClose') + Bus.$emit('loadFileFaild') return } if(this.$store.state.user.token && this.$store.state.user.userId === this.file.userId){ @@ -172,6 +174,7 @@ export default { }, onDocumentReady() { console.log('onDocumentReady') + this.$emit('onReday') let parentDoc = document.querySelector('.component-only-office') let doc = parentDoc.getElementsByTagName('iframe')[0].contentWindow.document let logo = doc.querySelector('.extra .logo') diff --git a/src/components/preview/OfficePreview.vue b/src/components/preview/OfficePreview.vue index 79b7daa..b71e0a8 100644 --- a/src/components/preview/OfficePreview.vue +++ b/src/components/preview/OfficePreview.vue @@ -11,16 +11,14 @@ >
- -
+
- +
-
@@ -60,15 +58,20 @@ export default { return { pc: this.$pc, show: this.status, + readyShow: false, readOnly: true, isSaveDialogVisible: false, saved: true, + previewDocument: {}, } }, watch: { status: function(visible){ if(visible){ this.show = true + this.$nextTick(() => { + this.previewDocument = document.querySelector('.preview-block') + }) this.checkReadOnly(this.file.userId) } } @@ -89,8 +92,24 @@ export default { */ close() { this.show = false + this.readyShow = false this.$emit('update:status', false) }, + /** + * 文件内容已经加载好了 + */ + onReday() { + this.saved = true + this.previewDocument.style.zIndex = 9999 + this.readyShow = true + this.$nextTick(() => { + Bus.$emit('loadFileReady') + let that = this + setTimeout(function () { + that.previewDocument.style.zIndex = 2001 + },200) + }) + }, /** * 编辑回调 * @param saved 是否已经保存 @@ -171,9 +190,16 @@ export default { background-color: rgba(0,0,0,.7); } -.block { +.preview-block { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: rgba(0,0,0,.7); + z-index: 2001; + .close-bar { - z-index: 2006; background-color: rgba(0,0,0,.5); position: relative; top: -2.5rem; @@ -197,7 +223,6 @@ export default { .preview-close { transform: rotate(-45deg); - z-index: 2009; position: absolute; font-size: 1.25rem; top: -8px; diff --git a/src/utils/file-config.js b/src/utils/file-config.js index 4c0bfde..c5eb2b0 100644 --- a/src/utils/file-config.js +++ b/src/utils/file-config.js @@ -7,7 +7,11 @@ export default { webDAVUrl: function(username) { return window.location.origin + `${this.baseUrl}/webDAV/${username}` }, - // webDAV的url + // office api url + officeApiUrl: function() { + return `${window.location.origin}/office/web-apps/apps/api/documents/api.js` + }, + // office回调url officeCallBackUrl: function(token, fileId) { return `${window.location.origin}${this.baseUrl}/office/track?jmal-token=${token}&fileId=${fileId}` }, diff --git a/src/utils/web.js b/src/utils/web.js index 805028e..16c112c 100755 --- a/src/utils/web.js +++ b/src/utils/web.js @@ -531,20 +531,20 @@ if (msg === false) { return; } - alert($J.L(msg)); + alert(msg); }, //提示 messageSuccess(msg) { - $J.Message.success($J.L(msg)); + $J.Message.success(msg); }, messageWarning(msg) { - $J.Message.warning($J.L(msg)); + $J.Message.warning(msg); }, messageError(msg) { - $J.Message.error($J.L(msg)); + $J.Message.error(msg); }, //通知