Browse Source

http://localhost:7000

pzc 4 years ago
parent
commit
fdff1e9d4a
2 changed files with 26 additions and 16 deletions
  1. 2 1
      UI/src/utils/config.js
  2. 24 15
      UI/src/utils/request.js

+ 2 - 1
UI/src/utils/config.js

@@ -15,6 +15,7 @@ module.exports =  {
   CORS: ['http://localhost:8000', 
   'http://localhost:8030',
   'http://localhost:8004',
+    'http://localhost:7000',
   'https://coop.360lj.com',
   'http://localhost:7777','http://119.130.113.245:7777'],
   //YQL: ['http://localhost:57251'],
@@ -55,4 +56,4 @@ module.exports =  {
     permissions:`${APIV3Auth}/ums/oauth2/list/permission?types=2`,
   },
   JAPIV, 
-}
+}

+ 24 - 15
UI/src/utils/request.js

@@ -8,6 +8,7 @@ import { message } from 'antd'
 import config from './config'
 import util from './util';
 import router from 'umi/router';
+import permission from './permission'
 
 
 const fetch = (options) => {
@@ -71,21 +72,29 @@ const fetch = (options) => {
   );
 
   //拦截器
-  // axios.interceptors.response.use(
-  // response => {
-  //   return response
-  // },
-  // error => {
-  //   if (error.response) {
-  //     switch (error.response.status) {
-  //       case 401:
-  //         // 返回 401 清除token信息并跳转到登录页面
-  //         confirm('过期')
-  //         // router.push('/login');
-  //     }
-  //   }
-  //   return Promise.reject(error.response.data)   // 返回接口返回的错误信息
-  // });
+  axios.interceptors.response.use(
+  response => {
+    if(response.data && response.data.result.messageCode){
+      util.auth.removeToken();
+      permission.clear();
+      confirm('过期')
+      router.push('/login');
+    }
+    return response
+  },
+  error => {
+    if (error.response) {
+      switch (error.response.status) {
+        case 401:
+          // 返回 401 清除token信息并跳转到登录页面
+          util.auth.removeToken();
+          permission.clear();
+          confirm('过期')
+          router.push('/login');
+      }
+    }
+    return Promise.reject(error.response.data)   // 返回接口返回的错误信息
+  });
 
   switch (method.toLowerCase()) {
     case 'get':