From d930b15104c7b2849a227367fa03742d8cf0e29f Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期二, 04 七月 2023 15:50:36 +0800
Subject: [PATCH] fix 修复 缓存监控图表 支持跟随屏幕大小自适应调整
---
src/utils/request.ts | 26 ++++++++++++++++----------
1 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/src/utils/request.ts b/src/utils/request.ts
index 5fe8f11..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,9 +23,12 @@
// 璇锋眰鎷︽埅鍣�
service.interceptors.request.use(
(config: InternalAxiosRequestConfig) => {
+ // 瀵瑰簲鍥介檯鍖栬祫婧愭枃浠跺悗缂�
+ config.headers['Content-Language'] = getLanguage();
+
const isToken = (config.headers || {}).isToken === false;
// 鏄惁闇�瑕侀槻姝㈡暟鎹噸澶嶆彁浜�
- const isRepeatSubmit = !(config.headers || {}).repeatSubmit;
+ const isRepeatSubmit = (config.headers || {}).repeatSubmit === false;
if (getToken() && !isToken) {
config.headers['Authorization'] = 'Bearer ' + getToken(); // 璁╂瘡涓姹傛惡甯﹁嚜瀹氫箟token 璇锋牴鎹疄闄呮儏鍐佃嚜琛屼慨鏀�
}
@@ -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