Browse Source

Merge pull request #98 from fwfmiao/master

🐛 fix content-type error
good luck 4 years ago
parent
commit
2f1e44ecd7
1 changed files with 6 additions and 25 deletions
  1. 6 25
      src/utils/request.js

+ 6 - 25
src/utils/request.js

@@ -20,22 +20,6 @@ let loadingInstance;
 
 /**
  * @author chuzhixin 1204505056@qq.com (不想保留author可删除)
- * @description 判断当前url是否需要加loading
- * @param {*} config
- * @returns
- */
-const needLoading = (config) => {
-  let status = false;
-  debounce.forEach((item) => {
-    if (Vue.prototype.$baseLodash.includes(config.url, item)) {
-      status = true;
-    }
-  });
-  return status;
-};
-
-/**
- * @author chuzhixin 1204505056@qq.com (不想保留author可删除)
  * @description 处理code异常
  * @param {*} code
  * @param {*} msg
@@ -77,17 +61,14 @@ instance.interceptors.request.use(
         config.data,
         Vue.prototype.$baseLodash.identity
       );
-
     if (
-      contentType === "application/x-www-form-urlencoded;charset=UTF-8" &&
-      config.data
-    ) {
+      config.data &&
+      config.headers["Content-Type"] ===
+        "application/x-www-form-urlencoded;charset=UTF-8"
+    )
       config.data = qs.stringify(config.data);
-    }
-
-    if (needLoading(config)) {
+    if (debounce.some((item) => config.url.includes(item)))
       loadingInstance = Vue.prototype.$baseLoading();
-    }
     return config;
   },
   (error) => {
@@ -99,7 +80,7 @@ instance.interceptors.response.use(
   (response) => {
     if (loadingInstance) loadingInstance.close();
 
-    const { status, data, config } = response;
+    const { data, config } = response;
     const { code, msg } = data;
     // 操作正常Code数组
     const codeVerificationArray = isArray(successCode)