|
|
@@ -5,6 +5,7 @@ import axios from "axios";
|
|
|
import {getHttpMsg, localStorageGet} from "@utils/helpers";
|
|
|
import {LOCAL_SIGN} from "@constants/localkey";
|
|
|
import {toast} from "react-toastify";
|
|
|
+import LZString, {compress, compressToEncodedURIComponent, compressToUTF16, decompressFromBase64} from "lz-string";
|
|
|
|
|
|
// axios.defaults.withCredentials = true
|
|
|
const getSign=()=>{
|
|
|
@@ -40,7 +41,8 @@ const service = axios.create({
|
|
|
withCredentials: true,
|
|
|
timeout: 10000, // Request timeout
|
|
|
retry:2,//重复5次
|
|
|
- retryDelay:1000
|
|
|
+ retryDelay:1000,
|
|
|
+ compress:true
|
|
|
});
|
|
|
//出错重试 retry
|
|
|
const checkRetryRequest=(error)=>{
|
|
|
@@ -67,7 +69,26 @@ const checkRetryRequest=(error)=>{
|
|
|
// Request intercepter
|
|
|
service.interceptors.request.use(
|
|
|
config => {
|
|
|
- // console.log(config);
|
|
|
+ if (config.compress){
|
|
|
+ let data=config.ori_data;
|
|
|
+ if (data==null)data=config.data;
|
|
|
+ if (data){
|
|
|
+ let compressData=LZString.compressToBase64(JSON.stringify(data));
|
|
|
+ config.data = {
|
|
|
+ lz:compressData
|
|
|
+ }
|
|
|
+ config.ori_data=data;
|
|
|
+ }
|
|
|
+ let params=config.ori_params;
|
|
|
+ if (params==null)params=config.params;
|
|
|
+ if (params){
|
|
|
+ let compressParams=LZString.compressToBase64(JSON.stringify(params));
|
|
|
+ config.params = {
|
|
|
+ lz:compressParams
|
|
|
+ }
|
|
|
+ config.ori_params=params;
|
|
|
+ }
|
|
|
+ }
|
|
|
return config;
|
|
|
},
|
|
|
error => {
|
|
|
@@ -80,6 +101,16 @@ service.interceptors.request.use(
|
|
|
// response pre-processing
|
|
|
service.interceptors.response.use(
|
|
|
response => {
|
|
|
+ let data=response.data;
|
|
|
+ if (typeof data==="string"){
|
|
|
+ data=LZString.decompressFromBase64(data);
|
|
|
+ try {
|
|
|
+ response.data=JSON.parse(data);
|
|
|
+ }
|
|
|
+ catch(error){
|
|
|
+ console.log(error);
|
|
|
+ }
|
|
|
+ }
|
|
|
checkResponse(response.data);
|
|
|
return response.data;
|
|
|
},
|