perf: 优化流程图组件

This commit is contained in:
jmal 2022-08-16 23:30:56 +08:00
parent 15eb1447d5
commit 363d77bc24
4 changed files with 30 additions and 17 deletions

View File

@ -827,7 +827,6 @@ export default {
mounted() { mounted() {
Bus.$on('fileSuccess', () => {}) Bus.$on('fileSuccess', () => {})
Bus.$on('loadFileFaild', () => { Bus.$on('loadFileFaild', () => {
console.log('loadFileFaild')
this.notPreviewDialogVisible = true this.notPreviewDialogVisible = true
}) })
Bus.$on('clickMore', (rows) => { Bus.$on('clickMore', (rows) => {
@ -1735,7 +1734,6 @@ export default {
if (newName.indexOf('.') > 0) { if (newName.indexOf('.') > 0) {
const name = newName.substring(0, newName.lastIndexOf('.')) const name = newName.substring(0, newName.lastIndexOf('.'))
const suffix = newName.substring(newName.lastIndexOf('.')) const suffix = newName.substring(newName.lastIndexOf('.'))
console.log('name', name, 'suffix', suffix)
newFileName = `${name}${append}${suffix}` newFileName = `${name}${append}${suffix}`
} else { } else {
newFileName = `${newName}${append}` newFileName = `${newName}${append}`
@ -1840,6 +1838,7 @@ export default {
this.textPreviewRow = res.data this.textPreviewRow = res.data
this.textPreviewVisible = true this.textPreviewVisible = true
break break
case 'drawio':
case 'docx': case 'docx':
case 'xlsx': case 'xlsx':
case 'pptx': case 'pptx':
@ -2562,6 +2561,10 @@ export default {
this.newCreateFileDialogTitle = "新建文本文件" this.newCreateFileDialogTitle = "新建文本文件"
this.createNewFile('txt') this.createNewFile('txt')
break break
case 'createDrawioFile':
this.newCreateFileDialogTitle = "新建流程图"
this.createNewFile('drawio')
break
case 'createWordFile': case 'createWordFile':
this.newCreateFileDialogTitle = "新建Word文档" this.newCreateFileDialogTitle = "新建Word文档"
this.createNewFile('docx') this.createNewFile('docx')

View File

@ -84,7 +84,8 @@ export default {
xml: '', xml: '',
saveBtnUpdating: false, saveBtnUpdating: false,
title: this.file.name, title: this.file.name,
saved: true saved: true,
reday: false
} }
}, },
created() { created() {
@ -120,8 +121,8 @@ export default {
path: encodeURI(this.file.path), path: encodeURI(this.file.path),
username: this.$store.state.user.name username: this.$store.state.user.name
}).then((res) => { }).then((res) => {
this.file.path = res.data.path
this.xml = res.data.contentText this.xml = res.data.contentText
console.log(this.xml)
if (this.bakData === res.data.contentText) { if (this.bakData === res.data.contentText) {
return return
} }
@ -146,6 +147,7 @@ export default {
this.saved = true this.saved = true
this.title = this.file.name this.title = this.file.name
this.update(this.xml) this.update(this.xml)
this.$emit('onEdit', this.saved)
}, },
update(value) { update(value) {
this.saveBtnUpdating = true this.saveBtnUpdating = true
@ -171,9 +173,9 @@ export default {
return return
} }
const payload = $J.jsonParse(event.data) const payload = $J.jsonParse(event.data)
console.log('handleMessage payload', payload.event, payload)
switch (payload.event) { switch (payload.event) {
case "init": case "init":
this.reday = true
this.$emit('onReady') this.$emit('onReady')
this.updateContent() this.updateContent()
break break
@ -196,7 +198,6 @@ export default {
case "save": case "save":
// save // save
this.save() this.save()
this.$emit('onEdit', this.saved)
break break
} }
} }

View File

@ -17,7 +17,7 @@
</div> </div>
<div class="wrapper"> <div class="wrapper">
<pdf-preview v-if="fileType === 'pdf'" :file="file" :shareId="shareId" :file-url="fileUrl" @onReady="onReady"></pdf-preview> <pdf-preview v-if="fileType === 'pdf'" :file="file" :shareId="shareId" :file-url="fileUrl" @onReady="onReady"></pdf-preview>
<drawio v-else-if="fileType === 'drawio'" :file="file" :shareId="shareId" :read-only="readOnly" @onEdit="onEdit" @onReady="onReady"></drawio> <drawio v-else-if="fileType === 'drawio'" v-show="fileReday" :file="file" :shareId="shareId" :read-only="readOnly" @onEdit="onEdit" @onReady="onReady"></drawio>
<only-office-editor ref="officeEditor" v-else :file="file" :file-url="fileUrl" :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" :read-only="readOnly" @onEdit="onEdit" @manualSave="manualSave" @onClose="close" @onReady="onReady"></only-office-editor>
</div> </div>
</div> </div>
@ -69,7 +69,8 @@ export default {
isSaveDialogVisible: false, isSaveDialogVisible: false,
saved: true, saved: true,
previewDocument: {}, previewDocument: {},
delayClosing: {} delayClosing: {},
fileReday: false,
} }
}, },
computed: { computed: {
@ -101,8 +102,7 @@ export default {
let that = this let that = this
this.delayClosing = setTimeout(function () { this.delayClosing = setTimeout(function () {
if (!that.readyShow) { if (!that.readyShow) {
that.readyShow = true that.loadFileFaild()
Bus.$emit('loadFileFaild')
} }
},3000) },3000)
} }
@ -119,6 +119,14 @@ export default {
return 'office' return 'office'
} }
}, },
/**
* 加载失败
*/
loadFileFaild() {
this.close()
Bus.$emit('loadFileFaild')
this.readyShow = true
},
/** /**
* 点击关闭按钮 * 点击关闭按钮
*/ */
@ -142,10 +150,10 @@ export default {
* 文件内容已经加载好了 * 文件内容已经加载好了
*/ */
onReady() { onReady() {
console.log('onReady')
this.saved = true this.saved = true
this.readyShow = true this.readyShow = true
if (this.fileType === 'office') { this.fileReday = true
if (['drawio', 'office'].include(this.fileType)) {
this.previewDocument.style.zIndex = 9999 this.previewDocument.style.zIndex = 9999
this.$nextTick(() => { this.$nextTick(() => {
let that = this let that = this
@ -162,13 +170,15 @@ export default {
onEdit(saved) { onEdit(saved) {
this.saved = saved this.saved = saved
if(saved){ if(saved){
window.onbeforeunload = function(e){ window.addEventListener('onbeforeunload', this.onbeforeunload)
e.returnValue=("文件未保存, 确定退出吗?");
}
} else { } else {
window.onbeforeunload = null window.removeEventListener('onbeforeunload', this.onbeforeunload)
} }
}, },
onbeforeunload(event) {
console.log('event', event)
event.returnValue=("文件未保存, 确定退出吗?");
},
/** /**
* 放弃修改 * 放弃修改
*/ */

View File

@ -212,7 +212,6 @@ export default {
this.loading = true this.loading = true
this.$store.dispatch('user/login', this.loginForm).then(() => { this.$store.dispatch('user/login', this.loginForm).then(() => {
this.$store.dispatch('user/setMenuList').then((res) => { this.$store.dispatch('user/setMenuList').then((res) => {
console.log(this.redirect)
this.$router.push({ path: this.redirect || '/' }) this.$router.push({ path: this.redirect || '/' })
this.loading = false this.loading = false
}).catch(() => { }).catch(() => {