From 92816308278aa9d6ee014fd389a7e8c375858618 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Sat, 23 Nov 2019 11:46:16 +0800 Subject: [PATCH] feat: #52 --- package-lock.json | 8 ++-- package.json | 2 +- src/views/post/PostEdit.vue | 39 ++++++++++++------- .../post/components/PostSettingDrawer.vue | 2 + src/views/sheet/SheetEdit.vue | 34 ++++++++++------ .../sheet/components/SheetSettingDrawer.vue | 4 ++ 6 files changed, 60 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index a0f361e7..dcbf7b6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8226,11 +8226,11 @@ } }, "halo-editor": { - "version": "2.7.8", - "resolved": "https://registry.npmjs.org/halo-editor/-/halo-editor-2.7.8.tgz", - "integrity": "sha512-Okpnv3JQMDgQsxmKNTcSNfrvV8+FeeR2MhZ1hBhVp1yvDHFyujXENmaoGplQ/aUrnpebc4RiDAuHcB+Yla1S3Q==", + "version": "2.7.6", + "resolved": "https://registry.npmjs.org/halo-editor/-/halo-editor-2.7.6.tgz", + "integrity": "sha512-ipzW+pxWoC3JB5jAlC/7fFZnqBbXMtC6eOXZDM1dtuM4BN60kOH/tzJMlLCuEYCzWnhg+abtwtljAtOe66ASGg==", "requires": { - "highlight.js": "^9.16.2", + "highlight.js": "^9.11.0", "highlight.js-async-webpack": "^1.0.4" } }, diff --git a/package.json b/package.json index 624eac34..d7e441ee 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "enquire.js": "^2.1.6", "filepond": "^4.7.2", "filepond-plugin-image-preview": "^4.5.0", - "halo-editor": "^2.7.8", + "halo-editor": "^2.7.6", "marked": "^0.7.0", "moment": "^2.24.0", "nprogress": "^0.2.0", diff --git a/src/views/post/PostEdit.vue b/src/views/post/PostEdit.vue index 24aaa34a..c0f7cecb 100644 --- a/src/views/post/PostEdit.vue +++ b/src/views/post/PostEdit.vue @@ -5,7 +5,6 @@
@@ -36,6 +35,7 @@ @onRefreshPost="onRefreshPostFromSetting" @onRefreshTagIds="onRefreshTagIdsFromSetting" @onRefreshCategoryIds="onRefreshCategoryIdsFromSetting" + @onSaved="onSaved" /> @@ -91,7 +91,8 @@ export default { postSettingVisible: false, postToStage: {}, selectedTagIds: [], - selectedCategoryIds: [] + selectedCategoryIds: [], + isSaved: false } }, beforeRouteEnter(to, from, next) { @@ -115,7 +116,9 @@ export default { if (this.attachmentDrawerVisible) { this.attachmentDrawerVisible = false } - window.onbeforeunload = null + if (window.onbeforeunload) { + window.onbeforeunload = null + } }, beforeRouteLeave(to, from, next) { if (this.postSettingVisible) { @@ -124,24 +127,31 @@ export default { if (this.attachmentDrawerVisible) { this.attachmentDrawerVisible = false } - if (this.postToStage.originalContent) { - const answer = window.confirm('当前文章数据未保存,确定要离开吗?') - if (answer) { - next() - } else { - next(false) - } - } else { + + if (!this.postToStage.originalContent) { next() + } else if (this.isSaved) { + next() + } else { + this.$confirm({ + title: '当前页面数据未保存,确定要离开吗?', + content: h =>
如果离开当面页面,你的数据很可能会丢失!
, + onOk() { + next() + }, + onCancel() { + next(false) + } + }) } }, mounted() { window.onbeforeunload = function(e) { e = e || window.event if (e) { - e.returnValue = '当前文章数据未保存,确定要离开吗?' + e.returnValue = '当前页面数据未保存,确定要离开吗?' } - return '当前文章数据未保存,确定要离开吗?' + return '当前页面数据未保存,确定要离开吗?' } }, computed: { @@ -228,6 +238,9 @@ export default { }, onRefreshCategoryIdsFromSetting(categoryIds) { this.selectedCategoryIds = categoryIds + }, + onSaved(isSaved) { + this.isSaved = isSaved } } } diff --git a/src/views/post/components/PostSettingDrawer.vue b/src/views/post/components/PostSettingDrawer.vue index 5ff2475d..02cb0f0c 100644 --- a/src/views/post/components/PostSettingDrawer.vue +++ b/src/views/post/components/PostSettingDrawer.vue @@ -377,6 +377,7 @@ export default { this.$log.debug('Updated post', response.data.data) if (updateSuccess) { updateSuccess() + this.$emit('onSaved', true) this.$router.push({ name: 'PostList' }) } }) @@ -386,6 +387,7 @@ export default { this.$log.debug('Created post', response.data.data) if (createSuccess) { createSuccess() + this.$emit('onSaved', true) this.$router.push({ name: 'PostList' }) } this.selectedPost = response.data.data diff --git a/src/views/sheet/SheetEdit.vue b/src/views/sheet/SheetEdit.vue index f6e4a9f5..c2d9e2b8 100644 --- a/src/views/sheet/SheetEdit.vue +++ b/src/views/sheet/SheetEdit.vue @@ -5,7 +5,6 @@
@@ -31,6 +30,7 @@ :visible="sheetSettingVisible" @close="onSheetSettingsClose" @onRefreshSheet="onRefreshSheetFromSetting" + @onSaved="onSaved" /> @@ -82,7 +82,8 @@ export default { toolbars, attachmentDrawerVisible: false, sheetSettingVisible: false, - sheetToStage: {} + sheetToStage: {}, + isSaved: false } }, beforeRouteEnter(to, from, next) { @@ -105,7 +106,9 @@ export default { if (this.attachmentDrawerVisible) { this.attachmentDrawerVisible = false } - window.onbeforeunload = null + if (window.onbeforeunload) { + window.onbeforeunload = null + } }, beforeRouteLeave(to, from, next) { if (this.sheetSettingVisible) { @@ -114,15 +117,21 @@ export default { if (this.attachmentDrawerVisible) { this.attachmentDrawerVisible = false } - if (this.sheetToStage.originalContent) { - const answer = window.confirm('当前页面数据未保存,确定要离开吗?') - if (answer) { - next() - } else { - next(false) - } - } else { + if (!this.sheetToStage.originalContent) { next() + } else if (this.isSaved) { + next() + } else { + this.$confirm({ + title: '当前页面数据未保存,确定要离开吗?', + content: h =>
如果离开当面页面,你的数据很可能会丢失!
, + onOk() { + next() + }, + onCancel() { + next(false) + } + }) } }, mounted() { @@ -207,6 +216,9 @@ export default { }, onRefreshSheetFromSetting(sheet) { this.sheetToStage = sheet + }, + onSaved(isSaved) { + this.isSaved = isSaved } } } diff --git a/src/views/sheet/components/SheetSettingDrawer.vue b/src/views/sheet/components/SheetSettingDrawer.vue index 2060233b..1466764a 100644 --- a/src/views/sheet/components/SheetSettingDrawer.vue +++ b/src/views/sheet/components/SheetSettingDrawer.vue @@ -222,6 +222,8 @@ export default { this.$log.debug('Updated sheet', response.data.data) if (updateSuccess) { updateSuccess() + this.$emit('onSaved', true) + this.$router.push({ name: 'SheetList' }) } }) } else { @@ -229,6 +231,8 @@ export default { this.$log.debug('Created sheet', response.data.data) if (createSuccess) { createSuccess() + this.$emit('onSaved', true) + this.$router.push({ name: 'SheetList' }) } this.selectedSheet = response.data.data })