From c5afffb07f9a186d67ce00254c57752afbbcd735 Mon Sep 17 00:00:00 2001 From: mxd <838425805@qq.com> Date: Sat, 31 Jul 2021 08:17:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E8=BF=87=E7=A8=8B=E4=B8=AD`Token`=E5=A4=B1=E6=95=88=E5=90=8E?= =?UTF-8?q?=E6=9C=AA=E6=98=BE=E7=A4=BA=E7=99=BB=E5=BD=95=E6=A1=86=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../magicapi/controller/MagicController.java | 2 +- magic-editor/src/console/src/api/request.js | 12 +++++++++--- .../src/components/editor/magic-script-editor.vue | 6 +++++- .../src/console/src/components/magic-editor.vue | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicController.java b/magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicController.java index 0226b83e..ff879bad 100644 --- a/magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicController.java +++ b/magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicController.java @@ -97,6 +97,6 @@ public class MagicController implements JsonCodeConstants { @ExceptionHandler(MagicLoginException.class) @ResponseBody public JsonBean invalidLogin(MagicLoginException exception) { - return new JsonBean<>(-1, exception.getMessage()); + return new JsonBean<>(401, exception.getMessage()); } } diff --git a/magic-editor/src/console/src/api/request.js b/magic-editor/src/console/src/api/request.js index 476f8d92..628e1e5e 100644 --- a/magic-editor/src/console/src/api/request.js +++ b/magic-editor/src/console/src/api/request.js @@ -1,8 +1,8 @@ import axios from 'axios' import Qs from 'qs' import {modal} from '@/components/common/modal' -import {replaceURL} from '@/scripts/utils.js' import contants from '@/scripts/contants.js' +import bus from '@/scripts/bus.js' const config = { // 请求路径 @@ -139,14 +139,20 @@ class HttpRequest { } requestConfig.baseURL = config.baseURL let httpResponse = new HttpResponse() + let successed = false; this.execute(requestConfig) .then(response => { let data = response.data if(data instanceof Blob){ + successed = true httpResponse.successHandle && httpResponse.successHandle(data, response) - }else if (data.code === 1) { + } else if (data.code === 1) { + successed = true httpResponse.successHandle && httpResponse.successHandle(data.data, response) } else { + if (data.code === 401) { + bus.$emit('showLogin') + } httpResponse.exceptionHandle && httpResponse.exceptionHandle(data.code, data.message, response) } }) @@ -160,7 +166,7 @@ class HttpRequest { }) .finally(() => { if (typeof httpResponse.endHandle === 'function') { - httpResponse.endHandle() + httpResponse.endHandle(successed) } }) return httpResponse diff --git a/magic-editor/src/console/src/components/editor/magic-script-editor.vue b/magic-editor/src/console/src/components/editor/magic-script-editor.vue index 2eedf955..71e52f13 100644 --- a/magic-editor/src/console/src/components/editor/magic-script-editor.vue +++ b/magic-editor/src/console/src/components/editor/magic-script-editor.vue @@ -474,7 +474,11 @@ export default { if (contants.AUTO_SAVE) { // 自动保存 let resp = this.doSave() - resp && resp.end(() => this.internalTest()) + resp && resp.end((successed) => { + if (successed) { + this.internalTest() + } + }) } else { this.internalTest() } diff --git a/magic-editor/src/console/src/components/magic-editor.vue b/magic-editor/src/console/src/components/magic-editor.vue index bfccf49a..2c7165c1 100644 --- a/magic-editor/src/console/src/components/magic-editor.vue +++ b/magic-editor/src/console/src/components/magic-editor.vue @@ -196,6 +196,7 @@ export default { } }) bus.$on('logout', () => this.showLogin = true) + bus.$on('showLogin', () => this.showLogin = true) this.open() }, destroyed() {