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() {
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')

View File

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

View File

@ -17,7 +17,7 @@
</div>
<div class="wrapper">
<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>
</div>
</div>
@ -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=("文件未保存, 确定退出吗?");
},
/**
* 放弃修改
*/

View File

@ -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(() => {