diff --git a/frontend/src/components/Bugit.vue b/frontend/src/components/Bugit.vue index c110eba..87e32e9 100644 --- a/frontend/src/components/Bugit.vue +++ b/frontend/src/components/Bugit.vue @@ -37,6 +37,8 @@ export default { this.$bus.$on('msg.success', this.successMessage) this.$bus.$on('msg.info', this.infoMessage) this.$bus.$on('msg.error', this.errorMessage) + this.$bus.$on('msg.loading', this.loadingMessage) + this.$bus.$on('msg.destroy', this.destroyMessage) }, mounted () { document.addEventListener('keydown', this.onKeyDown) @@ -81,6 +83,13 @@ export default { closable: true }) }, + loadingMessage (msg) { + this.$Message.loading({ + content: msg, + duration: 0, + closable: true + }) + }, displayMessage (data) { if (data.hasOwnProperty('code')) { if (data.code === 1000) { @@ -109,6 +118,9 @@ export default { closable: true }) } + }, + destroyMessage () { + this.$Message.destroy() } } } diff --git a/frontend/src/components/form/RichTextEditor.vue b/frontend/src/components/form/RichTextEditor.vue index e6dc7b0..fc38225 100644 --- a/frontend/src/components/form/RichTextEditor.vue +++ b/frontend/src/components/form/RichTextEditor.vue @@ -6,6 +6,7 @@ :format="['jpg','jpeg','png']" accept=".jpg,.jpeg,.png" :show-upload-list="false" + :before-upload="loadingFile" :on-success="handleSuccess" :on-error="handleError" style="display: none;" @@ -50,9 +51,9 @@ export default { } } } - } - }, - placeholder: 'Enter your description...' + }, + placeholder: 'Enter your description...' + } } }, created () { @@ -64,10 +65,15 @@ export default { this.$store.commit('setDescValue', this.quill) }, methods: { + loadingFile () { + this.$bus.$emit('msg.loading', 'Loading image...') + }, handleSuccess (response, file, fileList) { this.$store.dispatch('updateImgToDesc', file) + this.$bus.$emit('msg.destroy') }, handleError (error, file) { + this.$bus.$emit('msg.destroy') this.$bus.$emit('msg.error', 'Import ' + file.name + ' error: ' + error) }, initEvent () { diff --git a/frontend/src/store/form.js b/frontend/src/store/form.js index 0931e1e..2829c0d 100644 --- a/frontend/src/store/form.js +++ b/frontend/src/store/form.js @@ -188,8 +188,11 @@ export default { commit('setTemplateDetail', []) commit('setLoadTemplate', true) api.getTemplate(path, state.selectedCache).then(response => { - commit('setTemplateDetail', response.data) + commit('setTemplateDetail', response.data.template_detail) commit('setLoadTemplate', false) + if (response.data.message) { + bus.$emit('msg.info', response.data.message) + } }).catch(error => { bus.$emit('message', 'Load template detail error: ' + error) commit('setLoadTemplate', false) @@ -216,6 +219,7 @@ export default { let imgId = attachmentsList[i].id commit('addDescImgId', imgId) let apiPath = `/plugins/bugit/api/attachments/${imgId}` + quill.focus() let length = quill.getSelection().index quill.insertEmbed(length, 'image', apiPath) quill.setSelection(length + 1) @@ -264,6 +268,8 @@ export default { let extensionName = String(failAttach.split('.').slice(-1)) bus.$emit('msg.error', `Add ${failAttach} to attachment error: cannot convert data to a ${extensionName} file.`) } + } else if (response.data.template_detail) { + commit('setTemplateDetail', response.data.template_detail) } bus.$emit('message', response.data) commit('setSubmitLock', false) diff --git a/lyrebird_bugit/apis.py b/lyrebird_bugit/apis.py index a293eb7..b0723e4 100644 --- a/lyrebird_bugit/apis.py +++ b/lyrebird_bugit/apis.py @@ -69,9 +69,18 @@ def template(): template_detail = template.form({'cache': template_detail}) else: template_detail = template.form() + + # 'template_loaded' fields will be ensured to have a uniform value by the script. + if template_detail[0]['template_loaded']: + message = None + else: + message = 'Template loads failed! Please try again later.' cache.selected_template(template_path, draft_name) - return jsonify(template_detail) + return application.make_ok_response( + message=message, + template_detail=template_detail + ) def issue(): @@ -114,6 +123,9 @@ def issue(): except Exception as e: if e.__class__.__name__ == 'BugitFormInputError': return application.make_fail_response(str(e)) + if e.__class__.__name__ == 'SubmitError': + return application.make_fail_response(str(e.args[0]['message']), + template_detail=e.args[0]['template_detail']) error_message = traceback.format_exc() trace = "
".join(error_message.split("\n")) lyrebird.report({ diff --git a/setup.py b/setup.py index 21fc3d9..ac5109e 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='lyrebird-bugit', - version='1.13.0', + version='1.14.0', packages=['lyrebird_bugit'], url='https://github.com/Meituan-Dianping/lyrebird-bugit', author='HBQA',