拦截器拦截接近的请求,会导致关键数据丢失,很麻烦

dev_aliyun2
harry 5 years ago
parent df49f2fd78
commit 43c2f19eb9

@ -87,23 +87,27 @@ setpostcookie();
clearAllCookie()
if (timestamp && checkSubmitFlg === false) {
$.ajax({url:proxy,async:false,success:function(data){
$.ajax({
url: proxy, async: false, success: function (data) {
if (data.status === 0) {
timestamp = data.message;
setpostcookie();
}
}})
}
})
checkSubmitFlg = true
window.setTimeout(() => {
checkSubmitFlg = false;
}, 2000);
} else if (checkSubmitFlg === false) {
$.ajax({url:proxy,async:false,success:function(data){
$.ajax({
url: proxy, async: false, success: function (data) {
if (data.status === 0) {
timestamp = data.message;
setpostcookie();
}
}})
}
})
checkSubmitFlg = true
window.setTimeout(() => {
checkSubmitFlg = false;
@ -113,9 +117,6 @@ setpostcookie();
}
window._debugType = debugType;
export function initAxiosInterceptors(props) {
initOnlineOfflineListener()
@ -150,68 +151,6 @@ export function initAxiosInterceptors(props) {
config => {
setpostcookie()
clearAllCookie()
// config.headers['Content-Type']= 'no-cache'
// if (token) { // 每次发送请求之前判断是否存在token如果存在则统一在http请求的header都加上token不用每次请求都手动添加了
// config.headers.Authorization = token;
// }
// --------------------------------------------- 測試3007连测试服的代码
// if (url.indexOf('file_update') != -1 || url.indexOf('game_build') != -1 || url.indexOf('game_status') != -1) {
// proxy = 'https://testbdweb.trustie.net'
// } else {
// proxy = 'http://localhost:3000'
// }
// ---------------------------------------------
// console.log("开始请求了");
// console.log(config.url);
// console.log(window.location.pathname);
//
// try {
// const str =window.location.pathname;
// if(str.indexOf("/wxcode") !== -1){
// // console.log("开始重写cookis");
// const _params = window.location.search;
// // console.log("1111");
// if (_params) {
// // console.log("22222");
// let _search = _params.split('?')[1];
// var _educoder_sessionmys="";
// var autologin_trusties="";
// _search.split('&').forEach(item => {
// const _arr = item.split('=');
// if(_arr[0]==='_educoder_session'){
// cookie.save('_educoder_session',_arr[1], { domain: '.educoder.net', path: '/'});
// _educoder_sessionmys=_arr[1];
// }else{
// cookie.save('autologin_trustie',_arr[1], { domain: '.educoder.net', path: '/'});
// autologin_trusties=_arr[1];
// }
// });
// try {
// const autlogins= `_educoder_session=${_educoder_sessionmys}; autologin_trustie=${autologin_trusties} `;
// config.params = {'Cookie': autlogins}
// config.headers['Cookie'] =autlogins;
// // console.log("设置了cookis");
// } catch (e) {
//
// }
// try {
// const autloginysls= `_educoder_session=${_educoder_sessionmys}; autologin_trustie=${autologin_trusties} `;
// config.params = {'autloginysls': autloginysls}
// config.headers['Cookie'] =autloginysls;
// // console.log("设置了cookis");
// }catch (e) {
//
// }
// }
// }
// }catch (e) {
//
// }
if (config.url.indexOf(proxy) != -1 || config.url.indexOf(':') != -1) {
return config
}
@ -228,8 +167,6 @@ export function initAxiosInterceptors(props) {
if (`${config[0]}` != `true`) {
let timestamp = Date.parse(new Date()) / 1000;
if (window.location.port === "3007") {
// let timestamp=railsgettimes(proxy);
// console.log(timestamp)
// `https://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp`
railsgettimes(`${proxy}/api/main/first_stamp.json`);
let newopens = md5(opens + timestamp)
@ -254,18 +191,14 @@ export function initAxiosInterceptors(props) {
}
setpostcookie();
}
//
// console.log(config);
if (requestMap[config.url] === true) {
return false;
}
// // 非file_update请求
// 这里拦截掉请求, 会导致正常的业务丢失关键数据。。很麻烦
// if (requestMap[config.url] === true) {
// return false;
// }
if (config.url.indexOf('update_file') === -1) {
requestMap[config.url] = true;
window.setTimeout("setfalseInRequestMap('" + config.url + "')", 900)
}
// setTimeout("setfalseInRequestMap(" + config.url + ")", 1200)
return config;
},
err => {
@ -274,15 +207,11 @@ export function initAxiosInterceptors(props) {
axios.interceptors.response.use(function (response) {
// console.log(".............")
if (response === undefined) {
return
}
const config = response.config
if (response.data.status === -1) {
// console.error('error:', response.data.message)
// throw new Error()
// https://github.com/axios/axios/issues?utf8=%E2%9C%93&q=cancel+request+in+response+interceptors+
// https://github.com/axios/axios/issues/583
// message.info(response.data.message || '服务端返回status -1请联系管理员。');
@ -297,31 +226,11 @@ export function initAxiosInterceptors(props) {
zIndex: 99999999
},
});
// notification['error']({
// message:"提示",
// description: response.data.message || '服务器异常,请联系管理员。',
// });
}
throw new axios.Cancel('Operation canceled by the user.');
} else {
// hash跳转
// var hash = window.location.hash;
// if (hash) {
// hashTimeout && window.clearTimeout(hashTimeout)
// hashTimeout = setTimeout(() => {
// var element = document.querySelector(hash);
// if (element) {
// element.scrollIntoView();
// }
// }, 400)
// }
}
// if(response.data.status === 401){
// console.log("401401401")
// }
if (response.data.status === 403 || response.data.status === "403") {
locationurl('/403');
}
@ -349,38 +258,12 @@ export function initAxiosInterceptors(props) {
}, 2000);
}
// if (response.data.status === 402) {
// console.log(response.data.status);
// console.log(response.data);
// // locationurl(402);
// }
//
// if (response.data.status === 401) {
// console.log("161");
// console.log(config);
// return config;
// }
// if (response.data.status === 407) {
// 在app js 中解决 Trialapplication
// // </Trialapplication>
// ///在appjs
// notification.open({
// message:"提示",
// description: "账号未认证",
// });
// throw new axios.Cancel('Operation canceled by the user.');
// //
// }
requestMap[response.config.url] = false;
setpostcookie();
return response;
}, function (error) {
return Promise.reject(error);
});
// -----------------------------------------------------------------------------------
}

Loading…
Cancel
Save