Jelajahi Sumber

鉴权失败错误提示更改,移除开发鉴权模式

zhangjie 4 tahun lalu
induk
melakukan
89a4944cfc
2 mengubah file dengan 18 tambahan dan 23 penghapusan
  1. 12 19
      src/main.js
  2. 6 4
      src/plugins/axios.js

+ 12 - 19
src/main.js

@@ -25,8 +25,6 @@ Vue.use(globalVuePlugins);
 
 Vue.prototype.GLOBAL = GLOBAL;
 Vue.config.productionTip = false;
-// const IS_DEV = true;
-const IS_DEV = process.env.NODE_ENV === "development";
 
 // route interceptor
 router.beforeEach((to, from, next) => {
@@ -79,23 +77,18 @@ axios.interceptors.request.use(
       });
 
       // 新版鉴权 to open
-      if (IS_DEV) {
-        config.headers["Authorization"] = token;
-        config.headers["time"] = 1;
-      } else {
-        const sessionId = Vue.ls.get("user", { sessionId: "" }).sessionId;
-        const { Authorization, timestamp } = getAuthorization(
-          {
-            token: token,
-            account: sessionId,
-            uri: config.url.split("?")[0],
-            method: config.method
-          },
-          "token"
-        );
-        config.headers["Authorization"] = Authorization;
-        config.headers["time"] = timestamp;
-      }
+      const sessionId = Vue.ls.get("user", { sessionId: "" }).sessionId;
+      const { Authorization, timestamp } = getAuthorization(
+        {
+          token: token,
+          account: sessionId,
+          uri: config.url.split("?")[0],
+          method: config.method
+        },
+        "token"
+      );
+      config.headers["Authorization"] = Authorization;
+      config.headers["time"] = timestamp;
     }
     config.headers["deviceId"] = DEVICE_ID;
     config.headers["platform"] = PLATFORM;

+ 6 - 4
src/plugins/axios.js

@@ -23,7 +23,7 @@ const mdData = datas => {
  */
 const errorCallback = error => {
   if (error.response) {
-    return errorDataCallback(error.response.data);
+    return errorDataCallback(error.response);
   }
 
   if (error.request) {
@@ -39,12 +39,14 @@ const errorCallback = error => {
 
 /**
  * errorDataCallback 请求成功,结果有误的回调
- * @param {Object} error Response中的data信息
+ * @param {Object} response Response信息
  */
-const errorDataCallback = error => {
+const errorDataCallback = response => {
+  const error = response.data;
   let message = error.message || error.error || "请求错误";
+  const unauthCodes = [401, 403];
 
-  if (error.code === 4010006 || error.code === 5000012) {
+  if (unauthCodes.includes(response.status)) {
     if (unauthMsgBoxIsShow) return error;
     unauthMsgBoxIsShow = true;
     message = "身份验证失效,请重新登录";