fix: the post will be prompted to save even if it is not modified.

pull/59/head
ruibaby 2019-12-23 14:07:11 +08:00
parent 2b887e7a5a
commit 7df15e561a
2 changed files with 26 additions and 7 deletions

View File

@ -94,7 +94,8 @@ export default {
selectedTagIds: [],
selectedCategoryIds: [],
selectedPostMetas: [],
isSaved: false
isSaved: false,
contentChanges: 0
}
},
beforeRouteEnter(to, from, next) {
@ -131,7 +132,7 @@ export default {
this.attachmentDrawerVisible = false
}
if (!this.postToStage.originalContent) {
if (this.contentChanges <= 1) {
next()
} else if (this.isSaved) {
next()
@ -157,7 +158,17 @@ export default {
return '当前页面数据未保存,确定要离开吗?'
}
},
watch: {
temporaryContent: function(newValue, oldValue) {
if (newValue) {
this.contentChanges++
}
}
},
computed: {
temporaryContent() {
return this.postToStage.originalContent
},
...mapGetters(['options'])
},
methods: {
@ -204,9 +215,6 @@ export default {
if (!this.postToStage.title) {
this.postToStage.title = moment(new Date()).format('YYYY-MM-DD-HH-mm-ss')
}
if (!this.postToStage.originalContent) {
this.postToStage.originalContent = '开始编辑...'
}
if (this.postToStage.id) {
// Update the post
postApi.update(this.postToStage.id, this.postToStage, false).then(response => {

View File

@ -85,7 +85,8 @@ export default {
sheetSettingVisible: false,
sheetToStage: {},
selectedSheetMetas: [],
isSaved: false
isSaved: false,
contentChanges: 0
}
},
beforeRouteEnter(to, from, next) {
@ -120,7 +121,7 @@ export default {
if (this.attachmentDrawerVisible) {
this.attachmentDrawerVisible = false
}
if (!this.sheetToStage.originalContent) {
if (this.contentChanges <= 1) {
next()
} else if (this.isSaved) {
next()
@ -146,7 +147,17 @@ export default {
return '当前页面数据未保存,确定要离开吗?'
}
},
watch: {
temporaryContent: function(newValue, oldValue) {
if (newValue) {
this.contentChanges++
}
}
},
computed: {
temporaryContent() {
return this.sheetToStage.originalContent
},
...mapGetters(['options'])
},
methods: {