From 20f64b54d55603a63bbae959dbf3112de8a96c5f Mon Sep 17 00:00:00 2001
From: LiuHao <liuhaoai545@gmail>
Date: 星期三, 19 四月 2023 11:05:30 +0800
Subject: [PATCH] fix 修改国际化文件名称不规范问题,增加reqeust 国际化配置

---
 src/utils/request.ts |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/utils/request.ts b/src/utils/request.ts
index 14c33f8..d5fac4e 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -1,4 +1,4 @@
-import axios, { InternalAxiosRequestConfig } from 'axios';
+import axios, { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
 import { useUserStore } from '@/store/modules/user';
 import { getToken } from '@/utils/auth';
 import { tansParams, blobValidate } from '@/utils/ruoyi';
@@ -7,14 +7,13 @@
 import { errorCode } from '@/utils/errorCode';
 import { LoadingInstance } from 'element-plus/es/components/loading/src/loading';
 import FileSaver from 'file-saver';
+import { getLanguage } from '@/lang';
 
 let downloadLoadingInstance: LoadingInstance;
 // 鏄惁鏄剧ず閲嶆柊鐧诲綍
 export const isRelogin = { show: false };
 
 axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';
-// 瀵瑰簲鍥介檯鍖栬祫婧愭枃浠跺悗缂�
-axios.defaults.headers['Content-Language'] = 'zh_CN';
 // 鍒涘缓 axios 瀹炰緥
 const service = axios.create({
   baseURL: import.meta.env.VITE_APP_BASE_API,
@@ -24,6 +23,9 @@
 // 璇锋眰鎷︽埅鍣�
 service.interceptors.request.use(
   (config: InternalAxiosRequestConfig) => {
+    // 瀵瑰簲鍥介檯鍖栬祫婧愭枃浠跺悗缂�
+    config.headers['Content-Language'] = getLanguage();
+
     const isToken = (config.headers || {}).isToken === false;
     // 鏄惁闇�瑕侀槻姝㈡暟鎹噸澶嶆彁浜�
     const isRepeatSubmit = (config.headers || {}).repeatSubmit === false;
@@ -61,6 +63,10 @@
         }
       }
     }
+    // FormData鏁版嵁鍘昏姹傚ごContent-Type
+    if (config.data instanceof FormData) {
+      delete config.headers['Content-Type'];
+    }
     return config;
   },
   (error: any) => {
@@ -71,7 +77,7 @@
 
 // 鍝嶅簲鎷︽埅鍣�
 service.interceptors.response.use(
-  (res) => {
+  (res: AxiosResponse) => {
     // 鏈缃姸鎬佺爜鍒欓粯璁ゆ垚鍔熺姸鎬�
     const code = res.data.code || HttpStatus.SUCCESS;
     // 鑾峰彇閿欒淇℃伅
@@ -112,7 +118,7 @@
       return Promise.resolve(res.data);
     }
   },
-  (error) => {
+  (error: any) => {
     let { message } = error;
     if (message == 'Network Error') {
       message = '鍚庣鎺ュ彛杩炴帴寮傚父';
@@ -131,16 +137,16 @@
   // prettier-ignore
   return service.post(url, params, {
       transformRequest: [
-        (params) => {
+        (params: any) => {
           return tansParams(params);
         }
       ],
       headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
       responseType: 'blob'
-    }).then(async (resp) => {
+    }).then(async (resp: any) => {
       const isLogin = blobValidate(resp);
       if (isLogin) {
-        const blob = new Blob([resp as any]);
+        const blob = new Blob([resp]);
         FileSaver.saveAs(blob, fileName);
       } else {
         const resText = await resp.data.text();
@@ -149,7 +155,7 @@
         ElMessage.error(errMsg);
       }
       downloadLoadingInstance.close();
-    }).catch((r) => {
+    }).catch((r: any) => {
       console.error(r);
       ElMessage.error('涓嬭浇鏂囦欢鍑虹幇閿欒锛岃鑱旂郴绠$悊鍛橈紒');
       downloadLoadingInstance.close();

--
Gitblit v1.9.3