forgeplus-react/src/forge/users/Infos.js

393 lines
14 KiB
JavaScript
Raw Normal View History

2020-06-02 18:54:46 +08:00
import React, { Component } from "react";
2020-06-03 09:40:16 +08:00
import { Link } from "react-router-dom";
2021-06-04 09:43:38 +08:00
import { Button, Spin , Menu } from "antd";
2020-06-03 09:40:16 +08:00
import FocusButton from "../UsersList/focus_button";
2020-06-02 18:54:46 +08:00
2020-06-03 09:40:16 +08:00
import axios from "axios";
import { getImageUrl } from "educoder";
2020-06-02 18:54:46 +08:00
import { Route, Switch } from "react-router-dom";
2020-06-03 09:40:16 +08:00
import "./new_user.css";
2020-06-22 14:07:06 +08:00
import "../css/index.scss";
2020-06-03 18:08:04 +08:00
import './Index.scss';
2020-06-02 18:54:46 +08:00
import Loadable from "react-loadable";
import Loading from "../../Loading";
2021-06-04 09:43:38 +08:00
const UpdateInfo = Loadable({
loader: () => import("./Material/Index"),
loading: Loading,
});
2020-09-03 14:14:49 +08:00
const InfosDevOps = Loadable({
loader: () => import("./devOpsCI"),
loading: Loading,
});
const InfosDevOpsCD = Loadable({
loader: () => import("./devOpsCD"),
loading: Loading,
});
2021-05-28 16:19:40 +08:00
const Statistics = Loadable({
loader: () => import("./Statistics/Index"),
loading: Loading,
});
const GeneralView = Loadable({
loader: () => import("./GeneralView/Index"),
loading: Loading,
});
2020-06-03 18:10:53 +08:00
const InfosUser = Loadable({
2020-06-02 18:54:46 +08:00
loader: () => import("./InfosUser"),
loading: Loading,
});
2020-06-03 14:42:13 +08:00
const Organize = Loadable({
loader: () => import("./Team"),
loading: Loading,
});
2020-06-02 18:54:46 +08:00
2020-06-03 18:10:53 +08:00
const WatchsUser = Loadable({
loader: () => import("./watch_users"),
loading: Loading,
})
const FanUser = Loadable({
loader: () => import("./fan_users"),
loading: Loading,
})
2021-04-25 17:38:47 +08:00
const Notice = Loadable({
loader: () => import("../Notice/Index"),
2020-06-03 18:10:53 +08:00
loading: Loading,
})
2020-06-02 18:54:46 +08:00
class Infos extends Component {
2020-06-03 09:40:16 +08:00
constructor(props) {
super(props);
this.state = {
isSpin: false,
user: undefined,
2020-06-03 18:10:53 +08:00
project_type: undefined,
2021-04-27 17:12:00 +08:00
route_type: undefined,
2021-04-27 17:46:05 +08:00
undo_events:0,
2021-05-28 16:19:40 +08:00
menuKey:"0"
2020-06-03 09:40:16 +08:00
};
}
2021-05-28 16:19:40 +08:00
renderPath=(pathname)=>{
const { username } = this.props.match.params;
2021-08-30 10:31:51 +08:00
if(pathname === `/${username}`){
2021-06-02 18:22:29 +08:00
this.setState({menuKey:"0",route_type:undefined});
2021-08-30 10:31:51 +08:00
}else if(pathname === `/${username}/statistics`){
2021-06-02 18:22:29 +08:00
this.setState({menuKey:"1",route_type:undefined});
2021-08-30 10:31:51 +08:00
}else if(pathname.indexOf(`/${username}/projects`)>-1){
2021-06-02 18:22:29 +08:00
this.setState({menuKey:"2",route_type:undefined});
2021-08-30 10:31:51 +08:00
}else if(pathname.indexOf(`/${username}/notice`)>-1){
2021-06-02 18:22:29 +08:00
this.setState({menuKey:"3",route_type:undefined});
2021-08-30 10:31:51 +08:00
}else if(pathname.indexOf(`/${username}/devops`)>-1){
2021-06-02 18:22:29 +08:00
this.setState({menuKey:"4",route_type:undefined});
2021-08-30 10:31:51 +08:00
}else if(pathname === `/${username}/organizes`){
2021-06-02 18:22:29 +08:00
this.setState({menuKey:"5",route_type:undefined});
2021-08-30 10:31:51 +08:00
}else if(pathname === `/${username}/watchers`){
2021-06-02 18:22:29 +08:00
this.setState({menuKey:undefined,route_type:"watchers"});
2021-08-30 10:31:51 +08:00
}else if(pathname === `/${username}/fan_users`){
2021-06-02 18:22:29 +08:00
this.setState({menuKey:undefined,route_type:"fan_users"});
2021-06-04 09:43:38 +08:00
}else{
this.setState({menuKey:undefined,route_type:undefined});
2021-05-28 16:19:40 +08:00
}
}
2020-06-03 09:40:16 +08:00
componentDidMount = () => {
this.fetchUser();
2021-05-28 16:19:40 +08:00
const { pathname } = this.props.location;
this.renderPath(pathname);
2020-06-03 09:40:16 +08:00
};
2021-05-28 16:19:40 +08:00
2020-12-14 17:04:58 +08:00
componentDidUpdate=(prevProps)=>{
const { username } = this.props.match.params;
const prevUser = prevProps.match.params.username;
if(prevUser && username && prevUser !== username){
this.fetchUser();
}
2021-05-28 16:19:40 +08:00
const { pathname } = this.props.location;
const prevPath = prevProps.location.pathname;
if(prevPath && pathname && prevPath !== pathname){
this.renderPath(pathname);
}
this.props.history.listen(()=>{
if (document.body.scrollTop || document.documentElement.scrollTop > 0) {
window.scrollTo(0, 0)
}
})
2020-12-14 17:04:58 +08:00
}
2020-06-03 09:40:16 +08:00
fetchUser = () => {
2020-06-03 18:10:53 +08:00
this.setState({
isSpin: true,
});
2020-06-15 15:31:21 +08:00
const { current_user } = this.props;
const { username } = this.props.match.params;
let url = `/users/${username || (current_user && current_user.login)}.json`;
2021-06-04 09:43:38 +08:00
axios.get(url).then((result) => {
let e = result.data && result.data.undo_events;
this.setState({
user: result.data,
isSpin: false,
undo_events:e
2020-06-03 09:40:16 +08:00
});
2021-06-04 09:43:38 +08:00
})
.catch((error) => {
this.setState({
isSpin: false,
});
});
2020-06-03 09:40:16 +08:00
};
2020-09-03 14:14:49 +08:00
change_devops_type=(type)=>{
const {user} = this.state;
this.setState({
project_type: type ,
route_type: undefined
})
2021-08-30 10:31:51 +08:00
this.props.history.push(`/${user && user.login}/devops/${type}`);
2020-09-03 14:14:49 +08:00
}
2020-06-03 18:10:53 +08:00
undo_link = () => {
2021-04-27 18:27:56 +08:00
const {user } = this.state;
2020-06-03 18:20:20 +08:00
this.setState({
2021-04-25 17:38:47 +08:00
route_type: undefined,
2021-04-27 17:46:05 +08:00
project_type:"notice",
2021-04-27 18:27:56 +08:00
},()=>{
2021-08-30 10:31:51 +08:00
this.props.history.push(`/${user && user.login}/notice`);
2021-04-27 18:27:56 +08:00
this.fetchUser();
2020-06-03 18:20:20 +08:00
})
2020-06-03 18:10:53 +08:00
}
route_link = (type) => {
this.setState({
route_type: type
})
}
2020-06-03 18:18:56 +08:00
organize_link = () => {
const {user} = this.state
2020-06-03 18:20:20 +08:00
this.setState({
2021-04-25 17:38:47 +08:00
route_type: undefined,
project_type:"organizes"
2020-06-03 18:20:20 +08:00
})
2021-08-30 10:31:51 +08:00
this.props.history.push(`/${user && user.login}/organizes`)
2020-06-03 18:18:56 +08:00
}
2021-06-08 14:56:00 +08:00
resetUser=()=>{
const { resetUserInfo } = this.props;
this.fetchUser();
resetUserInfo && resetUserInfo();
}
// 修改待办事项右侧的数量
deleteUndoEvent=(count)=>{
let { undo_events } = this.state;
let undo = undo_events - count;
this.setState({
undo_events:undo
})
}
2020-06-02 18:54:46 +08:00
render() {
2021-06-09 17:37:04 +08:00
const { current_user } = this.props;
2020-12-14 17:04:58 +08:00
const { username } = this.props.match.params;
2021-06-09 17:37:04 +08:00
const { user, isSpin, route_type , undo_events , menuKey } = this.state;
2020-06-02 18:54:46 +08:00
return (
<div className="newMain clearfix">
2020-06-03 18:10:53 +08:00
<Spin spinning={isSpin}>
<div className="new-content-flex">
2021-03-19 11:35:03 +08:00
<div className="list-left" style={{border:"none"}}>
2020-06-03 18:10:53 +08:00
<div className="bgcF">
2021-06-04 09:43:38 +08:00
<div className="list-l-Menu text-center" style={{padding:"20px 25px"}}>
<span className="headimg">
<img src={getImageUrl(`/${user && user.image_url}`)} alt=""/>
<span>
{
user && user.gender===1?
2021-06-17 11:38:53 +08:00
<i className="iconfont icon-nan1"></i>
2021-06-04 09:43:38 +08:00
:
2021-06-17 11:38:53 +08:00
<i className="iconfont icon-nv1"></i>
2021-06-04 09:43:38 +08:00
}
</span>
</span>
2021-06-09 11:52:36 +08:00
<div className="text-center mt15 font-24 task-hide" title={user && user.username}>
2020-06-04 18:28:26 +08:00
{user && user.username}
</div>
2021-06-04 09:43:38 +08:00
<div className="userDescription">
{user && user.description}
</div>
2020-06-03 18:10:53 +08:00
<div>
2021-09-01 11:24:37 +08:00
{/* {user && current_user && user.login === current_user.login && (
2020-06-03 18:10:53 +08:00
<div className="user-info-star-button ">
<Button
block
className="text-button-grey"
2021-08-26 14:18:14 +08:00
onClick={()=>this.props.history.push(`/${user.login}/info`)}
2021-06-04 09:43:38 +08:00
type="primary"
2020-06-03 18:10:53 +08:00
>
{" "}
<i className="iconfont icon-shezhi4 font-15 mr5"></i>
修改资料
</Button>
</div>
2021-09-01 11:24:37 +08:00
)} */}
2020-06-03 18:10:53 +08:00
{current_user && user && user.login !== current_user.login && (
<div className="user-info-star-button ">
<FocusButton
is_block={true}
is_watch={user.is_watch}
id={user.login}
fontClass={"font-14 ml5"}
starText={"关注TA"}
/>
</div>
)}
2020-06-03 09:40:16 +08:00
</div>
2021-06-04 09:43:38 +08:00
<div className="focusBox">
2020-06-03 18:10:53 +08:00
<Link
2021-08-30 10:31:51 +08:00
to={`/${user && user.login}/watchers`}
2020-08-13 15:44:02 +08:00
className={`with50 text-center pull-left ${route_type === "watchers" ? "text-primary" : ""}`}
onClick={() =>this.route_link("watchers")}
2020-06-03 18:10:53 +08:00
>
2020-06-04 18:28:26 +08:00
<div>{current_user && user && user.login === current_user.login ? "我关注的" : "TA关注的"}</div>
2020-06-03 18:10:53 +08:00
<span>{user && user.watching_count}</span>
</Link>
<Link
2021-08-30 10:31:51 +08:00
to={`/${user && user.login}/fan_users`}
2020-06-03 18:10:53 +08:00
onClick={() =>this.route_link("fan_users")}
className={`with50 text-center pull-left ${route_type === "fan_users" ? "text-primary" : ""}`}
>
2020-06-04 18:28:26 +08:00
<div>{current_user && user && user.login === current_user.login ? "关注我的" : "关注TA的"}</div>
2020-06-03 18:10:53 +08:00
<span>{user && user.watched_count}</span>
</Link>
2020-06-03 09:40:16 +08:00
</div>
2021-06-04 09:43:38 +08:00
{
user && (user.province || user.custom_department || user.email) ?
<div className="infoBox">
{ user.province && <div><i className="iconfont icon-weizhi"></i><span>{user.province}</span><span title={user.city}>{user.city}</span></div> }
{ user.custom_department && <div><i className="iconfont icon-danwei"></i><span title={user.custom_department}>{user.custom_department}</span></div> }
{ user.email && <div><i className="iconfont icon-youxiangrenzheng"></i><span title={user.email}>{user.email}</span></div> }
2021-06-04 09:43:38 +08:00
</div>
:""
}
2020-06-03 18:10:53 +08:00
</div>
2020-06-03 09:40:16 +08:00
</div>
</div>
2020-06-03 18:10:53 +08:00
<div className="list-right">
2021-06-04 09:43:38 +08:00
{ !route_type && menuKey &&
2021-06-02 18:22:29 +08:00
<Menu selectedKeys={[menuKey]} mode={`horizontal`} className="infosRightMenu">
2021-08-30 10:31:51 +08:00
<Menu.Item key="0"><Link to={`/${user && user.login}`}><i className="iconfont icon-gailan"></i></Link></Menu.Item>
<Menu.Item key="1"><Link to={`/${user && user.login}/statistics`}><i className="iconfont icon-shujutongji"></i></Link></Menu.Item>
<Menu.Item key="2"><Link to={`/${user && user.login}/projects/common`}><i className="iconfont icon-xiangmu"></i></Link></Menu.Item>
2021-06-02 18:22:29 +08:00
{
current_user && user && user.login === current_user.login ?
2021-07-05 20:35:29 +08:00
<Menu.Item key="3">
2021-08-30 10:31:51 +08:00
<Link to={`/${user && user.login}/notice`}>
2021-07-05 20:35:29 +08:00
<i className="iconfont icon-daibanshixiang"></i>
{undo_events && undo_events >0 ? <span className="menuNum">({undo_events})</span>:""}</Link>
</Menu.Item>
2021-06-02 18:22:29 +08:00
:""
}
{
current_user && current_user.login && current_user.login === username ?
2021-08-30 10:31:51 +08:00
<Menu.Item key="4"><Link to={`/${user && user.login}/devops/CIService`}><i className="iconfont icon-gongzuoliu1"></i>DevOps</Link></Menu.Item>
2021-06-02 18:22:29 +08:00
:""
}
2021-07-05 20:35:29 +08:00
<Menu.Item key="5">
2021-08-30 10:31:51 +08:00
<Link to={`/${user && user.login}/organizes`}>
2021-07-05 20:35:29 +08:00
<i className="iconfont icon-zuzhi"></i>
{ user && user.user_org_count && user.user_org_count > 0 ? <span className="menuNum">({user.user_org_count})</span>:""}
</Link>
</Menu.Item>
2021-06-02 18:22:29 +08:00
</Menu>
}
2020-06-03 18:10:53 +08:00
{user && (
2021-05-28 16:19:40 +08:00
<Switch {...this.props}>
<Route
2021-08-30 10:31:51 +08:00
path="/:username/watchers"
2021-05-28 16:19:40 +08:00
render={() => {
return <WatchsUser {...this.props} {...this.state} userType="watchers" fetchUser={this.fetchUser}/>;
2021-05-28 16:19:40 +08:00
}}
></Route>
2020-06-03 18:10:53 +08:00
<Route
2021-08-30 10:31:51 +08:00
path="/:username/notice"
2021-05-28 16:19:40 +08:00
render={() => {
return <Notice {...this.props} {...this.state} deleteUndoEvent={this.deleteUndoEvent}/>;
2021-05-28 16:19:40 +08:00
}}
></Route>
<Route
2021-08-30 10:31:51 +08:00
path="/:username/fan_users"
2021-05-28 16:19:40 +08:00
render={() => {
return <FanUser {...this.props} {...this.state} userType="fan_users" fetchUser={this.fetchUser}/>;
2021-05-28 16:19:40 +08:00
}}
></Route>
<Route
2021-08-30 10:31:51 +08:00
path="/:username/devops/CDService"
2021-05-28 16:19:40 +08:00
render={() => {
return <InfosDevOpsCD {...this.props} {...this.state} />;
}}
></Route>
<Route
2021-08-30 10:31:51 +08:00
path="/:username/devops/CIService"
2021-05-28 16:19:40 +08:00
render={() => {
return <InfosDevOps {...this.props} {...this.state} />;
}}
></Route>
<Route
2021-08-30 10:31:51 +08:00
path="/:username/projects/:project_type"
2021-05-28 16:19:40 +08:00
render={() => {
return <InfosUser {...this.props} {...this.state} />;
}}
></Route>
<Route
2021-08-30 10:31:51 +08:00
path="/:username/organizes"
2021-05-28 16:19:40 +08:00
render={() => {
return <Organize {...this.props} {...this.state} />;
}}
></Route>
2021-09-01 11:24:37 +08:00
{/* <Route
2021-08-30 10:31:51 +08:00
path="/:username/info"
2021-06-04 09:43:38 +08:00
render={() => {
2021-06-08 14:56:00 +08:00
return <UpdateInfo {...this.props} {...this.state} resetUser={this.resetUser}/>;
2021-06-04 09:43:38 +08:00
}}
2021-09-01 11:24:37 +08:00
></Route> */}
{/* <Route
2021-08-30 10:31:51 +08:00
path="/:username/password"
2021-06-04 09:43:38 +08:00
render={() => {
return <UpdateInfo {...this.props} {...this.state}/>;
}}
2021-09-01 11:24:37 +08:00
></Route> */}
2021-06-04 09:43:38 +08:00
2021-05-28 16:19:40 +08:00
<Route
2021-08-30 10:31:51 +08:00
path="/:username/statistics"
2021-05-28 16:19:40 +08:00
render={(props) => {
return <Statistics {...this.props} {...this.state} />;
}}
></Route>
<Route
2021-08-30 10:31:51 +08:00
path="/:username"
2021-05-28 16:19:40 +08:00
render={(props) => {
return <GeneralView {...this.props} {...this.state} />;
}}
></Route>
<Route
path="/"
render={(props) => {
return <GeneralView {...this.props} {...this.state} />;
}}
></Route>
</Switch>
2020-06-03 18:10:53 +08:00
)}
2020-06-03 09:40:16 +08:00
</div>
2021-05-28 16:19:40 +08:00
</div>
2020-06-03 18:10:53 +08:00
</Spin>
2020-06-02 18:54:46 +08:00
</div>
);
}
}
2020-06-15 15:31:21 +08:00
export default Infos;