From 65f078efa3ea072746a6e67b26e480297f1f4ad0 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Sat, 22 Feb 2020 14:35:03 +0800 Subject: [PATCH] fix: If the post fails to save, the button will not be restored to clickable. (#68) --- src/views/post/PostEdit.vue | 66 ++++++++++++------- .../post/components/PostSettingDrawer.vue | 42 +++++++----- src/views/sheet/SheetEdit.vue | 54 +++++++++------ .../sheet/components/SheetSettingDrawer.vue | 42 +++++++----- 4 files changed, 128 insertions(+), 76 deletions(-) diff --git a/src/views/post/PostEdit.vue b/src/views/post/PostEdit.vue index 3a3e1178..f12d1629 100644 --- a/src/views/post/PostEdit.vue +++ b/src/views/post/PostEdit.vue @@ -185,25 +185,37 @@ export default { if (this.postToStage.id) { // Update the post if (draftOnly) { - postApi.updateDraft(this.postToStage.id, this.postToStage.originalContent).then(response => { - this.$message.success('保存草稿成功!') - this.saving = false - }) + postApi + .updateDraft(this.postToStage.id, this.postToStage.originalContent) + .then(response => { + this.$message.success('保存草稿成功!') + }) + .finally(() => { + 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 - }) + postApi + .update(this.postToStage.id, this.postToStage, false) + .then(response => { + this.$log.debug('Updated post', response.data.data) + this.$message.success('保存草稿成功!') + }) + .finally(() => { + this.saving = false + }) } } else { // Create the post - postApi.create(this.postToStage, false).then(response => { - this.$log.debug('Created post', response.data.data) - this.$message.success('保存草稿成功!') - this.postToStage = response.data.data - this.saving = false - }) + postApi + .create(this.postToStage, false) + .then(response => { + this.$log.debug('Created post', response.data.data) + this.$message.success('保存草稿成功!') + this.postToStage = response.data.data + }) + .finally(() => { + this.saving = false + }) } }, handleAttachmentUpload(pos, $file) { @@ -234,20 +246,28 @@ export default { // 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 - }) + postApi + .preview(this.postToStage.id) + .then(response => { + window.open(response.data, '_blank') + }) + .finally(() => { + this.saving = false + }) }) } else { // Create the post postApi.create(this.postToStage, false).then(response => { this.$log.debug('Created post', response.data.data) this.postToStage = response.data.data - postApi.preview(this.postToStage.id).then(response => { - window.open(response.data, '_blank') - this.saving = false - }) + postApi + .preview(this.postToStage.id) + .then(response => { + window.open(response.data, '_blank') + }) + .finally(() => { + this.saving = false + }) }) } }, diff --git a/src/views/post/components/PostSettingDrawer.vue b/src/views/post/components/PostSettingDrawer.vue index a8140f7e..5e2ececf 100644 --- a/src/views/post/components/PostSettingDrawer.vue +++ b/src/views/post/components/PostSettingDrawer.vue @@ -469,27 +469,35 @@ export default { 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() + postApi + .update(this.selectedPost.id, this.selectedPost, autoSave) + .then(response => { + this.$log.debug('Updated post', response.data.data) + if (updateSuccess) { + updateSuccess() + this.$emit('onSaved', true) + this.$router.push({ name: 'PostList' }) + } + }) + .finally(() => { this.saving = false - this.$emit('onSaved', true) - this.$router.push({ name: 'PostList' }) - } - }) + }) } else { // Create the post - postApi.create(this.selectedPost, autoSave).then(response => { - this.$log.debug('Created post', response.data.data) - if (createSuccess) { - createSuccess() + postApi + .create(this.selectedPost, autoSave) + .then(response => { + 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 + }) + .finally(() => { this.saving = false - this.$emit('onSaved', true) - this.$router.push({ name: 'PostList' }) - } - this.selectedPost = response.data.data - }) + }) } }, onClose() { diff --git a/src/views/sheet/SheetEdit.vue b/src/views/sheet/SheetEdit.vue index 42fa3631..79bb5a0c 100644 --- a/src/views/sheet/SheetEdit.vue +++ b/src/views/sheet/SheetEdit.vue @@ -171,18 +171,26 @@ export default { this.sheetToStage.title = moment(new Date()).format('YYYY-MM-DD-HH-mm-ss') } if (this.sheetToStage.id) { - sheetApi.update(this.sheetToStage.id, this.sheetToStage, false).then(response => { - this.$log.debug('Updated sheet', response.data.data) - this.$message.success('保存草稿成功!') - this.saving = false - }) + sheetApi + .update(this.sheetToStage.id, this.sheetToStage, false) + .then(response => { + this.$log.debug('Updated sheet', response.data.data) + this.$message.success('保存草稿成功!') + }) + .finally(() => { + 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 - }) + sheetApi + .create(this.sheetToStage, false) + .then(response => { + this.$log.debug('Created sheet', response.data.data) + this.$message.success('保存草稿成功!') + this.sheetToStage = response.data.data + }) + .finally(() => { + this.saving = false + }) } }, handleAttachmentUpload(pos, $file) { @@ -212,19 +220,27 @@ export default { 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 - }) + sheetApi + .preview(this.sheetToStage.id) + .then(response => { + window.open(response.data, '_blank') + }) + .finally(() => { + this.saving = false + }) }) } else { sheetApi.create(this.sheetToStage, false).then(response => { this.$log.debug('Created sheet', response.data.data) this.sheetToStage = response.data.data - sheetApi.preview(this.sheetToStage.id).then(response => { - window.open(response.data, '_blank') - this.saving = false - }) + sheetApi + .preview(this.sheetToStage.id) + .then(response => { + window.open(response.data, '_blank') + }) + .finally(() => { + this.saving = false + }) }) } }, diff --git a/src/views/sheet/components/SheetSettingDrawer.vue b/src/views/sheet/components/SheetSettingDrawer.vue index ce28ddc7..0bfa42aa 100644 --- a/src/views/sheet/components/SheetSettingDrawer.vue +++ b/src/views/sheet/components/SheetSettingDrawer.vue @@ -304,26 +304,34 @@ export default { 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() + sheetApi + .update(this.selectedSheet.id, this.selectedSheet, autoSave) + .then(response => { + this.$log.debug('Updated sheet', response.data.data) + if (updateSuccess) { + updateSuccess() + this.$emit('onSaved', true) + this.$router.push({ name: 'SheetList' }) + } + }) + .finally(() => { this.saving = false - this.$emit('onSaved', true) - this.$router.push({ name: 'SheetList' }) - } - }) + }) } else { - sheetApi.create(this.selectedSheet, autoSave).then(response => { - this.$log.debug('Created sheet', response.data.data) - if (createSuccess) { - createSuccess() + sheetApi + .create(this.selectedSheet, autoSave) + .then(response => { + 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 + }) + .finally(() => { this.saving = false - this.$emit('onSaved', true) - this.$router.push({ name: 'SheetList' }) - } - this.selectedSheet = response.data.data - }) + }) } }, onClose() {