接近的并发请求,拦截器会弃置掉其中一个,导致业务数据丢失。

courseware
harry 5 years ago
parent a3b29b41af
commit f1543a5b5b

@ -3,25 +3,25 @@ import React from "react";
import axios from 'axios';
import md5 from 'md5';
import { requestProxy } from "./indexEduplus2RequestProxy";
import { broadcastChannelOnmessage ,SetAppModel, isDev, queryString } from 'educoder';
import { broadcastChannelOnmessage, SetAppModel, isDev, queryString } from 'educoder';
import { notification } from 'antd';
import cookie from 'react-cookies';
import './index.css';
const $ = window.$;
const opens ="79e33abd4b6588941ab7622aed1e67e8";
const opens = "79e33abd4b6588941ab7622aed1e67e8";
let timestamp;
let checkSubmitFlg = false;
let message501=false;
let message501 = false;
broadcastChannelOnmessage('refreshPage', () => {
window.location.reload()
})
function locationurl(list){
function locationurl(list) {
if (window.location.port === "3007") {
} else {
window.location.href=list
window.location.href = list
}
}
@ -30,7 +30,7 @@ function locationurl(list){
// TODO 开发期多个身份切换
let debugType =""
let debugType = ""
if (isDev) {
const _search = window.location.search;
let parsed = {};
@ -42,7 +42,7 @@ if (isDev) {
window.location.search.indexOf('debug=a') != -1 ? 'admin' : parsed.debug || 'admin'
}
// 超管
debugType="admin";
debugType = "admin";
// 老师
// debugType="teacher";
// 学生
@ -53,30 +53,30 @@ debugType="admin";
function clearAllCookie() {
cookie.remove('_educoder_session', {path: '/'});
cookie.remove('autologin_trustie', {path: '/'});
cookie.remove('_educoder_session', { path: '/' });
cookie.remove('autologin_trustie', { path: '/' });
setpostcookie()
}
clearAllCookie();
function setpostcookie() {
const str =window.location.pathname;
const str = window.location.pathname;
// console.log(str.indexOf("/wxcode"))
let newdomain=".educoder.net"
if(str.indexOf("/wxcode") !== -1){
let newdomain = ".educoder.net"
if (str.indexOf("/wxcode") !== -1) {
console.log("123")
cookie.remove('_educoder_session', {path: '/'});
cookie.remove('autologin_trustie', {path: '/'});
cookie.remove('_educoder_session', { path: '/' });
cookie.remove('autologin_trustie', { path: '/' });
// console.log("开始重写cookis");
const _params = window.location.search;
// console.log("1111");
if (_params) {
// console.log("22222");
let _search = _params.split('?')[1];
let _educoder_sessions= _search.split('&')[0].split('=');
cookie.save('_educoder_session',_educoder_sessions[1], { domain:'.educoder.net', path: '/'});
let autologin_trusties=_search.split('&')[1].split('=');
cookie.save('autologin_trustie',autologin_trusties[1], { domain:'.educoder.net', path: '/'});
let _educoder_sessions = _search.split('&')[0].split('=');
cookie.save('_educoder_session', _educoder_sessions[1], { domain: '.educoder.net', path: '/' });
let autologin_trusties = _search.split('&')[1].split('=');
cookie.save('autologin_trustie', autologin_trusties[1], { domain: '.educoder.net', path: '/' });
}
}
@ -84,31 +84,35 @@ function setpostcookie() {
setpostcookie();
function railsgettimes(proxy) {
function railsgettimes(proxy) {
clearAllCookie()
if(timestamp&&checkSubmitFlg===false){
$.ajax({url:proxy,async:false,success:function(data){
if(data.status===0){
timestamp=data.message;
if (timestamp && checkSubmitFlg === false) {
$.ajax({
url: proxy, async: false, success: function (data) {
if (data.status === 0) {
timestamp = data.message;
setpostcookie();
}
}})
checkSubmitFlg=true
window.setTimeout(()=>{
checkSubmitFlg=false;
}
})
checkSubmitFlg = true
window.setTimeout(() => {
checkSubmitFlg = false;
}, 2000);
}else if(checkSubmitFlg===false){
$.ajax({url:proxy,async:false,success:function(data){
if(data.status===0){
timestamp=data.message;
} else if (checkSubmitFlg === false) {
$.ajax({
url: proxy, async: false, success: function (data) {
if (data.status === 0) {
timestamp = data.message;
setpostcookie();
}
}})
checkSubmitFlg=true
window.setTimeout( ()=>{
checkSubmitFlg=false;
}
})
checkSubmitFlg = true
window.setTimeout(() => {
checkSubmitFlg = false;
}, 2000);
}
@ -131,8 +135,8 @@ export function initAxiosInterceptors(props) {
// proxy = "http://testbdweb.educoder.net"
// proxy = "https://testeduplus2.educoder.net"
//proxy="http://47.96.87.25:48080"
proxy="https://pre-newweb.educoder.net"
proxy="https://test-newweb.educoder.net"
proxy = "https://pre-newweb.educoder.net"
proxy = "https://test-newweb.educoder.net"
// proxy="https://test-jupyterweb.educoder.net"
// proxy="https://test-newweb.educoder.net"
// proxy="https://test-jupyterweb.educoder.net"
@ -143,7 +147,7 @@ export function initAxiosInterceptors(props) {
// 如果需要支持重复的请求考虑config里面自定义一个allowRepeat参考来控制
const requestMap = {};
window.setfalseInRequestMap = function(keyName) {
window.setfalseInRequestMap = function (keyName) {
requestMap[keyName] = false;
}
@ -222,19 +226,19 @@ export function initAxiosInterceptors(props) {
let url = `/api${config.url}`;
//qq登录去掉api
if(config.params&&config.params.redirect_uri!=undefined){
if(config.params.redirect_uri.indexOf('otherloginqq')!=-1){
if (config.params && config.params.redirect_uri != undefined) {
if (config.params.redirect_uri.indexOf('otherloginqq') != -1) {
url = `${config.url}`;
}
}
if(`${config[0]}`!=`true`){
let timestamp = Date.parse(new Date())/1000;
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)
railsgettimes(`${proxy}/api/main/first_stamp.json`);
let newopens = md5(opens + timestamp)
config.url = `${proxy}${url}`;
if (config.url.indexOf('?') == -1) {
config.url = `${config.url}?debug=${debugType}&randomcode=${timestamp}&client_key=${newopens}`;
@ -245,8 +249,8 @@ export function initAxiosInterceptors(props) {
// 加api前缀
// railsgettimes(`http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp`);
railsgettimes( `/api/main/first_stamp.json`);
let newopens=md5(opens+timestamp)
railsgettimes(`/api/main/first_stamp.json`);
let newopens = md5(opens + timestamp)
config.url = url;
if (config.url.indexOf('?') == -1) {
config.url = `${config.url}?randomcode=${timestamp}&client_key=${newopens}`;
@ -256,16 +260,15 @@ export function initAxiosInterceptors(props) {
}
setpostcookie();
}
//
// console.log(config);
if (requestMap[config.url] === true) {
return false;
}
// 拦截器导致关键的业务数据丢失,先注释
// if (requestMap[config.url] === true) {
// return false;
// }
// // 非file_update请求
if (config.url.indexOf('update_file') === -1) {
requestMap[config.url] = true;
window.setTimeout("setfalseInRequestMap('"+config.url+"')", 900)
window.setTimeout("setfalseInRequestMap('" + config.url + "')", 900)
}
// setTimeout("setfalseInRequestMap(" + config.url + ")", 1200)
return config;
@ -277,7 +280,7 @@ export function initAxiosInterceptors(props) {
axios.interceptors.response.use(function (response) {
// console.log(".............")
if(response===undefined){
if (response === undefined) {
return
}
const config = response.config
@ -290,10 +293,10 @@ export function initAxiosInterceptors(props) {
// message.info(response.data.message || '服务端返回status -1请联系管理员。');
// props.showSnackbar( response.data.message || '服务器异常,请联系管理员。' )
if (window.location.pathname.startsWith('/tasks/')) {
props.showSnackbar( response.data.message || '服务器异常,请联系管理员。' )
props.showSnackbar(response.data.message || '服务器异常,请联系管理员。')
} else {
notification.open({
message:"提示",
message: "提示",
description: response.data.message || '服务器异常,请联系管理员。',
style: {
zIndex: 99999999
@ -322,7 +325,7 @@ export function initAxiosInterceptors(props) {
// if(response.data.status === 401){
// console.log("401401401")
// }
if (response.data.status === 403||response.data.status === "403") {
if (response.data.status === 403 || response.data.status === "403") {
locationurl('/403');
}
@ -336,18 +339,18 @@ export function initAxiosInterceptors(props) {
}
if (response.data.status === 501) {
if(message501===false){
message501=true
if (message501 === false) {
message501 = true
notification.open({
message:"提示",
description:response.data.message || '访问异常,请求不合理',
message: "提示",
description: response.data.message || '访问异常,请求不合理',
style: {
zIndex: 99999999
}
})
}
window.setTimeout(function () {
message501=false
message501 = false
}, 2000);
}
@ -382,7 +385,7 @@ export function initAxiosInterceptors(props) {
}, function (error) {
return Promise.reject(error);
});
// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------
}

Loading…
Cancel
Save