2020-06-26 02:08:47 +00:00
|
|
|
import { inject } from 'vue';
|
2019-01-12 03:33:27 +00:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import PropTypes from '../_util/vue-types';
|
2020-06-26 02:08:47 +00:00
|
|
|
import { getOptionProps, initDefaultProps } from '../_util/props-util';
|
2019-04-25 12:23:14 +00:00
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
2020-04-02 06:42:50 +00:00
|
|
|
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
|
|
|
|
import CheckOutlined from '@ant-design/icons-vue/CheckOutlined';
|
|
|
|
import CheckCircleFilled from '@ant-design/icons-vue/CheckCircleFilled';
|
|
|
|
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
|
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
|
|
|
|
2020-03-07 11:45:13 +00:00
|
|
|
const ProgressStatuses = ['normal', 'exception', 'active', 'success'];
|
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,
|
2020-03-07 11:45:13 +00:00
|
|
|
status: PropTypes.oneOf(ProgressStatuses),
|
2018-04-03 06:14:38 +00:00
|
|
|
showInfo: PropTypes.bool,
|
|
|
|
strokeWidth: PropTypes.number,
|
2020-03-07 11:45:13 +00:00
|
|
|
strokeLinecap: PropTypes.oneOf(['butt', 'round', 'square']),
|
|
|
|
strokeColor: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
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
|
|
|
}),
|
2020-06-26 02:08:47 +00:00
|
|
|
setup() {
|
|
|
|
return {
|
|
|
|
configProvider: inject('configProvider', ConfigConsumerProps),
|
|
|
|
};
|
2019-04-25 12:23:14 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2020-03-07 11:45:13 +00:00
|
|
|
getPercentNumber() {
|
|
|
|
const { successPercent, percent = 0 } = this.$props;
|
|
|
|
return parseInt(
|
|
|
|
successPercent !== undefined ? successPercent.toString() : percent.toString(),
|
|
|
|
10,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
getProgressStatus() {
|
|
|
|
const { status } = this.$props;
|
|
|
|
if (ProgressStatuses.indexOf(status) < 0 && this.getPercentNumber() >= 100) {
|
|
|
|
return 'success';
|
|
|
|
}
|
|
|
|
return status || 'normal';
|
|
|
|
},
|
2019-04-25 12:23:14 +00:00
|
|
|
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;
|
2020-06-26 02:08:47 +00:00
|
|
|
const textFormatter = format || this.$slots.format || (percentNumber => `${percentNumber}%`);
|
2020-04-02 06:42:50 +00:00
|
|
|
const isLineType = type === 'line';
|
2019-10-30 08:38:15 +00:00
|
|
|
if (
|
|
|
|
format ||
|
2020-06-26 02:08:47 +00:00
|
|
|
this.$slots.format ||
|
2019-10-30 08:38:15 +00:00
|
|
|
(progressStatus !== 'exception' && progressStatus !== 'success')
|
|
|
|
) {
|
2019-04-25 12:23:14 +00:00
|
|
|
text = textFormatter(validProgress(percent), validProgress(successPercent));
|
|
|
|
} else if (progressStatus === 'exception') {
|
2020-04-02 06:42:50 +00:00
|
|
|
text = isLineType ? <CloseCircleFilled /> : <CloseOutlined />;
|
2019-04-25 12:23:14 +00:00
|
|
|
} else if (progressStatus === 'success') {
|
2020-04-02 06:42:50 +00:00
|
|
|
text = isLineType ? <CheckCircleFilled /> : <CheckOutlined />;
|
2019-04-25 12:23:14 +00:00
|
|
|
}
|
|
|
|
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);
|
2020-03-18 06:52:02 +00:00
|
|
|
const { prefixCls: customizePrefixCls, size, type, showInfo } = 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);
|
2020-03-07 11:45:13 +00:00
|
|
|
const progressStatus = this.getProgressStatus();
|
|
|
|
const progressInfo = this.renderProcessInfo(prefixCls, progressStatus);
|
2019-04-25 12:23:14 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
let progress;
|
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 = {
|
2020-06-26 02:08:47 +00:00
|
|
|
...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 = {
|
2020-06-26 02:08:47 +00:00
|
|
|
...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 = {
|
|
|
|
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
|
|
|
};
|