Browse Source

优化请求拦截器:移除qiankun相关逻辑,改用window.fetchNew处理响应数据

yusheng 7 months ago
parent
commit
5f1ae0ad0b
1 changed files with 34 additions and 27 deletions
  1. 34 27
      src/utils/request.js

+ 34 - 27
src/utils/request.js

@@ -49,11 +49,18 @@ service.interceptors.response.use(
   (res) => {
     // token 自动续期
 
-    if (window.__POWERED_BY_QIANKUN__) {
-      console.log('主应用的 window 对象:', window.parent);
-      if (window.parentWindow) {
-        window.parentWindow.businessstatus = res;
-      }
+    // if (window.__POWERED_BY_QIANKUN__) {
+    //   console.log('主应用的 window 对象:', window.parent);
+    //   if (window.parentWindow&&window.parentWindow?.fetchNew ) {
+
+    //   }
+    // }
+    if (window.fetchNew) {
+      window.fetchNew({
+        code: res.data.code,
+        message: res.data.message,
+        apiUrl: res.config.url
+      });
     }
 
     // && res.config?.showErrorToast !== false
@@ -87,28 +94,28 @@ service.interceptors.response.use(
     //   }
     // }
     // 登录过期处理
-    if (error?.response?.status === 401) {
-      const currentPath = router.currentRoute.path;
-      if (currentPath === LAYOUT_PATH) {
-        logout(true);
-      } else {
-        MessageBox.alert('登录状态已过期, 请退出重新登录!', '系统提示', {
-          confirmButtonText: '重新登录',
-          callback: (action) => {
-            if (action === 'confirm') {
-              logout(false, currentPath);
-            }
-          },
-          beforeClose: () => {
-            MessageBox.close();
-          }
-        });
-      }
-      return Promise.reject(new Error(error.response.data?.message));
-    } else if (!error?.response?.status) {
-      Message.error('服务调用失败,请联系管理员!');
-    }
-    return Promise.reject(error);
+    // if (error?.response?.status === 401) {
+    //   const currentPath = router.currentRoute.path;
+    //   if (currentPath === LAYOUT_PATH) {
+    //     logout(true);
+    //   } else {
+    //     MessageBox.alert('登录状态已过期, 请退出重新登录!', '系统提示', {
+    //       confirmButtonText: '重新登录',
+    //       callback: (action) => {
+    //         if (action === 'confirm') {
+    //           logout(false, currentPath);
+    //         }
+    //       },
+    //       beforeClose: () => {
+    //         MessageBox.close();
+    //       }
+    //     });
+    //   }
+    //   return Promise.reject(new Error(error.response.data?.message));
+    // } else if (!error?.response?.status) {
+    //   Message.error('服务调用失败,请联系管理员!');
+    // }
+    // return Promise.reject(error);
   }
 );