diff --git a/src/views/post/PostEdit.vue b/src/views/post/PostEdit.vue index ade78d03..941a3b05 100644 --- a/src/views/post/PostEdit.vue +++ b/src/views/post/PostEdit.vue @@ -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 => { diff --git a/src/views/sheet/SheetEdit.vue b/src/views/sheet/SheetEdit.vue index 648b77f9..80330b4a 100644 --- a/src/views/sheet/SheetEdit.vue +++ b/src/views/sheet/SheetEdit.vue @@ -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: {