zhangdan 3 years ago
parent
commit
9600e65c57
2 changed files with 34 additions and 33 deletions
  1. 32 31
      src/utils/request.js
  2. 2 2
      vue.config.js

+ 32 - 31
src/utils/request.js

@@ -4,15 +4,15 @@ import store from '@/store'
 import notification from 'ant-design-vue/es/notification'
 import modal from 'ant-design-vue/es/modal'
 import { VueAxios } from './axios'
- 
+
 // 创建 axios 实例
 const service = axios.create({
   baseURL: process.env.VUE_APP_API_BASE_URL, // api base_url
-  timeout: 10000 ,// 请求超时时间
+  timeout: 10000 // 请求超时时间
 })
 
 const err = (error) => {
-  let config = error.config;
+  const config = error.config
   // 网络连接出错
   if (error.message.indexOf('Network Error') >= 0) {
     notification.destroy()
@@ -23,7 +23,7 @@ const err = (error) => {
     store.commit('SET_loadingStatus', false)
     return Promise.reject(err)
   }
-  
+
   // 业务错误提示
   if (error.response) {
     const status = error.response.status
@@ -37,7 +37,7 @@ const err = (error) => {
     store.commit('SET_loadingStatus', false)
     return Promise.reject(err)
   }
-  
+
   // 超时无法访问服务
   if (error.message.indexOf('timeout') >= 0) {
     notification.destroy()
@@ -46,36 +46,36 @@ const err = (error) => {
       description: '网络连接超时,正在重连...'
     })
     // If config does not exist or the retry option is not set, reject
-    if(!config || !config.retry) return Promise.reject(err);
+    if (!config || !config.retry) return Promise.reject(err)
     // Set the variable for keeping track of the retry count
-    config.__retryCount = Vue.ls.get(config.url+'__retryCount') || 0;
+    config.__retryCount = Vue.ls.get(config.url + '__retryCount') || 0
     // Check if we've maxed out the total number of retries
-    if(config.__retryCount >= config.retry) {
-        Vue.ls.remove(config.url+'__retryCount')
-        notification.destroy()
-        notification.error({
-          message: '提示',
-          description: '网络重连失败,请检测网络连接是否正常'
-        })
-        store.commit('SET_loadingStatus', false)
-        // Reject with the error
-        return Promise.reject(err);
+    if (config.__retryCount >= config.retry) {
+      Vue.ls.remove(config.url + '__retryCount')
+      notification.destroy()
+      notification.error({
+        message: '提示',
+        description: '网络重连失败,请检测网络连接是否正常'
+      })
+      store.commit('SET_loadingStatus', false)
+      // Reject with the error
+      return Promise.reject(err)
     }
     // Increase the retry count
-    config.__retryCount += 1;
-    Vue.ls.set(config.url+'__retryCount',config.__retryCount)
+    config.__retryCount += 1
+    Vue.ls.set(config.url + '__retryCount', config.__retryCount)
     // Create new promise to handle exponential backoff
-    config.url = config.url.replace('/api','')
-    let backoff = new Promise(function(resolve) {
-        setTimeout(function() {
-            resolve();
-        }, config.retryDelay || 1);
-    });
-    
+    config.url = config.url.replace('/api', '')
+    const backoff = new Promise(function (resolve) {
+      setTimeout(function () {
+        resolve()
+      }, config.retryDelay || 1)
+    })
+
     // Return the promise in which recalls axios to retry the request
-    return backoff.then(function() {
-        return service(config);
-    });
+    return backoff.then(function () {
+      return service(config)
+    })
   }
 }
 
@@ -110,7 +110,7 @@ service.interceptors.response.use((response) => {
         })
       }
     })
-  }else if(response.data.status != 200 && response.data.status){
+  } else if (response.data.status != 200 && response.data.status) {
     // 其它业务错误提示
     notification.destroy()
     notification.error({
@@ -119,7 +119,8 @@ service.interceptors.response.use((response) => {
     })
   }
   store.commit('SET_loadingStatus', false)
-  return response.data
+  console.log(response)
+  return response
 }, err)
 
 const installer = {

+ 2 - 2
vue.config.js

@@ -108,9 +108,9 @@ const vueConfig = {
     // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
     proxy: {
       '/api': {
-        // target: 'http://192.168.16.103:8503/qpls-md',
+        target: 'http://192.168.16.107:7300/mock/61aad8ea5688cb3878d81e39/qpls-md',
         // target: 'https://t.qpls.360arrow.com/qpls-md', //  Á·Ï°
-        target: 'http://p.iscm.360arrow.com/qpls-md', //  Ô¤·¢²¼
+        // target: 'http://p.iscm.360arrow.com/qpls-md', //  Ô¤·¢²¼
         // target: 'http://qpls-md.360arrow.com/qpls-md', //  Éú²ú
         // ws: false,
         ws: true,