|
|
@ -1,7 +1,59 @@ |
|
|
|
import React, { Component } from 'react'; |
|
|
|
import React, { Component } from 'react'; |
|
|
|
import { Link } from 'react-router-dom'; |
|
|
|
import { Link } from 'react-router-dom'; |
|
|
|
|
|
|
|
import $ from 'jquery'; |
|
|
|
|
|
|
|
|
|
|
|
class NavBar extends Component { |
|
|
|
class NavBar extends Component { |
|
|
|
state = { } |
|
|
|
state = { } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render_calc = () => { |
|
|
|
|
|
|
|
if (this.props.is_login){ |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<li className="nav-item"> |
|
|
|
|
|
|
|
<Link className="navbar-brand" to="/calc">计算器</Link> |
|
|
|
|
|
|
|
</li>); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else return ""; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleClickLogout = () => { |
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
|
|
|
|
url: "https://app165.acapp.acwing.com.cn/calculator/logout/", |
|
|
|
|
|
|
|
type: "GET", |
|
|
|
|
|
|
|
success: resp => { |
|
|
|
|
|
|
|
console.log(resp); |
|
|
|
|
|
|
|
if (resp.result === "success") { |
|
|
|
|
|
|
|
window.location.href = "/home"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render_logout = () => { |
|
|
|
|
|
|
|
if (this.props.is_login) { |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<ul className="navbar-nav"> |
|
|
|
|
|
|
|
<li className="nav-item"> |
|
|
|
|
|
|
|
<div className="navbar-brand" style={{cursor: "pointer"}}>{this.props.username}</div> |
|
|
|
|
|
|
|
</li> |
|
|
|
|
|
|
|
<li className="nav-item "> |
|
|
|
|
|
|
|
<div onClick={this.handleClickLogout} className="navbar-brand" style={{cursor: "pointer"}}>退出</div> |
|
|
|
|
|
|
|
</li> |
|
|
|
|
|
|
|
</ul>); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<ul className="navbar-nav"> |
|
|
|
|
|
|
|
<li className="nav-item"> |
|
|
|
|
|
|
|
<Link className="navbar-brand" to="/login">登录</Link> |
|
|
|
|
|
|
|
</li> |
|
|
|
|
|
|
|
<li className="nav-item"> |
|
|
|
|
|
|
|
<Link className="navbar-brand" to="/register">注册</Link> |
|
|
|
|
|
|
|
</li> |
|
|
|
|
|
|
|
</ul>); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
render() { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<nav className="navbar navbar-expand-lg navbar-light bg-light"> |
|
|
|
<nav className="navbar navbar-expand-lg navbar-light bg-light"> |
|
|
@ -15,18 +67,9 @@ class NavBar extends Component { |
|
|
|
<li className="nav-item"> |
|
|
|
<li className="nav-item"> |
|
|
|
<Link className="navbar-brand" to="/home">首页</Link> |
|
|
|
<Link className="navbar-brand" to="/home">首页</Link> |
|
|
|
</li> |
|
|
|
</li> |
|
|
|
<li className="nav-item"> |
|
|
|
{this.render_calc()} |
|
|
|
<Link className="navbar-brand" to="/calc">计算器</Link> |
|
|
|
|
|
|
|
</li> |
|
|
|
|
|
|
|
</ul> |
|
|
|
|
|
|
|
<ul className="navbar-nav"> |
|
|
|
|
|
|
|
<li className="nav-item"> |
|
|
|
|
|
|
|
<Link className="navbar-brand" to='/login'>登录</Link> |
|
|
|
|
|
|
|
</li> |
|
|
|
|
|
|
|
<li className="nav-item "> |
|
|
|
|
|
|
|
<Link className="navbar-brand" to='/register'>注册</Link> |
|
|
|
|
|
|
|
</li> |
|
|
|
|
|
|
|
</ul> |
|
|
|
</ul> |
|
|
|
|
|
|
|
{this.render_logout()} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</nav> |
|
|
|
</nav> |
|
|
|