From a5cf8f69154ab3bc768849ede9e86ea93b499164 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com>
Date: Tue, 15 Oct 2019 08:49:47 +0800
Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=B7=B1=E5=88=86=E6=94=AF=E5=90=88?=
 =?UTF-8?q?=E5=B9=B6=E9=98=BF=E9=87=8C=E4=BA=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 public/react/src/AppConfig.js               |   3 +-
 public/react/src/modules/tpm/NewHeader.js   | 266 +++++++++++++-------
 public/react/src/modules/tpm/TPMIndexHOC.js |   4 +-
 3 files changed, 182 insertions(+), 91 deletions(-)

diff --git a/public/react/src/AppConfig.js b/public/react/src/AppConfig.js
index e1d5da561..af00842f2 100644
--- a/public/react/src/AppConfig.js
+++ b/public/react/src/AppConfig.js
@@ -94,7 +94,8 @@ export function initAxiosInterceptors(props) {
                 }
             }
 
-            if (requestMap[config.url] === true) { // 避免重复的请求
+            if (requestMap[config.url] === true) { // 避免重复的请求  导致页面f5刷新 也会被阻止
+              console.log("被阻止了是重复请求=================================");
                 return false;
             }
             // 非file_update请求
diff --git a/public/react/src/modules/tpm/NewHeader.js b/public/react/src/modules/tpm/NewHeader.js
index 2716493c0..844610e54 100644
--- a/public/react/src/modules/tpm/NewHeader.js
+++ b/public/react/src/modules/tpm/NewHeader.js
@@ -67,16 +67,24 @@ class NewHeader extends Component {
       occupation:0,
       mydisplay:false,
 			headtypesonClickbool:false,
-			headtypess:"/"
+			headtypess:"/",
+			mygetHelmetapi2:undefined,
     }
      console.log("176")
     // console.log(props);
-    console.log("NewHeader1234567890");
-    console.log(this.props);
+    // console.log("NewHeader1234567890");
+    // console.log(this.props);
   }
-
+	componentDidUpdate = (prevProps) => {
+		console.log("componentDidMount2");
+		console.log(this.state.mygetHelmetapi2);
+		if(this.state.mygetHelmetapi2===undefined){
+			this.getAppdata();
+		}
+	}
   componentDidMount() {
-
+  	console.log("componentDidMount1");
+   this.getAppdata();
     window._header_componentHandler = this;
 
     //下拉框的显示隐藏
@@ -645,7 +653,70 @@ submittojoinclass=(value)=>{
 			headtypesonClickbool:bool,
 		})
 	}
