Enable draft only saving

pull/3445/head
johnniang 2020-01-04 21:11:16 +08:00
parent 20e093469a
commit 51b7e714cc
2 changed files with 26 additions and 8 deletions

View File

@ -51,6 +51,16 @@ postApi.update = (postId, postToUpdate, autoSave) => {
}) })
} }
postApi.updateDraft = (postId, content) => {
return service({
url: `${baseUrl}/${postId}/status/draft/content`,
method: 'put',
data: {
content: content
}
})
}
postApi.updateStatus = (postId, status) => { postApi.updateStatus = (postId, status) => {
return service({ return service({
url: `${baseUrl}/${postId}/status/${status}`, url: `${baseUrl}/${postId}/status/${status}`,

View File

@ -19,7 +19,7 @@
:ishljs="true" :ishljs="true"
:autofocus="false" :autofocus="false"
@imgAdd="handleAttachmentUpload" @imgAdd="handleAttachmentUpload"
@save="handleSaveDraft" @save="handleSaveDraft(true)"
/> />
</div> </div>
</a-col> </a-col>
@ -44,7 +44,7 @@
<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-button <a-button
type="danger" type="danger"
@click="handleSaveDraft" @click="handleSaveDraft(false)"
:disabled="saving" :disabled="saving"
>保存草稿</a-button> >保存草稿</a-button>
<a-button <a-button
@ -175,7 +175,8 @@ export default {
...mapGetters(['options']) ...mapGetters(['options'])
}, },
methods: { methods: {
handleSaveDraft() { handleSaveDraft(draftOnly = false) {
this.$log.debug('Draft only: ' + draftOnly)
this.postToStage.status = 'DRAFT' this.postToStage.status = 'DRAFT'
if (!this.postToStage.title) { if (!this.postToStage.title) {
this.postToStage.title = moment(new Date()).format('YYYY-MM-DD-HH-mm-ss') this.postToStage.title = moment(new Date()).format('YYYY-MM-DD-HH-mm-ss')
@ -183,11 +184,18 @@ export default {
this.saving = true this.saving = true
if (this.postToStage.id) { if (this.postToStage.id) {
// Update the post // Update the post
postApi.update(this.postToStage.id, this.postToStage, false).then(response => { if (draftOnly) {
this.$log.debug('Updated post', response.data.data) postApi.updateDraft(this.postToStage.id, this.postToStage.originalContent).then(response => {
this.$message.success('保存草稿成功!') this.$message.success('保存草稿成功!')
this.saving = false this.saving = false
}) })
} else {
postApi.update(this.postToStage.id, this.postToStage, false).then(response => {
this.$log.debug('Updated post', response.data.data)
this.$message.success('保存草稿成功!')
this.saving = false
})
}
} else { } else {
// Create the post // Create the post
postApi.create(this.postToStage, false).then(response => { postApi.create(this.postToStage, false).then(response => {