* fix: #241

* fix: #241
pull/248/head
Ryan Wang 2020-09-13 10:28:50 +08:00 committed by GitHub
parent 65c3894321
commit 0bf3009f0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 34 deletions

View File

@ -37,12 +37,12 @@
@onRefreshTagIds="onRefreshTagIdsFromSetting" @onRefreshTagIds="onRefreshTagIdsFromSetting"
@onRefreshCategoryIds="onRefreshCategoryIdsFromSetting" @onRefreshCategoryIds="onRefreshCategoryIdsFromSetting"
@onRefreshPostMetas="onRefreshPostMetasFromSetting" @onRefreshPostMetas="onRefreshPostMetasFromSetting"
@onSaved="onSaved" @onSaved="handleRestoreSavedStatus"
/> />
<AttachmentDrawer v-model="attachmentDrawerVisible" /> <AttachmentDrawer v-model="attachmentDrawerVisible" />
<footer-tool-bar :style="{ width: isSideMenu() && isDesktop() ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%'}"> <footer-tool-bar :style="{ width: isSideMenu() && isDesktop() ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%' }">
<a-space> <a-space>
<ReactiveButton <ReactiveButton
type="danger" type="danger"
@ -99,7 +99,6 @@ export default {
selectedTagIds: [], selectedTagIds: [],
selectedCategoryIds: [], selectedCategoryIds: [],
selectedMetas: [], selectedMetas: [],
isSaved: false,
contentChanges: 0, contentChanges: 0,
draftSaving: false, draftSaving: false,
previewSaving: false, previewSaving: false,
@ -142,8 +141,6 @@ export default {
if (this.contentChanges <= 1) { if (this.contentChanges <= 1) {
next() next()
} else if (this.isSaved) {
next()
} else { } else {
this.$confirm({ this.$confirm({
title: '当前页面数据未保存,确定要离开吗?', title: '当前页面数据未保存,确定要离开吗?',
@ -195,6 +192,9 @@ export default {
if (draftOnly) { if (draftOnly) {
postApi postApi
.updateDraft(this.postToStage.id, this.postToStage.originalContent) .updateDraft(this.postToStage.id, this.postToStage.originalContent)
.then((response) => {
this.handleRestoreSavedStatus()
})
.catch(() => { .catch(() => {
this.draftSavederrored = true this.draftSavederrored = true
}) })
@ -206,11 +206,12 @@ export default {
} else { } else {
postApi postApi
.update(this.postToStage.id, this.postToStage, false) .update(this.postToStage.id, this.postToStage, false)
.catch(() => {
this.draftSavederrored = true
})
.then((response) => { .then((response) => {
this.postToStage = response.data.data this.postToStage = response.data.data
this.handleRestoreSavedStatus()
})
.catch(() => {
this.draftSavederrored = true
}) })
.finally(() => { .finally(() => {
setTimeout(() => { setTimeout(() => {
@ -222,11 +223,12 @@ export default {
// Create the post // Create the post
postApi postApi
.create(this.postToStage, false) .create(this.postToStage, false)
.catch(() => {
this.draftSavederrored = true
})
.then((response) => { .then((response) => {
this.postToStage = response.data.data this.postToStage = response.data.data
this.handleRestoreSavedStatus()
})
.catch(() => {
this.draftSavederrored = true
}) })
.finally(() => { .finally(() => {
setTimeout(() => { setTimeout(() => {
@ -249,6 +251,7 @@ export default {
.preview(this.postToStage.id) .preview(this.postToStage.id)
.then((response) => { .then((response) => {
window.open(response.data, '_blank') window.open(response.data, '_blank')
this.handleRestoreSavedStatus()
}) })
.finally(() => { .finally(() => {
setTimeout(() => { setTimeout(() => {
@ -265,6 +268,7 @@ export default {
.preview(this.postToStage.id) .preview(this.postToStage.id)
.then((response) => { .then((response) => {
window.open(response.data, '_blank') window.open(response.data, '_blank')
this.handleRestoreSavedStatus()
}) })
.finally(() => { .finally(() => {
setTimeout(() => { setTimeout(() => {
@ -274,6 +278,9 @@ export default {
}) })
} }
}, },
handleRestoreSavedStatus() {
this.contentChanges = 0
},
onContentChange(val) { onContentChange(val) {
this.postToStage.originalContent = val this.postToStage.originalContent = val
}, },
@ -288,9 +295,6 @@ export default {
}, },
onRefreshPostMetasFromSetting(metas) { onRefreshPostMetasFromSetting(metas) {
this.selectedMetas = metas this.selectedMetas = metas
},
onSaved(isSaved) {
this.isSaved = isSaved
} }
} }
} }

View File

@ -33,7 +33,7 @@
@close="sheetSettingVisible = false" @close="sheetSettingVisible = false"
@onRefreshSheet="onRefreshSheetFromSetting" @onRefreshSheet="onRefreshSheetFromSetting"
@onRefreshSheetMetas="onRefreshSheetMetasFromSetting" @onRefreshSheetMetas="onRefreshSheetMetasFromSetting"
@onSaved="onSaved" @onSaved="handleRestoreSavedStatus"
/> />
<AttachmentDrawer v-model="attachmentDrawerVisible" /> <AttachmentDrawer v-model="attachmentDrawerVisible" />
@ -92,7 +92,6 @@ export default {
sheetSettingVisible: false, sheetSettingVisible: false,
sheetToStage: {}, sheetToStage: {},
selectedMetas: [], selectedMetas: [],
isSaved: false,
contentChanges: 0, contentChanges: 0,
draftSaving: false, draftSaving: false,
draftSavederrored: false, draftSavederrored: false,
@ -103,9 +102,9 @@ export default {
// Get sheetId id from query // Get sheetId id from query
const sheetId = to.query.sheetId const sheetId = to.query.sheetId
next(vm => { next((vm) => {
if (sheetId) { if (sheetId) {
sheetApi.get(sheetId).then(response => { sheetApi.get(sheetId).then((response) => {
const sheet = response.data.data const sheet = response.data.data
vm.sheetToStage = sheet vm.sheetToStage = sheet
vm.selectedMetas = sheet.metas vm.selectedMetas = sheet.metas
@ -133,12 +132,10 @@ export default {
} }
if (this.contentChanges <= 1) { if (this.contentChanges <= 1) {
next() next()
} else if (this.isSaved) {
next()
} else { } else {
this.$confirm({ this.$confirm({
title: '当前页面数据未保存,确定要离开吗?', title: '当前页面数据未保存,确定要离开吗?',
content: h => <div style="color:red;">如果离开当面页面你的数据很可能会丢失</div>, content: (h) => <div style="color:red;">如果离开当面页面你的数据很可能会丢失</div>,
onOk() { onOk() {
next() next()
}, },
@ -185,6 +182,9 @@ export default {
if (draftOnly) { if (draftOnly) {
sheetApi sheetApi
.updateDraft(this.sheetToStage.id, this.sheetToStage.originalContent) .updateDraft(this.sheetToStage.id, this.sheetToStage.originalContent)
.then((response) => {
this.handleRestoreSavedStatus()
})
.catch(() => { .catch(() => {
this.draftSavederrored = true this.draftSavederrored = true
}) })
@ -196,12 +196,13 @@ export default {
} else { } else {
sheetApi sheetApi
.update(this.sheetToStage.id, this.sheetToStage, false) .update(this.sheetToStage.id, this.sheetToStage, false)
.then((response) => {
this.sheetToStage = response.data.data
this.handleRestoreSavedStatus()
})
.catch(() => { .catch(() => {
this.draftSavederrored = true this.draftSavederrored = true
}) })
.then(response => {
this.sheetToStage = response.data.data
})
.finally(() => { .finally(() => {
setTimeout(() => { setTimeout(() => {
this.draftSaving = false this.draftSaving = false
@ -211,12 +212,13 @@ export default {
} else { } else {
sheetApi sheetApi
.create(this.sheetToStage, false) .create(this.sheetToStage, false)
.then((response) => {
this.sheetToStage = response.data.data
this.handleRestoreSavedStatus()
})
.catch(() => { .catch(() => {
this.draftSavederrored = true this.draftSavederrored = true
}) })
.then(response => {
this.sheetToStage = response.data.data
})
.finally(() => { .finally(() => {
setTimeout(() => { setTimeout(() => {
this.draftSaving = false this.draftSaving = false
@ -231,12 +233,13 @@ export default {
} }
this.previewSaving = true this.previewSaving = true
if (this.sheetToStage.id) { if (this.sheetToStage.id) {
sheetApi.update(this.sheetToStage.id, this.sheetToStage, false).then(response => { sheetApi.update(this.sheetToStage.id, this.sheetToStage, false).then((response) => {
this.$log.debug('Updated sheet', response.data.data) this.$log.debug('Updated sheet', response.data.data)
sheetApi sheetApi
.preview(this.sheetToStage.id) .preview(this.sheetToStage.id)
.then(response => { .then((response) => {
window.open(response.data, '_blank') window.open(response.data, '_blank')
this.handleRestoreSavedStatus()
}) })
.finally(() => { .finally(() => {
setTimeout(() => { setTimeout(() => {
@ -245,13 +248,14 @@ export default {
}) })
}) })
} else { } else {
sheetApi.create(this.sheetToStage, false).then(response => { sheetApi.create(this.sheetToStage, false).then((response) => {
this.$log.debug('Created sheet', response.data.data) this.$log.debug('Created sheet', response.data.data)
this.sheetToStage = response.data.data this.sheetToStage = response.data.data
sheetApi sheetApi
.preview(this.sheetToStage.id) .preview(this.sheetToStage.id)
.then(response => { .then((response) => {
window.open(response.data, '_blank') window.open(response.data, '_blank')
this.handleRestoreSavedStatus()
}) })
.finally(() => { .finally(() => {
setTimeout(() => { setTimeout(() => {
@ -261,6 +265,9 @@ export default {
}) })
} }
}, },
handleRestoreSavedStatus() {
this.contentChanges = 0
},
onContentChange(val) { onContentChange(val) {
this.sheetToStage.originalContent = val this.sheetToStage.originalContent = val
}, },
@ -269,9 +276,6 @@ export default {
}, },
onRefreshSheetMetasFromSetting(metas) { onRefreshSheetMetasFromSetting(metas) {
this.selectedMetas = metas this.selectedMetas = metas
},
onSaved(isSaved) {
this.isSaved = isSaved
} }
} }
} }