From 363d77bc2423c57284fff286c5dabe88655633e7 Mon Sep 17 00:00:00 2001 From: jmal Date: Tue, 16 Aug 2022 23:30:56 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E5=9B=BE=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ShowFile/ShowFile.vue | 7 ++++-- src/components/office/Drawio.vue | 9 +++---- src/components/preview/OfficePreview.vue | 30 ++++++++++++++++-------- src/views/login/index.vue | 1 - 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/components/ShowFile/ShowFile.vue b/src/components/ShowFile/ShowFile.vue index 65af0aa..2aee3cf 100644 --- a/src/components/ShowFile/ShowFile.vue +++ b/src/components/ShowFile/ShowFile.vue @@ -827,7 +827,6 @@ export default { mounted() { Bus.$on('fileSuccess', () => {}) Bus.$on('loadFileFaild', () => { - console.log('loadFileFaild') this.notPreviewDialogVisible = true }) Bus.$on('clickMore', (rows) => { @@ -1735,7 +1734,6 @@ export default { if (newName.indexOf('.') > 0) { const name = newName.substring(0, newName.lastIndexOf('.')) const suffix = newName.substring(newName.lastIndexOf('.')) - console.log('name', name, 'suffix', suffix) newFileName = `${name}${append}${suffix}` } else { newFileName = `${newName}${append}` @@ -1840,6 +1838,7 @@ export default { this.textPreviewRow = res.data this.textPreviewVisible = true break + case 'drawio': case 'docx': case 'xlsx': case 'pptx': @@ -2562,6 +2561,10 @@ export default { this.newCreateFileDialogTitle = "新建文本文件" this.createNewFile('txt') break + case 'createDrawioFile': + this.newCreateFileDialogTitle = "新建流程图" + this.createNewFile('drawio') + break case 'createWordFile': this.newCreateFileDialogTitle = "新建Word文档" this.createNewFile('docx') diff --git a/src/components/office/Drawio.vue b/src/components/office/Drawio.vue index 4937ff8..aeeb92c 100644 --- a/src/components/office/Drawio.vue +++ b/src/components/office/Drawio.vue @@ -84,7 +84,8 @@ export default { xml: '', saveBtnUpdating: false, title: this.file.name, - saved: true + saved: true, + reday: false } }, created() { @@ -120,8 +121,8 @@ export default { path: encodeURI(this.file.path), username: this.$store.state.user.name }).then((res) => { + this.file.path = res.data.path this.xml = res.data.contentText - console.log(this.xml) if (this.bakData === res.data.contentText) { return } @@ -146,6 +147,7 @@ export default { this.saved = true this.title = this.file.name this.update(this.xml) + this.$emit('onEdit', this.saved) }, update(value) { this.saveBtnUpdating = true @@ -171,9 +173,9 @@ export default { return } const payload = $J.jsonParse(event.data) - console.log('handleMessage payload', payload.event, payload) switch (payload.event) { case "init": + this.reday = true this.$emit('onReady') this.updateContent() break @@ -196,7 +198,6 @@ export default { case "save": // save this.save() - this.$emit('onEdit', this.saved) break } } diff --git a/src/components/preview/OfficePreview.vue b/src/components/preview/OfficePreview.vue index db93ca6..f1921e5 100644 --- a/src/components/preview/OfficePreview.vue +++ b/src/components/preview/OfficePreview.vue @@ -17,7 +17,7 @@
- +
@@ -69,7 +69,8 @@ export default { isSaveDialogVisible: false, saved: true, previewDocument: {}, - delayClosing: {} + delayClosing: {}, + fileReday: false, } }, computed: { @@ -101,8 +102,7 @@ export default { let that = this this.delayClosing = setTimeout(function () { if (!that.readyShow) { - that.readyShow = true - Bus.$emit('loadFileFaild') + that.loadFileFaild() } },3000) } @@ -119,6 +119,14 @@ export default { return 'office' } }, + /** + * 加载失败 + */ + loadFileFaild() { + this.close() + Bus.$emit('loadFileFaild') + this.readyShow = true + }, /** * 点击关闭按钮 */ @@ -142,10 +150,10 @@ export default { * 文件内容已经加载好了 */ onReady() { - console.log('onReady') this.saved = true this.readyShow = true - if (this.fileType === 'office') { + this.fileReday = true + if (['drawio', 'office'].include(this.fileType)) { this.previewDocument.style.zIndex = 9999 this.$nextTick(() => { let that = this @@ -162,13 +170,15 @@ export default { onEdit(saved) { this.saved = saved if(saved){ - window.onbeforeunload = function(e){ - e.returnValue=("文件未保存, 确定退出吗?"); - } + window.addEventListener('onbeforeunload', this.onbeforeunload) } else { - window.onbeforeunload = null + window.removeEventListener('onbeforeunload', this.onbeforeunload) } }, + onbeforeunload(event) { + console.log('event', event) + event.returnValue=("文件未保存, 确定退出吗?"); + }, /** * 放弃修改 */ diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 942310b..eeb7556 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -212,7 +212,6 @@ export default { this.loading = true this.$store.dispatch('user/login', this.loginForm).then(() => { this.$store.dispatch('user/setMenuList').then((res) => { - console.log(this.redirect) this.$router.push({ path: this.redirect || '/' }) this.loading = false }).catch(() => {