+	getAppdata=()=>{
+		console.log("开始刷新数据了")
+		let url = "/setting.json";
+		axios.get(url).then((response) => {
+			console.log("axios.get");
+			console.log(response);
+
+			if(response){
+				if(response.data){
+					this.setState({
+						mygetHelmetapi2:response.data.setting
+					});
+					document.title = response.data.setting.name;
+					var link = document.createElement('link'),
+						oldLink = document.getElementById('dynamic-favicon');
+					link.id = 'dynamic-favicon';
+					link.rel = 'shortcut icon';
+					link.href = response.data.setting.tab_logo_url;
+					if (oldLink) {
+						document.head.removeChild(oldLink);
+					}
+					document.head.appendChild(link);
+				}else {
+					document.title = "EduCoder";
+					var link = document.createElement('link'),
+						oldLink = document.getElementById('dynamic-favicon');
+					link.id = 'dynamic-favicon';
+					link.rel = 'shortcut icon';
+					link.href = "/react/build/./favicon.ico";
+					if (oldLink) {
+						document.head.removeChild(oldLink);
+					}
+					document.head.appendChild(link);
+				}
 
+			}else{
+				document.title = "EduCoder";
+				var link = document.createElement('link'),
+					oldLink = document.getElementById('dynamic-favicon');
+				link.id = 'dynamic-favicon';
+				link.rel = 'shortcut icon';
+				link.href = "/react/build/./favicon.ico";
+				if (oldLink) {
+					document.head.removeChild(oldLink);
+				}
+				document.head.appendChild(link);
+			}
+
+		}).catch((error) => {
+			console.log("开始刷新数据了但报错了");
+			console.log(error);
+
+			document.title = "EduCoder";
+			var link = document.createElement('link'),
+				oldLink = document.getElementById('dynamic-favicon');
+			link.id = 'dynamic-favicon';
+			link.rel = 'shortcut icon';
+			link.href = "/react/build/./favicon.ico";
+			if (oldLink) {
+				document.head.removeChild(oldLink);
+			}
+			document.head.appendChild(link);
+		});
+	};
   render() {
     const isLogin = true;   // 这里不会出现未登录的情况,服务端在服务端路由时发现如果是未登录,则跳转到登录页了。
     const {match,} = this.props;
@@ -668,27 +739,46 @@ submittojoinclass=(value)=>{
 			showSearchOpentype,
 			headtypesonClickbool,
 			headtypess,
+			mygetHelmetapi2,
     }=this.state;
     /*
         用户名称  用户头像url
     */
-    let activeIndex = false;
-    let activeForums = false;
-    let activeShixuns = false;
-    let activePaths = false;
-    let coursestype=false;
+		let activeIndex = false;
+		let activeForums = false;
+		let activeShixuns = false;
+		let activePaths = false;
+		let coursestype=false;
 		let activePackages=false;
 		let activeMoopCases=false;
-    let headtypes='/';
 
 
+		if (match.path === '/forums') {
+			activeForums = true;
+		} else if (match.path.startsWith('/shixuns')) {
+			activeShixuns = true;
+		}else if (match.path.startsWith('/paths')) {
+			activePaths = true;
+		} else if (match.path.startsWith('/courses')) {
+			coursestype = true;
+		}else if (match.path.startsWith('/crowdsourcing')) {
+			activePackages = true;
+		}else if(match.path.startsWith('/moop_cases')){
+			activeMoopCases =  true;
+		}else {
+			activeIndex = true;
+		}
+
+    let headtypes='/';
+
+		console.log("mygetHelmetapi2");
+		console.log(mygetHelmetapi2);
+	  if(mygetHelmetapi2){
+	  	if(mygetHelmetapi2.navbar){
+				if(mygetHelmetapi2.navbar.length>0){
+					console.log("mygetHelmetapi2.navbar.length>0====-=-=--=-=-=-=");
 
-	  if(this.props.mygetHelmetapi){
-	  	if(this.props.mygetHelmetapi.navbar){
-				if(this.props.mygetHelmetapi.navbar.length>0){
-					// console.log("this.props.mygetHelmetapi.navbar.length>0====-=-=--=-=-=-=");
-					// console.log(this.props);
-					// console.log(match.path);
+					console.log(match.path);
 					if(match.path==='/'){
 						if(headtypesonClickbool===false){
 							headtypes=undefined;
@@ -697,9 +787,9 @@ submittojoinclass=(value)=>{
 						}
 
 					}else {
-						for(var i=0;i<this.props.mygetHelmetapi.navbar.length;i++){
-							if(match.path===this.props.mygetHelmetapi.navbar[i].link){
-								headtypes=this.props.mygetHelmetapi.navbar[i].link;
+						for(var i=0;i<mygetHelmetapi2.navbar.length;i++){
+							if(match.path===mygetHelmetapi2.navbar[i].link){
+								headtypes=mygetHelmetapi2.navbar[i].link;
 								break;
 							}
 						}
@@ -764,10 +854,10 @@ submittojoinclass=(value)=>{
 		}
 
 	  // console.log("NewHeadergetHelmetapi432423423423");
-    // console.log(this.props.mygetHelmetapi);
+    // console.log(mygetHelmetapi2);
 		console.log("NewHeadermygetHelmetapi123123123123");
-		console.log(this.props);
-	  console.log(this.props.mygetHelmetapi);
+	  console.log(mygetHelmetapi2);
+	  console.log(this.props);
     return (
 
       <div className="newHeaders" id="nHeader"  >
@@ -785,10 +875,10 @@ submittojoinclass=(value)=>{
 				/>:""}
 				<a href={"/"} onClick={()=>this.headtypesonClick("/",false)} className={"fl mr30 ml25 mt10"}>
           {
-            this.props.mygetHelmetapi===undefined||this.props.mygetHelmetapi.nav_logo_url===null||this.props.mygetHelmetapi.nav_logo_url===undefined?
+            mygetHelmetapi2===undefined||mygetHelmetapi2.nav_logo_url===null||mygetHelmetapi2.nav_logo_url===undefined?
               <img alt="高校智能化教学与实训平台" className="logoimg" src={getImageUrl("images/educoder/headNavLogo.png?1526520218")}></img>
               :
-              <img alt="高校智能化教学与实训平台" className="logoimg" src={getImageUrl(this.props.mygetHelmetapi.nav_logo_url)}></img>
+              <img alt="高校智能化教学与实训平台" className="logoimg" src={getImageUrl(mygetHelmetapi2.nav_logo_url)}></img>
           }
 				</a>
 
@@ -804,18 +894,18 @@ submittojoinclass=(value)=>{
 					}
 				</style>
 					{
-						this.props.mygetHelmetapi!==undefined&&this.props.mygetHelmetapi.navbar!==null&&this.props.mygetHelmetapi.navbar!==undefined&&this.props.mygetHelmetapi.navbar.length>0?
+						mygetHelmetapi2!==undefined&&mygetHelmetapi2.navbar!==null&&mygetHelmetapi2.navbar!==undefined&&mygetHelmetapi2.navbar.length>0?
 						<div className="head-nav pr" id={"head-navpre1"}>
 								<ul id="header-nav">
 									{/*<li className={`${activeIndex === true ? 'active' : ''}`}><a href="/">首页</a></li>*/}
 									{/*<li><a href={this.props.Headertop===undefined?"":this.props.Headertop.shixun_paths_url}>实训路径</a></li>*/}
 									{
-										this.props.mygetHelmetapi.navbar && this.props.mygetHelmetapi.navbar.map((item,key)=>{
+										mygetHelmetapi2.navbar && mygetHelmetapi2.navbar.map((item,key)=>{
 											// console.log("headtypes");
 											// console.log(headtypes);
 											return(
-												<li key={key} className={`${headtypes===undefined?'pr':headtypes===item.link?'pr active':'pr'}`}>
-													<a href={item.link} onClick={()=>this.headtypesonClick(item.link,true)}>{item.name}</a>
+												<li key={key}  onClick={()=>this.headtypesonClick(item.link,true)} className={`${headtypes===undefined?'pr':headtypes===item.link?'pr active':'pr'}`}>
+													<Link to={item.link}>{item.name}</Link>
 												</li>
 											)
 										})
@@ -876,65 +966,65 @@ submittojoinclass=(value)=>{
 									</li>
 								</ul>
 							</div>
-							:this.props.mygetHelmetapi===undefined||this.props.mygetHelmetapi.navbar===null||this.props.mygetHelmetapi.navbar===undefined||this.props.mygetHelmetapi.navbar.length===0?
-						<div className="head-nav pr" id={"head-navpre2"}>
-
-							<ul id="header-nav">
-								{/*<li className={`${activeIndex === true ? 'active' : ''}`}><a href="/">首页</a></li>*/}
-
-								{/*<li><a href={this.props.Headertop===undefined?"":this.props.Headertop.shixun_paths_url}>实训路径</a></li>*/}
-								<li className={`${activePaths === true ? 'pr active' : 'pr'}`}>
-									<Link to={this.props.Headertop===undefined?"":'/paths'}>实践课程</Link>
-								</li>
-
-								{/*<li><a href={this.props.Headertop===undefined?"":'/courses'}>课堂</a></li>*/}
-								<li className={`${coursestype === true ? 'pr active' : 'pr'}`}>
-									{/*<a href={this.props.Headertop===undefined?"":this.props.Headertop.course_url}>课堂</a>*/}
-									<Link to={this.props.Headertop===undefined?"":'/courses'}>翻转课堂</Link>
-								</li>
-
-								<li className={`${activeShixuns === true ? 'pr active' : 'pr'}`}>
-									<Link to="/shixuns">实训项目</Link>
-									{/*<img src={getImageUrl("images/educoder/hot-h.png")} className="nav-img">*/}
-									{/*</img>*/}
-								</li>
-
-								<li className="fl edu-menu-panel  careershover "
-										style={{display: this.props.Headertop === undefined ?'none'  : this.props.Headertop.career_url.length > 0 ? 'block' : 'none'}}>
-									<a>职业路径</a>
-									<div
-										style={{display: this.props.Headertop === undefined ?'none'  : this.props.Headertop.career_url.length > 0 ? 'block' : 'none'}}>
-										<ul className="edu-menu-list edu-menu-listnew " style={{top:'60px'}}>
-											{this.props.Headertop === undefined ? "" : this.props.Headertop.career_url.map((item, key) => {
-												return(
-													<li key={key}><i className="iconfont icon-java left careersiconfont"
-																					 style={{color: '#000 important'}}
-													></i><a style={{width: '83%'}}
-																	href={item.url}>{item.name}</a></li>
-												)
-											})
-											}
-										</ul>
-									</div>
-								</li>
-
-								{/*<li className=""><a href={"/libraries"}>教学案例</a></li>*/}
-								<li className="">
-									<a href={this.props.Headertop===undefined?"":this.props.Headertop.competitions_url}>在线竞赛</a>
-									{/*<img className="roundedRectangles"*/}
-									{/*		 src={require('./roundedRectangle.png')}*/}
-									{/*/>*/}
-								</li>
-								<li className={`${activeMoopCases === true ? 'pr active' : 'pr'}`}> <Link to={`/moop_cases`}>教学案例</Link></li>
-								{/*<li className={`${activePackages === true ? 'pr active' : 'pr'}`}>*/}
-								{/*<Link to={'/crowdsourcing'}>众包创新</Link>*/}
-								{/*</li>*/}
-								<li className={`${activeForums === true ? 'active' : ''}`}>	<Link to={this.props.Headertop===undefined?"":this.props.Headertop.topic_url}>交流问答</Link></li>
-								<li
-									style={{display: this.props.Headertop === undefined ? 'none'  : this.props.Headertop.auth===null? 'none' : 'block'}}
-								><a href={this.props.Headertop===undefined?"":this.props.Headertop.auth}>工程认证</a></li>
-							</ul>
-						</div>
+						// 	:mygetHelmetapi2===undefined||mygetHelmetapi2.navbar===null||mygetHelmetapi2.navbar===undefined||mygetHelmetapi2.navbar.length===0?
+						// <div className="head-nav pr" id={"head-navpre2"}>
+						//
+						// 	<ul id="header-nav">
+						// 		{/*<li className={`${activeIndex === true ? 'active' : ''}`}><a href="/">首页</a></li>*/}
+						//
+						// 		{/*<li><a href={this.props.Headertop===undefined?"":this.props.Headertop.shixun_paths_url}>实训路径</a></li>*/}
+						// 		<li className={`${activePaths === true ? 'pr active' : 'pr'}`}>
+						// 			<Link to={this.props.Headertop===undefined?"":'/paths'}>实践课程</Link>
+						// 		</li>
+						//
+						// 		{/*<li><a href={this.props.Headertop===undefined?"":'/courses'}>课堂</a></li>*/}
+						// 		<li className={`${coursestype === true ? 'pr active' : 'pr'}`}>
+						// 			{/*<a href={this.props.Headertop===undefined?"":this.props.Headertop.course_url}>课堂</a>*/}
+						// 			<Link to={this.props.Headertop===undefined?"":'/courses'}>翻转课堂</Link>
+						// 		</li>
+						//
+						// 		<li className={`${activeShixuns === true ? 'pr active' : 'pr'}`}>
+						// 			<Link to="/shixuns">实训项目</Link>
+						// 			{/*<img src={getImageUrl("images/educoder/hot-h.png")} className="nav-img">*/}
+						// 			{/*</img>*/}
+						// 		</li>
+						//
+						// 		<li className="fl edu-menu-panel  careershover "
+						// 				style={{display: this.props.Headertop === undefined ?'none'  : this.props.Headertop.career_url.length > 0 ? 'block' : 'none'}}>
+						// 			<a>职业路径</a>
+						// 			<div
+						// 				style={{display: this.props.Headertop === undefined ?'none'  : this.props.Headertop.career_url.length > 0 ? 'block' : 'none'}}>
+						// 				<ul className="edu-menu-list edu-menu-listnew " style={{top:'60px'}}>
+						// 					{this.props.Headertop === undefined ? "" : this.props.Headertop.career_url.map((item, key) => {
+						// 						return(
+						// 							<li key={key}><i className="iconfont icon-java left careersiconfont"
+						// 															 style={{color: '#000 important'}}
+						// 							></i><a style={{width: '83%'}}
+						// 											href={item.url}>{item.name}</a></li>
+						// 						)
+						// 					})
+						// 					}
+						// 				</ul>
+						// 			</div>
+						// 		</li>
+						//
+						// 		{/*<li className=""><a href={"/libraries"}>教学案例</a></li>*/}
+						// 		<li className="">
+						// 			<a href={this.props.Headertop===undefined?"":this.props.Headertop.competitions_url}>在线竞赛</a>
+						// 			{/*<img className="roundedRectangles"*/}
+						// 			{/*		 src={require('./roundedRectangle.png')}*/}
+						// 			{/*/>*/}
+						// 		</li>
+						// 		<li className={`${activeMoopCases === true ? 'pr active' : 'pr'}`}> <Link to={`/moop_cases`}>教学案例</Link></li>
+						// 		{/*<li className={`${activePackages === true ? 'pr active' : 'pr'}`}>*/}
+						// 		{/*<Link to={'/crowdsourcing'}>众包创新</Link>*/}
+						// 		{/*</li>*/}
+						// 		<li className={`${activeForums === true ? 'active' : ''}`}>	<Link to={this.props.Headertop===undefined?"":this.props.Headertop.topic_url}>交流问答</Link></li>
+						// 		<li
+						// 			style={{display: this.props.Headertop === undefined ? 'none'  : this.props.Headertop.auth===null? 'none' : 'block'}}
+						// 		><a href={this.props.Headertop===undefined?"":this.props.Headertop.auth}>工程认证</a></li>
+						// 	</ul>
+						// </div>
 						:
 						<div className="head-nav pr" id={"head-navpre3"}>
 
diff --git a/public/react/src/modules/tpm/TPMIndexHOC.js b/public/react/src/modules/tpm/TPMIndexHOC.js
index 31bbba3ec..dc76b67d1 100644
--- a/public/react/src/modules/tpm/TPMIndexHOC.js
+++ b/public/react/src/modules/tpm/TPMIndexHOC.js
@@ -148,8 +148,8 @@ export function TPMIndexHOC(WrappedComponent) {
       }
       
 	    componentDidMount() {
-	    	console.log("TPMIndexHOC========");
-	    	console.log(this.props);
+	    	// console.log("TPMIndexHOC========");
+	    	// console.log(this.props);
         window.addEventListener('keyup', this.keyupListener)
 
 	        if(this.props.match.path==="/"){