Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
fix: the post will be prompted to save even if it is not modified.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Dec 23, 2019
1 parent 2b887e7 commit 7df15e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/views/post/PostEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export default {
selectedTagIds: [],
selectedCategoryIds: [],
selectedPostMetas: [],
isSaved: false
isSaved: false,
contentChanges: 0
}
},
beforeRouteEnter(to, from, next) {
Expand Down Expand Up @@ -131,7 +132,7 @@ export default {
this.attachmentDrawerVisible = false
}
if (!this.postToStage.originalContent) {
if (this.contentChanges <= 1) {
next()
} else if (this.isSaved) {
next()
Expand All @@ -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: {
Expand Down Expand Up @@ -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 => {
Expand Down
15 changes: 13 additions & 2 deletions src/views/sheet/SheetEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export default {
sheetSettingVisible: false,
sheetToStage: {},
selectedSheetMetas: [],
isSaved: false
isSaved: false,
contentChanges: 0
}
},
beforeRouteEnter(to, from, next) {
Expand Down Expand Up @@ -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()
Expand All @@ -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: {
Expand Down

0 comments on commit 7df15e5

Please sign in to comment.