Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
Enable draft only saving
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnNiang committed Jan 4, 2020
1 parent dee738f commit 8e3de35
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/api/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
return service({
url: `${baseUrl}/${postId}/status/${status}`,
Expand Down
24 changes: 16 additions & 8 deletions src/views/post/PostEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
:ishljs="true"
:autofocus="false"
@imgAdd="handleAttachmentUpload"
@save="handleSaveDraft"
@save="handleSaveDraft(true)"
/>
</div>
</a-col>
Expand All @@ -44,7 +44,7 @@
<footer-tool-bar :style="{ width: isSideMenu() && isDesktop() ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%'}">
<a-button
type="danger"
@click="handleSaveDraft"
@click="handleSaveDraft(false)"
:disabled="saving"
>保存草稿</a-button>
<a-button
Expand Down Expand Up @@ -175,19 +175,27 @@ export default {
...mapGetters(['options'])
},
methods: {
handleSaveDraft() {
handleSaveDraft(draftOnly = false) {
this.$log.debug('Draft only: ' + draftOnly)
this.postToStage.status = 'DRAFT'
if (!this.postToStage.title) {
this.postToStage.title = moment(new Date()).format('YYYY-MM-DD-HH-mm-ss')
}
this.saving = true
if (this.postToStage.id) {
// Update the post
postApi.update(this.postToStage.id, this.postToStage, false).then(response => {
this.$log.debug('Updated post', response.data.data)
this.$message.success('保存草稿成功!')
this.saving = false
})
if (draftOnly) {
postApi.updateDraft(this.postToStage.id, this.postToStage.originalContent).then(response => {
this.$message.success('保存草稿成功!')
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 {
// Create the post
postApi.create(this.postToStage, false).then(response => {
Expand Down

0 comments on commit 8e3de35

Please sign in to comment.