Pārlūkot izejas kodu

修复在使用过程中`Token`失效后未显示登录框的问题

mxd 3 gadi atpakaļ
vecāks
revīzija
c5afffb07f

+ 1 - 1
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<Void> invalidLogin(MagicLoginException exception) {
-		return new JsonBean<>(-1, exception.getMessage());
+		return new JsonBean<>(401, exception.getMessage());
 	}
 }

+ 9 - 3
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

+ 5 - 1
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()
         }

+ 1 - 0
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() {