2015-07-23 22:23:11 +08:00
|
|
|
import {Line as Progressline, Circle as Progresscircle} from 'rc-progress';
|
|
|
|
import React from 'react';
|
|
|
|
import assign from 'object-assign';
|
2015-06-14 12:55:44 +08:00
|
|
|
|
|
|
|
var Line = React.createClass({
|
2015-07-06 10:58:34 +08:00
|
|
|
getDefaultProps() {
|
2015-06-14 12:55:44 +08:00
|
|
|
return {
|
2015-06-15 16:16:51 +08:00
|
|
|
width: 300,
|
2015-06-14 12:55:44 +08:00
|
|
|
percent: 0,
|
2015-06-15 16:16:51 +08:00
|
|
|
strokeWidth: 3,
|
2015-06-15 11:00:27 +08:00
|
|
|
status: 'normal' // exception
|
2015-06-15 11:48:30 +08:00
|
|
|
};
|
2015-06-14 12:55:44 +08:00
|
|
|
},
|
|
|
|
render() {
|
2015-06-14 19:50:23 +08:00
|
|
|
var statusColorMap = {
|
2015-06-15 11:00:27 +08:00
|
|
|
'normal': '#3FC7FA',
|
|
|
|
'exception': '#FE8C6A',
|
|
|
|
'success': '#85D262'
|
2015-06-14 19:50:23 +08:00
|
|
|
};
|
|
|
|
|
2015-07-08 20:53:11 +08:00
|
|
|
var props = assign({}, this.props);
|
|
|
|
|
|
|
|
if (parseInt(props.percent) === 100) {
|
|
|
|
props.status = 'success';
|
2015-06-14 19:50:23 +08:00
|
|
|
}
|
|
|
|
|
2015-06-14 12:55:44 +08:00
|
|
|
var style = {
|
2015-07-08 20:53:11 +08:00
|
|
|
'width': props.width
|
2015-06-15 11:48:30 +08:00
|
|
|
};
|
2015-07-08 20:53:11 +08:00
|
|
|
var fontSize = (props.width / 100 * props.strokeWidth);
|
2015-06-15 16:16:51 +08:00
|
|
|
var iconStyle = {
|
2015-07-09 18:17:15 +08:00
|
|
|
'fontSize': (fontSize < 12) ? 12 : fontSize
|
2015-06-15 11:48:30 +08:00
|
|
|
};
|
2015-06-14 19:50:23 +08:00
|
|
|
var textStyle = {
|
2015-07-08 20:53:11 +08:00
|
|
|
'color': statusColorMap[props.status]
|
2015-06-15 11:48:30 +08:00
|
|
|
};
|
|
|
|
var progressInfo;
|
2015-07-08 20:53:11 +08:00
|
|
|
if (props.status === 'exception') {
|
2015-06-14 12:55:44 +08:00
|
|
|
progressInfo = (
|
2015-06-15 11:00:27 +08:00
|
|
|
<span style={textStyle} className='ant-progress-line-text'>
|
2015-06-18 10:43:35 +08:00
|
|
|
<i style={iconStyle} className="anticon anticon-exclamation-circle"></i>
|
2015-06-14 19:50:23 +08:00
|
|
|
</span>
|
2015-06-15 11:48:30 +08:00
|
|
|
);
|
2015-07-08 20:53:11 +08:00
|
|
|
} else if (props.status === 'success') {
|
2015-06-14 19:50:23 +08:00
|
|
|
progressInfo = (
|
2015-06-15 11:00:27 +08:00
|
|
|
<span style={textStyle} className='ant-progress-line-text'>
|
2015-06-18 10:43:35 +08:00
|
|
|
<i style={iconStyle} className="anticon anticon-check-circle"></i>
|
2015-06-14 19:50:23 +08:00
|
|
|
</span>
|
2015-06-15 11:48:30 +08:00
|
|
|
);
|
2015-07-06 10:58:34 +08:00
|
|
|
} else {
|
2015-06-14 12:55:44 +08:00
|
|
|
progressInfo = (
|
2015-07-08 20:53:11 +08:00
|
|
|
<span className='ant-progress-line-text'>{props.percent}%</span>
|
2015-06-15 11:48:30 +08:00
|
|
|
);
|
2015-06-14 12:55:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2015-07-06 10:58:34 +08:00
|
|
|
<div className='ant-progress-line-wrap'>
|
2015-06-15 11:00:27 +08:00
|
|
|
<div className='ant-progress-line-inner' style={style}>
|
2015-07-08 20:53:11 +08:00
|
|
|
<Progressline percent={props.percent} strokeWidth={props.strokeWidth}
|
|
|
|
strokeColor={statusColorMap[props.status]} trailColor="#e9e9e9" />
|
2015-06-14 19:50:23 +08:00
|
|
|
</div>
|
2015-06-14 12:55:44 +08:00
|
|
|
{progressInfo}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var Circle = React.createClass({
|
2015-06-14 19:50:23 +08:00
|
|
|
getDefaultProps: function () {
|
2015-06-14 12:55:44 +08:00
|
|
|
return {
|
2015-06-15 17:30:24 +08:00
|
|
|
width: 132,
|
2015-06-14 12:55:44 +08:00
|
|
|
percent: 0,
|
2015-06-15 17:30:24 +08:00
|
|
|
strokeWidth: 6,
|
2015-06-15 11:00:27 +08:00
|
|
|
status: 'normal' // exception
|
2015-06-15 11:48:30 +08:00
|
|
|
};
|
2015-06-14 12:55:44 +08:00
|
|
|
},
|
|
|
|
render() {
|
2015-06-14 20:07:21 +08:00
|
|
|
var statusColorMap = {
|
2015-06-15 11:00:27 +08:00
|
|
|
'normal': '#3FC7FA',
|
|
|
|
'exception': '#FE8C6A',
|
|
|
|
'success': '#85D262'
|
2015-06-14 20:07:21 +08:00
|
|
|
};
|
|
|
|
|
2015-07-08 20:53:11 +08:00
|
|
|
var props = assign({}, this.props);
|
|
|
|
|
|
|
|
if (parseInt(props.percent) === 100) {
|
|
|
|
props.status = 'success';
|
2015-06-14 20:07:21 +08:00
|
|
|
}
|
|
|
|
|
2015-06-14 12:55:44 +08:00
|
|
|
var style = {
|
2015-07-08 20:53:11 +08:00
|
|
|
'width': props.width,
|
|
|
|
'height': props.width
|
2015-06-15 11:48:30 +08:00
|
|
|
};
|
2015-06-14 20:07:21 +08:00
|
|
|
var wrapStyle = {
|
2015-07-08 20:53:11 +08:00
|
|
|
'fontSize': props.width * 0.16 + 6
|
2015-06-15 11:48:30 +08:00
|
|
|
};
|
2015-06-14 20:07:21 +08:00
|
|
|
var textStyle = {
|
2015-07-08 20:53:11 +08:00
|
|
|
'color': statusColorMap[props.status]
|
2015-06-15 11:48:30 +08:00
|
|
|
};
|
|
|
|
var progressInfo;
|
2015-07-08 20:53:11 +08:00
|
|
|
if (props.status === 'exception') {
|
2015-06-14 12:55:44 +08:00
|
|
|
progressInfo = (
|
2015-06-15 11:00:27 +08:00
|
|
|
<span style={textStyle} className='ant-progress-circle-text'>
|
|
|
|
<i className='anticon anticon-exclamation'></i>
|
2015-06-14 20:07:21 +08:00
|
|
|
</span>
|
2015-06-15 11:48:30 +08:00
|
|
|
);
|
2015-07-08 20:53:11 +08:00
|
|
|
} else if (props.status === 'success') {
|
2015-06-15 16:16:51 +08:00
|
|
|
progressInfo = (
|
|
|
|
<span style={textStyle} className='ant-progress-circle-text'>
|
|
|
|
<i className="anticon anticon-check"></i>
|
|
|
|
</span>
|
|
|
|
);
|
2015-07-06 10:58:34 +08:00
|
|
|
} else {
|
2015-06-14 12:55:44 +08:00
|
|
|
progressInfo = (
|
2015-07-08 20:53:11 +08:00
|
|
|
<span className="ant-progress-circle-text">{props.percent}%</span>
|
2015-06-15 11:48:30 +08:00
|
|
|
);
|
2015-06-14 12:55:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2015-06-14 20:07:21 +08:00
|
|
|
<div className="ant-progress-circle-wrap" style={wrapStyle}>
|
|
|
|
<div className="ant-progress-circle-inner" style={style}>
|
2015-07-08 20:53:11 +08:00
|
|
|
<Progresscircle percent={props.percent} strokeWidth={props.strokeWidth}
|
|
|
|
strokeColor={statusColorMap[props.status]} trailColor="#e9e9e9" />
|
2015-06-14 20:07:21 +08:00
|
|
|
{progressInfo}
|
|
|
|
</div>
|
2015-06-14 12:55:44 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-23 22:23:11 +08:00
|
|
|
export default {
|
2015-06-14 12:55:44 +08:00
|
|
|
Line: Line,
|
|
|
|
Circle: Circle
|
|
|
|
};
|
|
|
|
|
|
|
|
|