From 2e1fdca340d465dc15d737a8f522ed5cfc3bf6b6 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Mon, 23 Dec 2019 14:07:11 +0800 Subject: [PATCH] fix: the post will be prompted to save even if it is not modified. --- src/views/post/PostEdit.vue | 18 +++++++++++++----- src/views/sheet/SheetEdit.vue | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/views/post/PostEdit.vue b/src/views/post/PostEdit.vue index ade78d03a..941a3b059 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 648b77f93..80330b4a1 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: {