|
|
|
@ -2,7 +2,7 @@
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
import md5 from 'md5';
|
|
|
|
|
import { requestProxy } from "./indexEduplus2RequestProxy";
|
|
|
|
|
import { broadcastChannelOnmessage, isDev, queryString } from './common/educoder';
|
|
|
|
|
import { isDev, queryString } from './common/educoder';
|
|
|
|
|
import { notification } from 'antd';
|
|
|
|
|
import cookie from 'react-cookies';
|
|
|
|
|
import './index.css';
|
|
|
|
@ -12,10 +12,6 @@ let timestamp;
|
|
|
|
|
let checkSubmitFlg = false;
|
|
|
|
|
let message501 = false;
|
|
|
|
|
|
|
|
|
|
broadcastChannelOnmessage('refreshPage', () => {
|
|
|
|
|
window.location.reload()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
function locationurl(list) {
|
|
|
|
|
if (window.location.port === "3007") {
|
|
|
|
|
|
|
|
|
@ -53,7 +49,6 @@ function setpostcookie() {
|
|
|
|
|
|
|
|
|
|
const str = window.location.pathname;
|
|
|
|
|
if (str.indexOf("/wxcode") !== -1) {
|
|
|
|
|
console.log("123")
|
|
|
|
|
cookie.remove('_educoder_session', { path: '/' });
|
|
|
|
|
cookie.remove('autologin_trustie', { path: '/' });
|
|
|
|
|
const _params = window.location.search;
|
|
|
|
@ -111,23 +106,9 @@ function railsgettimes(proxy) {
|
|
|
|
|
window._debugType = debugType;
|
|
|
|
|
export function initAxiosInterceptors(props) {
|
|
|
|
|
initOnlineOfflineListener()
|
|
|
|
|
|
|
|
|
|
// TODO 避免重复的请求 https://github.com/axios/axios#cancellation
|
|
|
|
|
// https://github.com/axios/axios/issues/1497
|
|
|
|
|
|
|
|
|
|
// TODO 读取到package.json中的配置?
|
|
|
|
|
var proxy = "http://localhost:3000"
|
|
|
|
|
// proxy = "http://testbdweb.trustie.net"
|
|
|
|
|
// 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://test-jupyterweb.educoder.net"
|
|
|
|
|
// proxy="https://test-newweb.educoder.net"
|
|
|
|
|
// proxy="https://test-jupyterweb.educoder.net"
|
|
|
|
|
//proxy="http://192.168.2.63:3001"
|
|
|
|
|
|
|
|
|
|
let proxy = "https://test-newweb.educoder.net"
|
|
|
|
|
|
|
|
|
|
// 在这里使用requestMap控制,避免用户通过双击等操作发出重复的请求;
|
|
|
|
|
// 如果需要支持重复的请求,考虑config里面自定义一个allowRepeat参考来控制
|
|
|
|
@ -171,21 +152,15 @@ 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)
|
|
|
|
|
config.url = `${proxy}${url}`;
|
|
|
|
|
if (config.url.indexOf('?') == -1) {
|
|
|
|
|
config.url = `${config.url}?debug=${debugType}&randomcode=${timestamp}&client_key=${newopens}`;
|
|
|
|
|
config.url = `${config.url}?randomcode=${timestamp}&client_key=${newopens}`;
|
|
|
|
|
} else {
|
|
|
|
|
config.url = `${config.url}&debug=${debugType}&randomcode=${timestamp}&client_key=${newopens}`;
|
|
|
|
|
config.url = `${config.url}&&randomcode=${timestamp}&client_key=${newopens}`;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 加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)
|
|
|
|
|
config.url = url;
|
|
|
|
@ -197,14 +172,8 @@ export function initAxiosInterceptors(props) {
|
|
|
|
|
}
|
|
|
|
|
setpostcookie();
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
// console.log(config);
|
|
|
|
|
if (config.method === "post") {
|
|
|
|
|
if (requestMap[config.url] === true) { // 避免重复的请求 导致页面f5刷新 也会被阻止 显示这个方法会影响到定制信息
|
|
|
|
|
// console.log(config);
|
|
|
|
|
// console.log(JSON.parse(config));
|
|
|
|
|
// console.log(config.url);
|
|
|
|
|
// console.log("被阻止了是重复请求=================================");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -223,11 +192,9 @@ 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()
|
|
|
|
|