fix 拦截器

courseware
harry 5 years ago
parent f98cadd00c
commit 1ab6569f22

@ -2,7 +2,7 @@ import React, { Component } from 'react';
import { BrowserRouter as Router, Route, Link, Switch } from "react-router-dom"; import { BrowserRouter as Router, Route, Link, Switch } from "react-router-dom";
import { Row, Col ,Menu,Popover,Button} from 'antd'; import { Row, Col, Menu, Popover, Button } from 'antd';
import Loading from '../../Loading'; import Loading from '../../Loading';
@ -134,7 +134,7 @@ const AddFile = Loadable({
loading: Loading, loading: Loading,
}) })
// 版本库上传文件 // 版本库上传文件
const Uploadfile= Loadable({ const Uploadfile = Loadable({
loader: () => import('./shixunchild/Repository/RepositoryAddFileupload_file'), loader: () => import('./shixunchild/Repository/RepositoryAddFileupload_file'),
loading: Loading, loading: Loading,
}) })
@ -152,49 +152,49 @@ class TPMIndex extends Component {
shixunId: undefined, shixunId: undefined,
star_info: [0, 0, 0, 0, 0, 0], star_info: [0, 0, 0, 0, 0, 0],
star_infos: [0, 0, 0, 0, 0, 0], star_infos: [0, 0, 0, 0, 0, 0],
identity:undefined, identity: undefined,
TPMRightSectionData:undefined, TPMRightSectionData: undefined,
PropaedeuticsList: undefined, PropaedeuticsList: undefined,
tpmindexjupyterbool:false, tpmindexjupyterbool: false,
is_jupyter:false, is_jupyter: false,
selectedKeys:"", selectedKeys: "",
openknows:false, openknows: false,
newathArray:[] newathArray: []
} }
} }
openknow=()=>{ openknow = () => {
let storage=window.localStorage; let storage = window.localStorage;
this.setState({ this.setState({
openknows:false openknows: false
}) })
let newTPMsettings=this.props.user&&this.props.user.user_id+'newTPMsettings' let newTPMsettings = this.props.user && this.props.user.user_id + 'newTPMsettings'
storage.setItem(newTPMsettings,false); storage.setItem(newTPMsettings, false);
} }
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
if (prevProps!=this.props) { if (prevProps != this.props) {
if(this.props.user&&this.props.user.user_id){ if (this.props.user && this.props.user.user_id) {
let getnewTPMsettings=this.props.user&&this.props.user.user_id+'newTPMsettings'; let getnewTPMsettings = this.props.user && this.props.user.user_id + 'newTPMsettings';
let newTPMsettings=window.localStorage.getItem(getnewTPMsettings) let newTPMsettings = window.localStorage.getItem(getnewTPMsettings)
if(newTPMsettings===undefined||newTPMsettings===false||newTPMsettings===null){ if (newTPMsettings === undefined || newTPMsettings === false || newTPMsettings === null) {
this.setState({ this.setState({
openknows:false openknows: false
}) })
}else{ } else {
this.setState({ this.setState({
openknows:false openknows: false
}) })
} }
} }
} }
} }
getcomponentdidmount=()=>{ getcomponentdidmount = () => {
let userid=this.props.user&&this.props.user.user_id; let userid = this.props.user && this.props.user.user_id;
let getnewTPMsettings=this.props.user&&this.props.user.user_id+'newTPMsettings'; let getnewTPMsettings = this.props.user && this.props.user.user_id + 'newTPMsettings';
let newTPMsettings=window.localStorage.getItem(getnewTPMsettings) let newTPMsettings = window.localStorage.getItem(getnewTPMsettings)
let id = this.props.match.params.shixunId; let id = this.props.match.params.shixunId;
// console.log('props', this.props); // console.log('props', this.props);
// let collaborators = `/shixuns/` + id + `/propaedeutics.json`; // let collaborators = `/shixuns/` + id + `/propaedeutics.json`;
@ -217,7 +217,7 @@ class TPMIndex extends Component {
let Url = `/shixuns/` + id + `.json`; let Url = `/shixuns/` + id + `.json`;
axios.get(Url).then((response) => { axios.get(Url).then((response) => {
if (response.status === 200) { if (response.status === 200) {
document.title=response.data.name; document.title = response.data.name;
let newstar_info = []; let newstar_info = [];
// let start1= // let start1=
for (var i = 0; i < response.data.score_info.length; i++) { for (var i = 0; i < response.data.score_info.length; i++) {
@ -236,23 +236,23 @@ class TPMIndex extends Component {
star_infos: newstar_infos, star_infos: newstar_infos,
power: response.data.power, power: response.data.power,
identity: response.data.identity, identity: response.data.identity,
propaedeutics:response.data.propaedeutics, propaedeutics: response.data.propaedeutics,
status: response.data.shixun_status, status: response.data.shixun_status,
secret_repository: response.data.secret_repository, secret_repository: response.data.secret_repository,
public:response.data.public, public: response.data.public,
is_jupyter:response.data.is_jupyter=== undefined||response.data.is_jupyter===null?false:response.data.is_jupyter, is_jupyter: response.data.is_jupyter === undefined || response.data.is_jupyter === null ? false : response.data.is_jupyter,
}); });
if(userid){ if (userid) {
if(response.data.identity <4){ if (response.data.identity < 4) {
if(newTPMsettings===undefined||newTPMsettings===false||newTPMsettings===null){ if (newTPMsettings === undefined || newTPMsettings === false || newTPMsettings === null) {
console.log() console.log()
this.setState({ this.setState({
openknows:true openknows: true
}) })
}else{ } else {
this.setState({ this.setState({
openknows:false openknows: false
}) })
} }
} }
@ -268,49 +268,15 @@ class TPMIndex extends Component {
power: undefined, power: undefined,
identity: undefined, identity: undefined,
status: undefined, status: undefined,
propaedeutics:undefined, propaedeutics: undefined,
is_jupyter:false, is_jupyter: false,
}); });
}); });
// this.tpmContentRequestInterceptor = axios.interceptors.request.use((config) => {
// let url = config.url;
// // console.log('tpmContentRequestInterceptor:', url)
// for ( let i = 0; i < interceptorUrlArray.length; i++ ) {
// if (url.indexOf(interceptorUrlArray[i]) != -1) {
// url = url.split('?')[0]
// console.log('loadingContent, url:', url)
//
// this.setState({ loadingContent: true })
//
// cacheInterceptorUrlMap[url] = true
// }
// }
// return config;
// }, function (error) {
// return Promise.reject(error);
// });
// Add a response interceptor
this.tpmContentResponseInterceptor = axios.interceptors.response.use((response) => {
// console.log('loadingContent finished, url:', response.config.url)
// TODO 依赖了api这个前缀
let url = response.config.url.split('api')[1];
url = url.split('?')[0]
if (cacheInterceptorUrlMap[url]) {
this.setState({ loadingContent: false })
delete cacheInterceptorUrlMap[response.url]
}
return response;
}, function (error) {
// Do something with response error
return Promise.reject(error);
});
//右侧数据 //右侧数据
let shixunsDetailsURL=`/shixuns/`+id+`/show_right.json`; let shixunsDetailsURL = `/shixuns/` + id + `/show_right.json`;
axios.get(shixunsDetailsURL).then((response)=> { axios.get(shixunsDetailsURL).then((response) => {
if(response.data){ if (response.data) {
} }
this.setState({ this.setState({
@ -324,83 +290,75 @@ class TPMIndex extends Component {
} }
componentWillUnmount = () => {
axios.interceptors.request.eject(this.tpmContentRequestInterceptor);
this.tpmContentRequestInterceptor = null;
axios.interceptors.request.eject(this.tpmContentResponseInterceptor);
this.tpmContentResponseInterceptor = null;
// this.getnavdatas()
}
setLoadingContent = (isLoadingContent) => { setLoadingContent = (isLoadingContent) => {
// this.setState({ loadingContent: isLoadingContent }) // this.setState({ loadingContent: isLoadingContent })
} }
getnavdatas=()=>{ getnavdatas = () => {
let selectedKeys; let selectedKeys;
const {location} = this.props; const { location } = this.props;
if(location.pathname.indexOf('/challenges')!=-1){ if (location.pathname.indexOf('/challenges') != -1) {
selectedKeys="1" selectedKeys = "1"
}else if(location.pathname.indexOf('/propaedeutics')!=-1){ } else if (location.pathname.indexOf('/propaedeutics') != -1) {
selectedKeys="2" selectedKeys = "2"
}else if(location.pathname.indexOf('/repository')!=-1){ } else if (location.pathname.indexOf('/repository') != -1) {
selectedKeys="3" selectedKeys = "3"
}else if(location.pathname.indexOf('/secret_repository')!=-1){ } else if (location.pathname.indexOf('/secret_repository') != -1) {
selectedKeys="4" selectedKeys = "4"
} else if(location.pathname.indexOf('/collaborators')!=-1){ } else if (location.pathname.indexOf('/collaborators') != -1) {
selectedKeys="5" selectedKeys = "5"
}else if(location.pathname.indexOf('/dataset')!=-1){ } else if (location.pathname.indexOf('/dataset') != -1) {
selectedKeys="6" selectedKeys = "6"
}else if(location.pathname.indexOf('/shixun_discuss')!=-1){ } else if (location.pathname.indexOf('/shixun_discuss') != -1) {
selectedKeys="7" selectedKeys = "7"
}else if(location.pathname.indexOf('/ranking_list')!=-1){ } else if (location.pathname.indexOf('/ranking_list') != -1) {
selectedKeys="8" selectedKeys = "8"
}else if(location.pathname.indexOf('/settings')!=-1){ } else if (location.pathname.indexOf('/settings') != -1) {
selectedKeys="9" selectedKeys = "9"
} }
this.setState({ this.setState({
selectedKeys:selectedKeys selectedKeys: selectedKeys
}) })
} }
handleClick=(e)=>{ handleClick = (e) => {
this.setState({ this.setState({
selectedKeys: e.key, selectedKeys: e.key,
}); });
let id = this.props.match.params.shixunId; let id = this.props.match.params.shixunId;
if(e.key==="1"){ if (e.key === "1") {
this.props.history.replace(`/shixuns/${id}/challenges`); this.props.history.replace(`/shixuns/${id}/challenges`);
}else if(e.key==="2"){ } else if (e.key === "2") {
this.props.history.replace(`/shixuns/${id}/propaedeutics`); this.props.history.replace(`/shixuns/${id}/propaedeutics`);
}else if(e.key==="3"){ } else if (e.key === "3") {
// window.location.href=`/shixuns/${id}/repository`; // window.location.href=`/shixuns/${id}/repository`;
this.props.history.push(`/shixuns/${id}/repository`); this.props.history.push(`/shixuns/${id}/repository`);
}else if(e.key==="4"){ } else if (e.key === "4") {
// window.location.href=`/shixuns/${id}/secret_repository`; // window.location.href=`/shixuns/${id}/secret_repository`;
this.props.history.push(`/shixuns/${id}/secret_repository`); this.props.history.push(`/shixuns/${id}/secret_repository`);
}else if(e.key==="5"){ } else if (e.key === "5") {
this.props.history.replace(`/shixuns/${id}/collaborators`); this.props.history.replace(`/shixuns/${id}/collaborators`);
}else if(e.key==="6"){ } else if (e.key === "6") {
this.props.history.replace(`/shixuns/${id}/dataset`); this.props.history.replace(`/shixuns/${id}/dataset`);
}else if(e.key==="7"){ } else if (e.key === "7") {
this.props.history.replace(`/shixuns/${id}/shixun_discuss`); this.props.history.replace(`/shixuns/${id}/shixun_discuss`);
}else if(e.key==="8"){ } else if (e.key === "8") {
this.props.history.replace(`/shixuns/${id}/ranking_list`); this.props.history.replace(`/shixuns/${id}/ranking_list`);
}else if(e.key==="9"){ } else if (e.key === "9") {
this.props.history.replace(`/shixuns/${id}/settings`); this.props.history.replace(`/shixuns/${id}/settings`);
} }
} }
setpathArray=(list)=>{ setpathArray = (list) => {
this.setState({ this.setState({
newathArray:list newathArray: list
}) })
} }
render() { render() {
let url = window.location.href; let url = window.location.href;
let flag =false; let flag = false;
// url.indexOf("add_file")>-1; // url.indexOf("add_file")>-1;
return ( return (
@ -411,8 +369,8 @@ class TPMIndex extends Component {
<TPMBanner <TPMBanner
{...this.props} {...this.props}
{...this.state} {...this.state}
is_jupyter={this.state. is_jupyter} is_jupyter={this.state.is_jupyter}
getcomponentdidmount={()=>this.getcomponentdidmount()} getcomponentdidmount={() => this.getcomponentdidmount()}
></TPMBanner> ></TPMBanner>
} }
@ -440,16 +398,16 @@ class TPMIndex extends Component {
<span className={"tpmbannernavstyler"}>任务</span> <span className={"tpmbannernavstyler"}>任务</span>
</Menu.Item> </Menu.Item>
{ this.state.propaedeutics===undefined?"":this.state.propaedeutics===false?"":<Menu.Item key="2" className={"competitionmr50"}> {this.state.propaedeutics === undefined ? "" : this.state.propaedeutics === false ? "" : <Menu.Item key="2" className={"competitionmr50"}>
<span className={"tpmbannernavstyler"}>背景知识</span> <span className={"tpmbannernavstyler"}>背景知识</span>
</Menu.Item>} </Menu.Item>}
{ this.state.identity >4||this.state.identity===undefined ?"": {this.state.identity > 4 || this.state.identity === undefined ? "" :
this.state.is_jupyter===false?<Menu.Item key="3" className={"competitionmr50"}> this.state.is_jupyter === false ? <Menu.Item key="3" className={"competitionmr50"}>
<span className={"tpmbannernavstyler"}>版本库</span> <span className={"tpmbannernavstyler"}>版本库</span>
</Menu.Item>:""} </Menu.Item> : ""}
{this.state.identity >4||this.state.identity===undefined ?"": this.state.secret_repository && <Menu.Item key="4" className={"competitionmr50"}> {this.state.identity > 4 || this.state.identity === undefined ? "" : this.state.secret_repository && <Menu.Item key="4" className={"competitionmr50"}>
<span className={"tpmbannernavstyler"}>私密版本库</span> <span className={"tpmbannernavstyler"}>私密版本库</span>
</Menu.Item>} </Menu.Item>}
@ -457,17 +415,17 @@ class TPMIndex extends Component {
<span className={"tpmbannernavstyler"}>合作者</span> <span className={"tpmbannernavstyler"}>合作者</span>
</Menu.Item> </Menu.Item>
{ this.state.identity >4||this.state.identity===undefined ? "":this.state.is_jupyter===true?<Menu.Item key="6" className={"competitionmr50"}> {this.state.identity > 4 || this.state.identity === undefined ? "" : this.state.is_jupyter === true ? <Menu.Item key="6" className={"competitionmr50"}>
<span className={"tpmbannernavstyler"}>数据集</span> <span className={"tpmbannernavstyler"}>数据集</span>
</Menu.Item>:""} </Menu.Item> : ""}
{ this.state.is_jupyter===false?<Menu.Item key="7" className={"competitionmr50"}> {this.state.is_jupyter === false ? <Menu.Item key="7" className={"competitionmr50"}>
<span className={"tpmbannernavstyler"}>评论</span> <span className={"tpmbannernavstyler"}>评论</span>
</Menu.Item>:""} </Menu.Item> : ""}
{ this.state.is_jupyter===false? <Menu.Item key="8" className={"competitionmr50"}> {this.state.is_jupyter === false ? <Menu.Item key="8" className={"competitionmr50"}>
<span className={"tpmbannernavstyler"}>排行榜</span> <span className={"tpmbannernavstyler"}>排行榜</span>
</Menu.Item>:""} </Menu.Item> : ""}
{/*{this.state.identity >4||this.state.identity===undefined ? "":this.state.openknows===true?<span>*/} {/*{this.state.identity >4||this.state.identity===undefined ? "":this.state.openknows===true?<span>*/}
{/* <Popover*/} {/* <Popover*/}
{/* content={*/} {/* content={*/}
@ -483,13 +441,13 @@ class TPMIndex extends Component {
{/* </Popover>*/} {/* </Popover>*/}
{/*</span>:""}*/} {/*</span>:""}*/}
{this.state.identity >4||this.state.identity===undefined ? "": {this.state.identity > 4 || this.state.identity === undefined ? "" :
<Menu.Item key="9" className={"competitionmr50"}> <Menu.Item key="9" className={"competitionmr50"}>
<span className={"tpmbannernavstyler"}>配置</span> <span className={"tpmbannernavstyler"}>配置</span>
</Menu.Item> </Menu.Item>
} }
{this.state.identity >2||this.state.identity===undefined?"": {this.state.identity > 2 || this.state.identity === undefined ? "" :
<div className={"fr"}> <div className={"fr"}>
<Link to={`/shixuns/${this.props.match.params.shixunId}/audit_situation`} <Link to={`/shixuns/${this.props.match.params.shixunId}/audit_situation`}
className={`${this.props.match.url.indexOf('audit_situation') != -1 ? 'font-16 audit_situationactive' : 'font-16 audit_situationactive'} fl`}>审核情况</Link> className={`${this.props.match.url.indexOf('audit_situation') != -1 ? 'font-16 audit_situationactive' : 'font-16 audit_situationactive'} fl`}>审核情况</Link>
@ -546,24 +504,24 @@ class TPMIndex extends Component {
<Route path="/shixuns/:shixunId/repository/master/shixun_show/:fileId" render={ <Route path="/shixuns/:shixunId/repository/master/shixun_show/:fileId" render={
(props) => (<TPMRepositoryComponent {...this.props} {...this.state} {...props} is_jupyter={this.state.is_jupyter} setpathArray={(value)=>this.setpathArray(value)} (props) => (<TPMRepositoryComponent {...this.props} {...this.state} {...props} is_jupyter={this.state.is_jupyter} setpathArray={(value) => this.setpathArray(value)}
/>) />)
}></Route> }></Route>
<Route path="/shixuns/:shixunId/secret_repository/master/shixun_show/:fileId" render={ <Route path="/shixuns/:shixunId/secret_repository/master/shixun_show/:fileId" render={
(props) => (<TPMRepositoryComponent {...this.props} {...this.state} {...props} secret_repository_tab={true} is_jupyter={this.state.is_jupyter} setpathArray={(value)=>this.setpathArray(value)} (props) => (<TPMRepositoryComponent {...this.props} {...this.state} {...props} secret_repository_tab={true} is_jupyter={this.state.is_jupyter} setpathArray={(value) => this.setpathArray(value)}
/>) />)
}></Route> }></Route>
<Route path="/shixuns/:shixunId/repository" render={ <Route path="/shixuns/:shixunId/repository" render={
(props) => (<TPMRepositoryComponent {...this.props} {...this.state} {...props} is_jupyter={this.state.is_jupyter} setpathArray={(value)=>this.setpathArray(value)} (props) => (<TPMRepositoryComponent {...this.props} {...this.state} {...props} is_jupyter={this.state.is_jupyter} setpathArray={(value) => this.setpathArray(value)}
/>) />)
}></Route> }></Route>
<Route path="/shixuns/:shixunId/secret_repository" render={ <Route path="/shixuns/:shixunId/secret_repository" render={
(props) => (<TPMRepositoryComponent {...this.props} {...this.state} {...props} secret_repository_tab={true} is_jupyter={this.state.is_jupyter} setpathArray={(value)=>this.setpathArray(value)} (props) => (<TPMRepositoryComponent {...this.props} {...this.state} {...props} secret_repository_tab={true} is_jupyter={this.state.is_jupyter} setpathArray={(value) => this.setpathArray(value)}
/>) />)
}></Route> }></Route>
@ -587,7 +545,7 @@ class TPMIndex extends Component {
<Route path="/shixuns/:shixunId/shixun_discuss" render={ <Route path="/shixuns/:shixunId/shixun_discuss" render={
(props) => (<TPMShixunDiscussContainer {...this.props} {...this.state} {...props} is_jupyter={this.state.is_jupyter} (props) => (<TPMShixunDiscussContainer {...this.props} {...this.state} {...props} is_jupyter={this.state.is_jupyter}
initForumState={(data)=>this.initForumState(data)} initForumState={(data) => this.initForumState(data)}
setSearchValue={this.setSearchValue} setSearchValue={this.setSearchValue}
setHotLabelIndex={this.setHotLabelIndex} setHotLabelIndex={this.setHotLabelIndex}
/>) />)
@ -595,7 +553,7 @@ class TPMIndex extends Component {
<Route path="/shixuns/:shixunId/settings" render={ <Route path="/shixuns/:shixunId/settings" render={
(props) => (<TPMsettings {...this.props} {...this.state} {...props} getcomponentdidmount={()=>this.getcomponentdidmount()} />) (props) => (<TPMsettings {...this.props} {...this.state} {...props} getcomponentdidmount={() => this.getcomponentdidmount()} />)
}></Route> }></Route>
{/*实训项目条目塞选*/} {/*实训项目条目塞选*/}
@ -626,18 +584,18 @@ class TPMIndex extends Component {
{/*评测设置*/} {/*评测设置*/}
<Route path="/shixuns/:shixunId/challenges/:checkpointId/tab=2" render={ <Route path="/shixuns/:shixunId/challenges/:checkpointId/tab=2" render={
(props) => (<TPMevaluation {...this.props} {...props} {...this.state}/>) (props) => (<TPMevaluation {...this.props} {...props} {...this.state} />)
}></Route> }></Route>
{/*参考答案*/} {/*参考答案*/}
<Route path="/shixuns/:shixunId/challenges/:checkpointId/tab=3" render={ <Route path="/shixuns/:shixunId/challenges/:checkpointId/tab=3" render={
(props) => (<TPManswer {...this.props} {...props} {...this.state}/>) (props) => (<TPManswer {...this.props} {...props} {...this.state} />)
}></Route> }></Route>
{/*新建关卡*/} {/*新建关卡*/}
<Route path="/shixuns/:shixunId/challenges/new" render={ <Route path="/shixuns/:shixunId/challenges/new" render={
(props) => (<TPMchallengesnew {...this.props} {...props} {...this.state}/>) (props) => (<TPMchallengesnew {...this.props} {...props} {...this.state} />)
}></Route> }></Route>
{/*编辑关卡*/} {/*编辑关卡*/}
@ -652,12 +610,12 @@ class TPMIndex extends Component {
{/*修改选择题*/} {/*修改选择题*/}
<Route path="/shixuns/:shixunId/challenges/:checkpointId/editquestion/:choose_id" render={ <Route path="/shixuns/:shixunId/challenges/:checkpointId/editquestion/:choose_id" render={
(props) => (<TPMquestion {...this.props} {...props} {...this.state}/>) (props) => (<TPMquestion {...this.props} {...props} {...this.state} />)
}></Route> }></Route>
{/*修改选择题*/} {/*修改选择题*/}
<Route path="/shixuns/:shixunId/challenges/:checkpointId/editquestion" render={ <Route path="/shixuns/:shixunId/challenges/:checkpointId/editquestion" render={
(props) => (<TPMquestion {...this.props} {...props} {...this.state}/>) (props) => (<TPMquestion {...this.props} {...props} {...this.state} />)
}></Route> }></Route>
<Route exact path="/shixuns/:shixunId" render={ <Route exact path="/shixuns/:shixunId" render={
@ -674,4 +632,4 @@ class TPMIndex extends Component {
} }
} }
export default SnackbarHOC() (TPMIndexHOC ( TPMIndex )); export default SnackbarHOC()(TPMIndexHOC(TPMIndex));

Loading…
Cancel
Save