屏掉跨页面刷新

dev_aliyun2
harry 5 years ago
parent b4881824cb
commit 77c1f04d35

@ -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()

@ -4,7 +4,7 @@ export function trigger(eventName, data) {
}
export function on(eventName, callback) {
$(window).on(eventName, (event, data)=>{
$(window).on(eventName, (event, data) => {
callback && callback(event, data)
});
}
@ -25,7 +25,7 @@ function onMessageByLocalStorage(eventName, callback) {
console.log('storage event register:', eventName)
localStorageMap[eventName] = callback;
}
window.addEventListener("storage", function(ev) {
window.addEventListener("storage", function (ev) {
const cb = localStorageMap[ev.key];
// console.log('storage event:', ev)
if (cb) {
@ -64,7 +64,6 @@ export function broadcastChannelOnmessage(eventName, callback) {
bc = broadcastChannelMap[eventName]
}
bc.onmessage = function (ev) {
console.log(ev);
callback && callback(ev)
}
}

@ -300,11 +300,9 @@ class LoginDialog extends Component {
}
componentWillReceiveProps(nextProps) {
this.setState({
isRender: nextProps.isRender
})
// console.log(nextProps.isRender);
}
IsPC = () => {
@ -333,12 +331,6 @@ class LoginDialog extends Component {
})
}
// $(document).on("showLoginDialog", (e, args)=>{
// this.setState({
// isRender: true
// })
// })
this.dragWrapper();
axios.interceptors.response.use((response) => {
@ -385,7 +377,6 @@ class LoginDialog extends Component {
if (response.status === 200) {
if (response.data.status === 402) {
// window.location.href = response.data.url;
} else if (response.data.status === -2) {
if (response.data.message === "登录密码出错已达上限,账号已被锁定, 请10分钟后重新登录或找回密码") {
const messge = (
@ -410,22 +401,15 @@ class LoginDialog extends Component {
});
}
} else {
broadcastChannelPostMessage('refreshPage')
broadcastChannelPostMessage('refreshPage', response.data)
this.setState({
isRender: false
})
this.props.Modifyloginvalue();
window.location.reload();
window.location.reload()
}
}
// try {
// this.props.Modifyloginvalue();
// }catch (e) {
//
// }
}).catch((error) => {
console.log("356");
console.log(error)
@ -515,18 +499,6 @@ class LoginDialog extends Component {
setNotcompleteds={() => { this.setNotcompleteds() }}
/>
{/*{this.state.isphone===false||this.props.user&&this.props.user.main_site===false?<style>*/}
{/*{*/}
{/*`*/}
{/*#DialogID .dialogBox {*/}
{/*width: 405px !important;*/}
{/*}*/}
{/*.dialogBox {*/}
{/*height: 290px !important;*/}
{/*}*/}
{/*`*/}
{/*}*/}
{/*</style>:""}*/}
<style>
{
`

@ -1,11 +1,6 @@
import React, { Component } from 'react';
import { Redirect } from 'react-router';
import { BrowserRouter as Router, Route, Link, Switch } from "react-router-dom";
import { Route, Switch } from "react-router-dom";
import Loading from '../../Loading'
import Loadable from 'react-loadable';
import { TPMIndexHOC } from '../tpm/TPMIndexHOC'
import { SnackbarHOC } from 'educoder'
@ -22,7 +17,7 @@ class Topic_bank extends Component {
super(props)
}
componentDidMount(){
componentDidMount() {
}
render() {
@ -31,15 +26,15 @@ class Topic_bank extends Component {
<Switch>
<Route path="/topicbank/:username/:topicstype"
render={
(props) => (<PackageIndex {...this.props} {...props} {...this.state} />)
}
render={
(props) => (<PackageIndex {...this.props} {...props} {...this.state} />)
}
></Route>
<Route path="/topicbank/:topicstype"
render={
(props) => (<PackageIndex {...this.props} {...props} {...this.state} />)
}
render={
(props) => (<PackageIndex {...this.props} {...props} {...this.state} />)
}
></Route>
</Switch>
@ -48,4 +43,4 @@ class Topic_bank extends Component {
}
}
export default SnackbarHOC() (TPMIndexHOC (Topic_bank)) ;
export default SnackbarHOC()(TPMIndexHOC(Topic_bank));

@ -11,6 +11,8 @@ import LoginDialog from '../login/LoginDialog';
import AccountProfile from '../user/AccountProfile';
import AccountPhoneemail from '../user/AccountPhoneemail';
import { broadcastChannelOnmessage } from 'educoder';
const $ = window.$;
let _url_origin = '';
@ -120,7 +122,6 @@ export function TPMIndexHOC(WrappedComponent) {
window.addEventListener('keyup', this.keyupListener)
if (this.props.match.path === "/") {
// document.title="创新源于实践";
} else if (this.props.match.path === "/403") {
document.title = "你没有权限访问";
} else if (this.props.match.path === "/nopage") {
@ -139,10 +140,6 @@ export function TPMIndexHOC(WrappedComponent) {
//帮助后台传参数
const query = this.props.location.search;
// const type = query.split('?chinaoocTimestamp=');
// console.log("Eduinforms12345");
// console.log(this.foo(query));
// console.log(JSON.stringify(this.foo(query)));
var dataqueryss = {}
try {
var foqus = this.foo(query);
@ -167,8 +164,6 @@ export function TPMIndexHOC(WrappedComponent) {
axios.get(url, {
}).then((response) => {
// console.log("开始请求/get_navigation_info.json");
// console.log(response);
if (response != undefined) {
if (response.status === 200) {
this.setState({
@ -242,13 +237,6 @@ export function TPMIndexHOC(WrappedComponent) {
return this.state.current_user ? this.state.current_user.course_is_end : false
}
// setTrialapplication = ()=>{
// this.setState({
// isRenders:true
// })
//
// }
//获取数据为空的时候
gettablogourlnull = () => {
this.setState({
@ -284,9 +272,6 @@ export function TPMIndexHOC(WrappedComponent) {
try {
var chromesettingArray = JSON.parse(localStorage.getItem('chromesetting'));
var chromesettingresponseArray = JSON.parse(localStorage.getItem('chromesettingresponse'));
// console.log("TPMLNdexHOC");
// console.log(chromesettingArray);
// console.log(chromesettingresponseArray);
this.setState({
mygetHelmetapi: chromesettingArray
});
@ -369,11 +354,7 @@ export function TPMIndexHOC(WrappedComponent) {
axios.get(url, {
params:
datay
},
{
// withCredentials: true
}
).then((response) => {
}).then((response) => {
/*
{
"username": "黄井泉",
@ -620,11 +601,6 @@ export function TPMIndexHOC(WrappedComponent) {
scrollToAnchor: this.scrollToAnchor
};
// console.log("this.props.mygetHelmetapi");
// console.log(this.props.mygetHelmetapi);
// console.log("WrappedComponent");
// console.log(this.props);
// console.log(this.props.match.path);
var mypath = this.props && this.props.match && this.props.match.path;
return (
<div className="indexHOC">

Loading…
Cancel
Save