fix: prevent duplicate data.

pull/59/head
ruibaby 5 years ago
parent ce6ea9c787
commit 5e0da2f35d

@ -45,10 +45,12 @@
<a-button
type="danger"
@click="handleSaveDraft"
:disabled="saving"
>保存草稿</a-button>
<a-button
@click="handlePreview"
style="margin-left: 8px;"
:disabled="saving"
>预览</a-button>
<a-button
type="primary"
@ -95,7 +97,8 @@ export default {
selectedCategoryIds: [],
selectedPostMetas: [],
isSaved: false,
contentChanges: 0
contentChanges: 0,
saving: false
}
},
beforeRouteEnter(to, from, next) {
@ -177,11 +180,13 @@ export default {
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
})
} else {
// Create the post
@ -189,6 +194,7 @@ export default {
this.$log.debug('Created post', response.data.data)
this.$message.success('保存草稿成功!')
this.postToStage = response.data.data
this.saving = false
})
}
},
@ -215,12 +221,14 @@ export default {
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)
postApi.preview(this.postToStage.id).then(response => {
window.open(response.data, '_blank')
this.saving = false
})
})
} else {
@ -230,6 +238,7 @@ export default {
this.postToStage = response.data.data
postApi.preview(this.postToStage.id).then(response => {
window.open(response.data, '_blank')
this.saving = false
})
})
}

@ -228,16 +228,19 @@
style="marginRight: 8px"
@click="handleDraftClick"
v-if="saveDraftButton"
:disabled="saving"
>保存草稿</a-button>
<a-button
@click="handlePublishClick"
type="primary"
v-if="savePublishButton"
:disabled="saving"
>发布</a-button>
<a-button
@click="handlePublishClick"
type="primary"
v-if="saveButton"
:disabled="saving"
>保存</a-button>
</div>
</a-drawer>
@ -272,7 +275,8 @@ export default {
selectedCategoryIds: this.categoryIds,
categories: [],
categoryToCreate: {},
customTpls: []
customTpls: [],
saving: false
}
},
props: {
@ -449,13 +453,14 @@ export default {
this.selectedPost.tagIds = this.selectedTagIds
// Set post metas
this.selectedPost.postMetas = this.selectedPostMetas
this.saving = true
if (this.selectedPost.id) {
// Update the post
postApi.update(this.selectedPost.id, this.selectedPost, autoSave).then(response => {
this.$log.debug('Updated post', response.data.data)
if (updateSuccess) {
updateSuccess()
this.saving = false
this.$emit('onSaved', true)
this.$router.push({ name: 'PostList' })
}
@ -466,6 +471,7 @@ export default {
this.$log.debug('Created post', response.data.data)
if (createSuccess) {
createSuccess()
this.saving = false
this.$emit('onSaved', true)
this.$router.push({ name: 'PostList' })
}

@ -39,10 +39,12 @@
<a-button
type="danger"
@click="handleSaveDraft"
:disabled="saving"
>保存草稿</a-button>
<a-button
@click="handlePreview"
style="margin-left: 8px;"
:disabled="saving"
>预览</a-button>
<a-button
type="primary"
@ -86,7 +88,8 @@ export default {
sheetToStage: {},
selectedSheetMetas: [],
isSaved: false,
contentChanges: 0
contentChanges: 0,
saving: false
}
},
beforeRouteEnter(to, from, next) {
@ -163,6 +166,7 @@ export default {
methods: {
handleSaveDraft() {
this.sheetToStage.status = 'DRAFT'
this.saving = true
if (!this.sheetToStage.title) {
this.sheetToStage.title = moment(new Date()).format('YYYY-MM-DD-HH-mm-ss')
}
@ -170,12 +174,14 @@ export default {
sheetApi.update(this.sheetToStage.id, this.sheetToStage, false).then(response => {
this.$log.debug('Updated sheet', response.data.data)
this.$message.success('保存草稿成功!')
this.saving = false
})
} else {
sheetApi.create(this.sheetToStage, false).then(response => {
this.$log.debug('Created sheet', response.data.data)
this.$message.success('保存草稿成功!')
this.sheetToStage = response.data.data
this.saving = false
})
}
},
@ -202,14 +208,13 @@ export default {
if (!this.sheetToStage.title) {
this.sheetToStage.title = moment(new Date()).format('YYYY-MM-DD-HH-mm-ss')
}
if (!this.sheetToStage.originalContent) {
this.sheetToStage.originalContent = '开始编辑...'
}
this.saving = true
if (this.sheetToStage.id) {
sheetApi.update(this.sheetToStage.id, this.sheetToStage, false).then(response => {
this.$log.debug('Updated sheet', response.data.data)
sheetApi.preview(this.sheetToStage.id).then(response => {
window.open(response.data, '_blank')
this.saving = false
})
})
} else {
@ -218,6 +223,7 @@ export default {
this.sheetToStage = response.data.data
sheetApi.preview(this.sheetToStage.id).then(response => {
window.open(response.data, '_blank')
this.saving = false
})
})
}

@ -131,10 +131,12 @@
<a-button
style="marginRight: 8px"
@click="handleDraftClick"
:disabled="saving"
>保存草稿</a-button>
<a-button
type="primary"
@click="handlePublishClick"
:disabled="saving"
>发布</a-button>
</div>
</a-drawer>
@ -157,7 +159,8 @@ export default {
thumbDrawerVisible: false,
settingLoading: true,
selectedSheet: this.sheet,
customTpls: []
customTpls: [],
saving: false
}
},
props: {
@ -272,11 +275,13 @@ export default {
return
}
this.selectedSheet.sheetMetas = this.selectedSheetMetas
this.saving = true
if (this.selectedSheet.id) {
sheetApi.update(this.selectedSheet.id, this.selectedSheet, autoSave).then(response => {
this.$log.debug('Updated sheet', response.data.data)
if (updateSuccess) {
updateSuccess()
this.saving = false
this.$emit('onSaved', true)
this.$router.push({ name: 'SheetList' })
}
@ -286,6 +291,7 @@ export default {
this.$log.debug('Created sheet', response.data.data)
if (createSuccess) {
createSuccess()
this.saving = false
this.$emit('onSaved', true)
this.$router.push({ name: 'SheetList' })
}

Loading…
Cancel
Save