forked from Gitlink/forgeplus-react
git cherry-pick a9285f37e7
This commit is contained in:
parent
d1bbe72857
commit
c2a718ef4d
|
@ -10,7 +10,7 @@ function Calendar({ userLogin , time , chooseTime }) {
|
|||
useEffect(()=>{
|
||||
if(time){
|
||||
let e,b = "";
|
||||
if(parseInt(time,0) === parseInt(moment().get('year'),0)){
|
||||
if(time === "0"){
|
||||
let y = moment().get('year');
|
||||
let m = moment().get('month');
|
||||
let d = moment().get('date');
|
||||
|
@ -52,30 +52,13 @@ function Calendar({ userLogin , time , chooseTime }) {
|
|||
}
|
||||
|
||||
function getVirtulData(data) {
|
||||
var date = +echarts.number.parseDate(baginT);
|
||||
var end = +echarts.number.parseDate(endT);
|
||||
var dayTime = 3600 * 24 * 1000;
|
||||
var array = [];
|
||||
for (var time = date; time <= end; time += dayTime) {
|
||||
let stamp = timestampToTime(time);
|
||||
let stampFilter = data.filter(i=>i.date === stamp);
|
||||
if(stampFilter && stampFilter.length > 0){
|
||||
array.push([stampFilter[0].date,stampFilter[0].contributions]);
|
||||
}else{
|
||||
array.push([stamp,0]);
|
||||
}
|
||||
for(var i=0;i<data.length;i++){
|
||||
array.push([data[i].date,data[i].contributions]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
function timestampToTime(timestamp) {
|
||||
var date = new Date(timestamp);
|
||||
var Y = date.getFullYear() + '-';
|
||||
var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
|
||||
var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
|
||||
return Y+M+D;
|
||||
}
|
||||
|
||||
function Init(data,max) {
|
||||
var huan_val = document.getElementById("Calendar");
|
||||
var myEcharts = echarts.init(huan_val);
|
||||
|
@ -83,11 +66,7 @@ function Calendar({ userLogin , time , chooseTime }) {
|
|||
title: {
|
||||
show:false
|
||||
},
|
||||
tooltip: {
|
||||
formatter:function(params){
|
||||
return params.data[0] + ': ' + params.data[1] + '个贡献';
|
||||
}
|
||||
},
|
||||
tooltip: {},
|
||||
visualMap: {
|
||||
min: 0,
|
||||
max: max,
|
||||
|
@ -96,23 +75,15 @@ function Calendar({ userLogin , time , chooseTime }) {
|
|||
left: 'center',
|
||||
bottom: 40,
|
||||
inRange:{
|
||||
color:['#fafafa', '#216e39']
|
||||
color:['#C7DBFF', '#5291FF']
|
||||
}
|
||||
},
|
||||
calendar: {
|
||||
top: 50,
|
||||
left: 40,
|
||||
right: 30,
|
||||
top: 60,
|
||||
left: 30,
|
||||
right: 0,
|
||||
cellSize: ['auto', 13],
|
||||
range: [baginT, endT],
|
||||
splitLine:{
|
||||
show:false,
|
||||
lineStyle:{
|
||||
color:"#fff",
|
||||
width:1,
|
||||
type:"solid"
|
||||
}
|
||||
},
|
||||
itemStyle: {
|
||||
borderWidth: 0.5
|
||||
},
|
||||
|
@ -121,8 +92,7 @@ function Calendar({ userLogin , time , chooseTime }) {
|
|||
nameMap:"cn"
|
||||
},
|
||||
dayLabel:{
|
||||
nameMap:"cn",
|
||||
firstDay:1
|
||||
nameMap:"cn"
|
||||
}
|
||||
},
|
||||
series: {
|
||||
|
@ -138,7 +108,7 @@ function Calendar({ userLogin , time , chooseTime }) {
|
|||
}
|
||||
|
||||
return(
|
||||
<div id="Calendar" style={{height:"210px"}}></div>
|
||||
<div id="Calendar" style={{height:"230px"}}></div>
|
||||
)
|
||||
}
|
||||
export default Calendar;
|
|
@ -15,20 +15,22 @@ function Line({data}) {
|
|||
let option = {
|
||||
color: ["#f8e367", "#58c0f0", "#ff9e48"],
|
||||
title: {
|
||||
show:false
|
||||
text: '近期活动统计',
|
||||
left: '3%',
|
||||
top:"3%"
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'axis'
|
||||
},
|
||||
legend: {
|
||||
data: ['提交数', '易修数', '合并请求数'],
|
||||
data: ['commits', 'issues', 'pull_requests'],
|
||||
right: 'center',
|
||||
bottom: '4%',
|
||||
bottom: '0',
|
||||
},
|
||||
grid: {
|
||||
left: '4%',
|
||||
right: '5%',
|
||||
bottom: '16%',
|
||||
right: '4%',
|
||||
bottom: '12%',
|
||||
containLabel: true
|
||||
},
|
||||
toolbox: {
|
||||
|
@ -51,23 +53,21 @@ function Line({data}) {
|
|||
},
|
||||
axisTick:{
|
||||
show:false
|
||||
},
|
||||
minInterval:1,
|
||||
splitNumber: 5,
|
||||
}
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '提交数',
|
||||
name: 'commits',
|
||||
type: 'line',
|
||||
data: d.commits_count
|
||||
},
|
||||
{
|
||||
name: '易修数',
|
||||
name: 'issues',
|
||||
type: 'line',
|
||||
data: d.issues_count
|
||||
},
|
||||
{
|
||||
name: '合并请求数',
|
||||
name: 'pull_requests',
|
||||
type: 'line',
|
||||
data: d.pull_requests_count
|
||||
}
|
||||
|
|
|
@ -13,12 +13,20 @@ import Calendar from '../Echart/Calendar';
|
|||
import ConcentrateProject from './ConcentrateProject';
|
||||
import Activity from './Activity';
|
||||
import moment from 'moment';
|
||||
import Axios from 'axios';
|
||||
|
||||
const { Option } = Select;
|
||||
const aLimit = 5;
|
||||
function Index(props) {
|
||||
const [ page , setPage ] = useState(1);
|
||||
const [ total , setTotal ] = useState(0);
|
||||
const [ createYear , setCreateYear ] = useState(undefined);
|
||||
const [ projectTrends , setProjectTrends ] = useState(undefined);
|
||||
|
||||
const [ year , setYear ] = useState("0");
|
||||
const [ yearList , setYearList ] = useState(undefined);
|
||||
const [ activityDate , setActivityDate ] = useState(undefined);
|
||||
|
||||
const [ statisticData , setStatisticData ] = useState(undefined);
|
||||
|
||||
const username = props.match.params.username;
|
||||
const current_user = props.current_user;
|
||||
|
@ -27,21 +35,63 @@ function Index(props) {
|
|||
useEffect(()=>{
|
||||
if(user){
|
||||
let c = user.created_time && user.created_time.split("-")[0];
|
||||
setCreateYear(parseInt(c,0));
|
||||
let y = moment().get('year');
|
||||
let array = []
|
||||
for(var i = y ; i >= parseInt(c,0);i--){
|
||||
array.push(i);
|
||||
}
|
||||
setYearList(array);
|
||||
}
|
||||
},[user])
|
||||
|
||||
// 在贡献度日历表中选择一个时间
|
||||
function chooseTime(data) {
|
||||
if(data){
|
||||
console.log(data);
|
||||
setActivityDate(data[0]);
|
||||
}
|
||||
}
|
||||
|
||||
function renderYear(){
|
||||
let y = moment().get('year');
|
||||
for(var i = y ; i > createYear;i--){
|
||||
}
|
||||
// 年份下拉框option
|
||||
function renderYear(list){
|
||||
return list.map((i,k)=>{
|
||||
return(
|
||||
<Option key={i}>{i}</Option>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(()=>{
|
||||
getActivity();
|
||||
},[activityDate,page])
|
||||
|
||||
// 获取动态列表
|
||||
function getActivity() {
|
||||
const url = `/users/${username}/project_trends.json`;
|
||||
Axios.get(url,{
|
||||
params:{
|
||||
date:activityDate,
|
||||
limit:aLimit,page
|
||||
}
|
||||
}).then(result=>{
|
||||
if(result && result.data){
|
||||
setProjectTrends(result.data.project_trends);
|
||||
setTotal(result.data.total_count);
|
||||
}
|
||||
}).catch(error=>{})
|
||||
}
|
||||
|
||||
// 获取近期活动统计
|
||||
useEffect(()=>{
|
||||
getStatistics();
|
||||
},[])
|
||||
|
||||
function getStatistics() {
|
||||
const url = `/users/${username}/statistics/activity.json`;
|
||||
Axios.get(url).then(result=>{
|
||||
if(result && result.data){
|
||||
setStatisticData(result.data);
|
||||
}
|
||||
}).catch(error=>{})
|
||||
}
|
||||
|
||||
return(
|
||||
|
@ -50,21 +100,21 @@ function Index(props) {
|
|||
<ConcentrateProject userLogin={username} current={current_user && (current_user.login === username)}/>
|
||||
</div>
|
||||
<div className="recentStatic">
|
||||
<Line />
|
||||
<Line data={statisticData}/>
|
||||
</div>
|
||||
<div className="calendarStatic">
|
||||
<FlexAJ>
|
||||
<span className="font-18">贡献度</span>
|
||||
<Select style={{width:"200px"}} placeholder="选择年份">
|
||||
<Select.Option key="">选择年份</Select.Option>
|
||||
{ createYear && renderYear()}
|
||||
<Select style={{width:"200px"}} placeholder="选择年份" value={year} onSelect={(e)=>setYear(e)}>
|
||||
<Option key={"0"}>选择年份</Option>
|
||||
{ yearList && renderYear(yearList) }
|
||||
</Select>
|
||||
</FlexAJ>
|
||||
<Calendar time={''} userLogin={username} chooseTime={chooseTime}/>
|
||||
<Calendar time={year} userLogin={username} chooseTime={chooseTime}/>
|
||||
</div>
|
||||
<div className="activeStatic">
|
||||
<span className="font-18">动态</span>
|
||||
<Activity />
|
||||
{ projectTrends && projectTrends.length > 0 && <Activity list = {projectTrends}/> }
|
||||
{ total > aLimit && <div style={{textAlign:'center',paddingBottom:"30px"}}><Pagination pageSize={aLimit} current={page} total={total} onChange={(p)=>setPage(p)}/></div> }
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue