2020-10-17 12:52:58 +00:00
|
|
|
import { defineComponent, inject } from 'vue';
|
2020-08-31 08:53:19 +00:00
|
|
|
import classNames from '../_util/classNames';
|
2020-10-17 12:52:58 +00:00
|
|
|
import { getOptionProps } from '../_util/props-util';
|
|
|
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
2020-09-30 02:47:18 +00:00
|
|
|
import { defaultConfigProvider } 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';
|
2020-10-17 12:52:58 +00:00
|
|
|
import { ProgressProps, ProgressStatuses } from './props';
|
2018-04-03 06:14:38 +00:00
|
|
|
|
2020-10-17 12:52:58 +00:00
|
|
|
export default defineComponent({
|
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,
|
2021-01-14 09:33:17 +00:00
|
|
|
// null for different theme definition
|
|
|
|
trailColor: null,
|
2018-04-03 06:14:38 +00:00
|
|
|
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 {
|
2020-09-30 02:47:18 +00:00
|
|
|
configProvider: inject('configProvider', defaultConfigProvider),
|
2020-06-26 02:08:47 +00:00
|
|
|
};
|
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';
|
|
|
|
},
|
2020-10-17 12:52:58 +00:00
|
|
|
renderProcessInfo(prefixCls: string, progressStatus: typeof ProgressStatuses[number]) {
|
2019-04-25 12:23:14 +00:00
|
|
|
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;
|
2020-10-17 12:52:58 +00:00
|
|
|
const { getPrefixCls } = this.configProvider;
|
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
|
|
|
},
|
2020-10-17 12:52:58 +00:00
|
|
|
});
|