forgeplus-react/src/forge/Activity/Activity.js

226 lines
7.0 KiB
JavaScript
Raw Normal View History

2020-03-16 14:12:11 +08:00
import React , { Component } from 'react';
2020-04-09 17:23:40 +08:00
import { Dropdown , Menu , Icon , Pagination , Spin } from 'antd';
2020-06-22 14:07:06 +08:00
import '../css/index.scss';
2021-07-22 17:44:12 +08:00
import '../Branch/branch.scss';
2020-03-16 14:12:11 +08:00
import './activity.css';
2020-03-27 18:29:00 +08:00
import NoneData from '../Nodata';
2020-03-16 14:12:11 +08:00
import ActivityItem from './ActivityItem';
import axios from 'axios';
const LIMIT = 15;
const ARRAY = [
2021-10-14 13:59:03 +08:00
{
id:"",
name:'全部'
},
2020-03-16 14:12:11 +08:00
{
id:1,
name:'1天'
},
{
id:3,
name:'3天'
},
{
id:7,
name:'1周'
},
{
id:30,
name:'1个月'
}
]
class Activity extends Component{
constructor(props){
super(props);
this.state={
2021-10-14 13:59:03 +08:00
time:undefined,
2020-03-16 14:12:11 +08:00
type:undefined,
state:undefined,
page:1,
2021-10-15 15:20:21 +08:00
pr_count:undefined,
new_pr_count:undefined,
close_issues_count:undefined,
open_issues_count:undefined,
pr_all_count:undefined,issues_count:undefined,
2020-03-16 14:12:11 +08:00
data:undefined,
2020-04-09 17:23:40 +08:00
project_trends:undefined,
isSpin:false
2020-03-16 14:12:11 +08:00
}
}
componentDidMount=()=>{
const { time,type,status,page } = this.state;
2020-04-09 17:23:40 +08:00
this.setState({
isSpin:true
})
2020-03-16 14:12:11 +08:00
this.getInfo(time,type,status,page);
}
2023-08-15 10:40:07 +08:00
componentDidUpdate(){
this.updateDocumentTitle();
}
// 更新网页标题
updateDocumentTitle(){
const {projectDetail} = this.props;
if(projectDetail){
const { author, name} = projectDetail;
document.title = `动态-${author.name}/${name}`;
}
}
2020-03-16 14:12:11 +08:00
getInfo =(time,type,status,page)=>{
2020-08-12 18:13:18 +08:00
const { projectsId , owner } = this.props.match.params;
const url = `/${owner}/${projectsId}/activity.json`;
2020-03-16 14:12:11 +08:00
axios.get(url,{
params:{
time,type,status,page
}
}).then(result=>{
if(result){
this.setState({
data:result.data,
2020-04-09 17:23:40 +08:00
project_trends:result.data.project_trends,
2021-10-15 15:20:21 +08:00
isSpin:false,
pr_count:result.data.pr_count,
new_pr_count:result.data.new_pr_count,
close_issues_count:result.data.close_issues_count,
open_issues_count:result.data.open_issues_count,
pr_all_count:result.data.pr_all_count,
issues_count:result.data.issues_count,
2020-03-16 14:12:11 +08:00
})
2021-10-14 13:59:03 +08:00
window.scrollTo(0,0);
2020-03-16 14:12:11 +08:00
}
}).catch(error=>{
console.log(error);
})
}
// 切换周期
changeTime=(e)=>{
this.setState({
2021-10-14 13:59:03 +08:00
time:e.key ==="item_0"?undefined:e.key,
2020-04-09 17:23:40 +08:00
isSpin:true
2020-03-16 14:12:11 +08:00
})
const { type,status,page } = this.state;
2021-10-14 13:59:03 +08:00
this.getInfo(e.key ==="item_0"?undefined:e.key,type,status,page);
2020-03-16 14:12:11 +08:00
}
//筛选
changeTrends=(type,status)=>{
this.setState({
2021-10-14 13:59:03 +08:00
type,status,page:1
2020-03-16 14:12:11 +08:00
})
2021-10-14 13:59:03 +08:00
const {time}=this.state;
this.getInfo(time,type,status,1);
2020-03-16 14:12:11 +08:00
}
// 分页
ChangePage=(page)=>{
this.setState({
page
})
const { time,type,status } = this.state;
this.getInfo(time,type,status,page);
}
2020-07-06 16:11:44 +08:00
menu =()=> (
<Menu>
{
ARRAY && ARRAY.map((item,key)=>{
return(
<Menu.Item key={item.id} onClick={this.changeTime}>{item.name}</Menu.Item>
)
})
}
</Menu>
)
2020-03-16 14:12:11 +08:00
render(){
2021-11-30 18:34:41 +08:00
const { time , data , page , project_trends , isSpin ,
pr_count , new_pr_count , close_issues_count , open_issues_count , pr_all_count ,issues_count,
type,status } = this.state;
2021-10-14 13:59:03 +08:00
let name = time ? ARRAY.filter(item=>item.id === parseInt(time)) :[{name:"全部"}];
2021-10-15 15:20:21 +08:00
const first_per = pr_all_count > 0 ? `${parseFloat(pr_count/pr_all_count).toFixed(2)*100}%` :"50%";
const second_per =pr_all_count > 0 ? `${parseFloat(new_pr_count/pr_all_count).toFixed(2)*100}%` :"50%";
const third_per =issues_count > 0 ?`${parseFloat(close_issues_count/issues_count).toFixed(2)*100}%` :"50%";
const fourth_per =issues_count > 0 ?`${parseFloat(open_issues_count/issues_count).toFixed(2)*100}%` :"50%";
2020-03-16 14:12:11 +08:00
return(
<div className="main">
<div className="normalBox">
<div class="normalBox-title">概览</div>
<div className="orderInfo">
<div>
<div className="percentLine prPercent">
2021-10-14 13:59:03 +08:00
<p className="percent_purple" style={{width:first_per}}></p>
2020-03-16 14:12:11 +08:00
<p className="percent_green resetStyle" style={{width:`${second_per}`}}></p>
</div>
<span>{data && data.pr_all_count}合并请求</span>
</div>
<div>
<div className="percentLine">
<p className="percent_red" style={{width:`${third_per}`}}></p>
<p className="percent_green" style={{width:`${fourth_per}`}}></p>
</div>
2021-12-17 15:49:52 +08:00
<span>{data && data.issues_count}疑修</span>
2020-03-16 14:12:11 +08:00
</div>
</div>
<ul className="percentBox">
<li>
<span className="purple">{data && data.pr_count}</span>
2021-11-30 18:34:41 +08:00
<span className={type==="PullRequest" && status==="delay" ?`change active`:"change"} onClick={()=>this.changeTrends("PullRequest","delay")}>已处理的合并请求</span>
2020-03-16 14:12:11 +08:00
</li>
<li>
<span className="green">{data && data.new_pr_count}</span>
2021-11-30 18:34:41 +08:00
<span className={type==="PullRequest"&& status==="not_delay" ?`change active`:"change"} onClick={()=>this.changeTrends("PullRequest","not_delay")}>未处理的合并请求</span>
2020-03-16 14:12:11 +08:00
</li>
<li>
<span className="red">{data && data.close_issues_count}</span>
2021-12-17 15:49:52 +08:00
<span className={type==="Issue"&& status==="delay" ?`change active`:"change"} onClick={()=>this.changeTrends("Issue","delay")}>已关闭的疑修</span>
2020-03-16 14:12:11 +08:00
</li>
<li>
<span className="green">{data && data.open_issues_count}</span>
2021-12-17 15:49:52 +08:00
<span className={type==="Issue"&& status==="not_delay" ?`change active`:"change"} onClick={()=>this.changeTrends("Issue","not_delay")}>未处理的疑修</span>
2020-03-16 14:12:11 +08:00
</li>
</ul>
</div>
<div className="df trendsTop mt20">
<div className="branchDropdown f-wrap-alignCenter">
2020-07-06 16:11:44 +08:00
<Dropdown overlay={this.menu()} trigger={['click']} placement="bottomLeft">
2020-03-16 14:12:11 +08:00
<a className="ant-dropdown-link">
2020-03-27 18:29:00 +08:00
<span className="color-grey-9 mr3">周期:</span>
2020-03-20 16:49:41 +08:00
{name && name.length>0 && name[0].name} <Icon type="down" />
2020-03-16 14:12:11 +08:00
</a>
</Dropdown>
</div>
</div>
2020-04-09 17:23:40 +08:00
<Spin spinning={isSpin}>
{
project_trends && project_trends.length > 0 ?
<div className="activity_list">
{
project_trends && project_trends.map((item,key)=>{
return(
<ActivityItem item={item} {...this.props} ></ActivityItem>
)
})
}
</div>
:
2020-10-30 10:42:02 +08:00
<NoneData _html="暂时还没有相关数据!" />
2020-04-09 17:23:40 +08:00
}
</Spin>
2020-03-16 14:12:11 +08:00
{
data && data.project_trends_size > 0 && data.project_trends_size > LIMIT &&
<div className="pageDIV">
<Pagination showQuickJumper defaultCurrent={page} total={data && data.project_trends_size} pageSize={LIMIT} onChange={this.ChangePage}></Pagination>
</div>
}
</div>
)
}
}
export default Activity;