2019-01-12 03:33:27 +00:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import { getOptionProps, initDefaultProps } from '../_util/props-util';
|
2019-04-25 12:23:14 +00:00
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
2019-01-12 03:33:27 +00:00
|
|
|
import Icon from '../icon';
|
2019-04-25 12:23:14 +00:00
|
|
|
import Line from './line';
|
|
|
|
import Circle from './circle';
|
|
|
|
import { validProgress } from './utils';
|
2018-04-03 06:14:38 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
function addUnit(num, unit) {
|
|
|
|
const unitType = unit || 'px';
|
|
|
|
return num ? num + unitType : null;
|
2018-04-03 06:14:38 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export const ProgressType = PropTypes.oneOf(['line', 'circle', 'dashboard']);
|
|
|
|
export const ProgressSize = PropTypes.oneOf(['default', 'small']);
|
2018-09-05 13:28:54 +00:00
|
|
|
|
2018-04-03 06:14:38 +00:00
|
|
|
export const ProgressProps = {
|
|
|
|
prefixCls: PropTypes.string,
|
2018-09-05 13:28:54 +00:00
|
|
|
type: ProgressType,
|
2018-04-03 06:14:38 +00:00
|
|
|
percent: PropTypes.number,
|
|
|
|
successPercent: PropTypes.number,
|
|
|
|
format: PropTypes.func,
|
2018-11-10 14:27:12 +00:00
|
|
|
status: PropTypes.oneOf(['normal', 'success', 'active', 'exception']),
|
2018-04-03 06:14:38 +00:00
|
|
|
showInfo: PropTypes.bool,
|
|
|
|
strokeWidth: PropTypes.number,
|
2018-09-05 13:28:54 +00:00
|
|
|
strokeLinecap: PropTypes.oneOf(['round', 'square']),
|
|
|
|
strokeColor: PropTypes.string,
|
2018-04-03 06:14:38 +00:00
|
|
|
trailColor: PropTypes.string,
|
|
|
|
width: PropTypes.number,
|
|
|
|
gapDegree: PropTypes.number,
|
|
|
|
gapPosition: PropTypes.oneOf(['top', 'bottom', 'left', 'right']),
|
2018-09-05 13:28:54 +00:00
|
|
|
size: ProgressSize,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-09-05 13:28:54 +00:00
|
|
|
|
2018-04-03 06:14:38 +00:00
|
|
|
export default {
|
2018-04-08 13:17:20 +00:00
|
|
|
name: 'AProgress',
|
2018-04-03 06:14:38 +00:00
|
|
|
props: initDefaultProps(ProgressProps, {
|
|
|
|
type: 'line',
|
|
|
|
percent: 0,
|
|
|
|
showInfo: true,
|
|
|
|
trailColor: '#f3f3f3',
|
|
|
|
size: 'default',
|
2019-04-25 12:23:14 +00:00
|
|
|
gapDegree: 0,
|
|
|
|
strokeLinecap: 'round',
|
2018-04-03 06:14:38 +00:00
|
|
|
}),
|
2019-04-25 12:23:14 +00:00
|
|
|
inject: {
|
2019-09-11 14:35:25 +00:00
|
|
|
configProvider: { default: () => ConfigConsumerProps },
|
2019-04-25 12:23:14 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
renderProcessInfo(prefixCls, progressStatus) {
|
|
|
|
const { showInfo, format, type, percent, successPercent } = this.$props;
|
|
|
|
if (!showInfo) return null;
|
2018-04-03 06:14:38 +00:00
|
|
|
|
2019-04-25 12:23:14 +00:00
|
|
|
let text;
|
|
|
|
const textFormatter = format || (percentNumber => `${percentNumber}%`);
|
|
|
|
const iconType = type === 'circle' || type === 'dashboard' ? '' : '-circle';
|
|
|
|
if (format || (progressStatus !== 'exception' && progressStatus !== 'success')) {
|
|
|
|
text = textFormatter(validProgress(percent), validProgress(successPercent));
|
|
|
|
} else if (progressStatus === 'exception') {
|
|
|
|
text = <Icon type={`close${iconType}`} theme={type === 'line' ? 'filled' : 'outlined'} />;
|
|
|
|
} else if (progressStatus === 'success') {
|
|
|
|
text = <Icon type={`check${iconType}`} theme={type === 'line' ? 'filled' : 'outlined'} />;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<span class={`${prefixCls}-text`} title={typeof text === 'string' ? text : undefined}>
|
|
|
|
{text}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
const props = getOptionProps(this);
|
2018-04-03 06:14:38 +00:00
|
|
|
const {
|
2019-04-25 12:23:14 +00:00
|
|
|
prefixCls: customizePrefixCls,
|
2019-01-12 03:33:27 +00:00
|
|
|
percent = 0,
|
|
|
|
status,
|
|
|
|
format,
|
|
|
|
trailColor,
|
|
|
|
size,
|
|
|
|
successPercent,
|
|
|
|
type,
|
|
|
|
strokeWidth,
|
|
|
|
width,
|
|
|
|
showInfo,
|
|
|
|
gapDegree = 0,
|
|
|
|
gapPosition,
|
|
|
|
strokeColor,
|
|
|
|
strokeLinecap = 'round',
|
2018-09-05 13:28:54 +00:00
|
|
|
...restProps
|
2019-01-12 03:33:27 +00:00
|
|
|
} = props;
|
2019-09-11 14:35:25 +00:00
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
2019-04-25 12:23:14 +00:00
|
|
|
const prefixCls = getPrefixCls('progress', customizePrefixCls);
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const progressStatus =
|
2019-05-28 03:37:38 +00:00
|
|
|
parseInt(successPercent !== undefined ? successPercent.toString() : percent.toString(), 10) >=
|
|
|
|
100 && !('status' in props)
|
2019-01-12 03:33:27 +00:00
|
|
|
? 'success'
|
|
|
|
: status || 'normal';
|
|
|
|
let progress;
|
2019-04-25 12:23:14 +00:00
|
|
|
const progressInfo = this.renderProcessInfo(prefixCls, progressStatus);
|
2018-04-03 06:14:38 +00:00
|
|
|
|
2019-04-25 12:23:14 +00:00
|
|
|
// Render progress shape
|
2018-04-03 06:14:38 +00:00
|
|
|
if (type === 'line') {
|
2019-04-25 12:23:14 +00:00
|
|
|
const lineProps = {
|
|
|
|
props: {
|
|
|
|
...props,
|
|
|
|
prefixCls,
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2019-05-28 03:37:38 +00:00
|
|
|
progress = <Line {...lineProps}>{progressInfo}</Line>;
|
2018-04-03 06:14:38 +00:00
|
|
|
} else if (type === 'circle' || type === 'dashboard') {
|
2019-04-25 12:23:14 +00:00
|
|
|
const circleProps = {
|
|
|
|
props: {
|
|
|
|
...props,
|
|
|
|
prefixCls,
|
|
|
|
progressStatus,
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2019-05-28 03:37:38 +00:00
|
|
|
progress = <Circle {...circleProps}>{progressInfo}</Circle>;
|
2018-04-03 06:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const classString = classNames(prefixCls, {
|
2019-01-12 03:33:27 +00:00
|
|
|
[`${prefixCls}-${(type === 'dashboard' && 'circle') || type}`]: true,
|
2018-04-03 06:14:38 +00:00
|
|
|
[`${prefixCls}-status-${progressStatus}`]: true,
|
|
|
|
[`${prefixCls}-show-info`]: showInfo,
|
|
|
|
[`${prefixCls}-${size}`]: size,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-04-03 06:14:38 +00:00
|
|
|
|
|
|
|
const progressProps = {
|
2018-09-05 13:28:54 +00:00
|
|
|
props: {
|
|
|
|
...restProps,
|
|
|
|
},
|
2018-04-03 06:14:38 +00:00
|
|
|
on: this.$listeners,
|
|
|
|
class: classString,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
|
|
|
return <div {...progressProps}>{progress}</div>;
|
2018-04-03 06:14:38 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|