2021-09-25 08:51:32 +00:00
|
|
|
import type { VNodeChild } from 'vue';
|
|
|
|
import { computed, defineComponent } from 'vue';
|
2020-10-17 12:52:58 +00:00
|
|
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
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';
|
2021-09-25 08:51:32 +00:00
|
|
|
import Line from './Line';
|
|
|
|
import Circle from './Circle';
|
|
|
|
import Steps from './Steps';
|
|
|
|
import { getSuccessPercent, validProgress } from './utils';
|
|
|
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
|
|
|
import devWarning from '../vc-util/devWarning';
|
|
|
|
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',
|
2021-09-25 08:51:32 +00:00
|
|
|
props: initDefaultProps(progressProps(), {
|
2018-04-03 06:14:38 +00:00
|
|
|
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
|
|
|
}),
|
2021-09-25 08:51:32 +00:00
|
|
|
slots: ['format'],
|
|
|
|
setup(props, { slots }) {
|
|
|
|
const { prefixCls, direction } = useConfigInject('progress', props);
|
|
|
|
devWarning(
|
|
|
|
props.successPercent == undefined,
|
|
|
|
'Progress',
|
|
|
|
'`successPercent` is deprecated. Please use `success.percent` instead.',
|
|
|
|
);
|
|
|
|
const classString = computed(() => {
|
|
|
|
const { type, showInfo, size } = props;
|
|
|
|
const pre = prefixCls.value;
|
|
|
|
return {
|
|
|
|
[pre]: true,
|
|
|
|
[`${pre}-${(type === 'dashboard' && 'circle') || type}`]: true,
|
|
|
|
[`${pre}-show-info`]: showInfo,
|
|
|
|
[`${pre}-${size}`]: size,
|
|
|
|
[`${pre}-rtl`]: direction.value === 'rtl',
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
const percentNumber = computed(() => {
|
|
|
|
const { percent = 0 } = props;
|
|
|
|
const successPercent = getSuccessPercent(props);
|
2020-03-07 11:45:13 +00:00
|
|
|
return parseInt(
|
|
|
|
successPercent !== undefined ? successPercent.toString() : percent.toString(),
|
|
|
|
10,
|
|
|
|
);
|
2021-09-25 08:51:32 +00:00
|
|
|
});
|
2020-03-07 11:45:13 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
const progressStatus = computed(() => {
|
|
|
|
const { status } = props;
|
|
|
|
if (progressStatuses.indexOf(status) < 0 && percentNumber.value >= 100) {
|
2020-03-07 11:45:13 +00:00
|
|
|
return 'success';
|
|
|
|
}
|
|
|
|
return status || 'normal';
|
2021-09-25 08:51:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const renderProcessInfo = () => {
|
|
|
|
const { showInfo, format, type, percent } = props;
|
|
|
|
const successPercent = getSuccessPercent(props);
|
2019-04-25 12:23:14 +00:00
|
|
|
if (!showInfo) return null;
|
2018-04-03 06:14:38 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
let text: VNodeChild;
|
|
|
|
const textFormatter = format || slots?.format || ((val: number) => `${val}%`);
|
2020-04-02 06:42:50 +00:00
|
|
|
const isLineType = type === 'line';
|
2019-10-30 08:38:15 +00:00
|
|
|
if (
|
|
|
|
format ||
|
2021-09-25 08:51:32 +00:00
|
|
|
slots?.format ||
|
|
|
|
(progressStatus.value !== 'exception' && progressStatus.value !== 'success')
|
2019-10-30 08:38:15 +00:00
|
|
|
) {
|
2019-04-25 12:23:14 +00:00
|
|
|
text = textFormatter(validProgress(percent), validProgress(successPercent));
|
2021-09-25 08:51:32 +00:00
|
|
|
} else if (progressStatus.value === 'exception') {
|
2020-04-02 06:42:50 +00:00
|
|
|
text = isLineType ? <CloseCircleFilled /> : <CloseOutlined />;
|
2021-09-25 08:51:32 +00:00
|
|
|
} else if (progressStatus.value === 'success') {
|
2020-04-02 06:42:50 +00:00
|
|
|
text = isLineType ? <CheckCircleFilled /> : <CheckOutlined />;
|
2019-04-25 12:23:14 +00:00
|
|
|
}
|
|
|
|
return (
|
2021-09-25 08:51:32 +00:00
|
|
|
<span class={`${prefixCls.value}-text`} title={typeof text === 'string' ? text : undefined}>
|
2019-04-25 12:23:14 +00:00
|
|
|
{text}
|
|
|
|
</span>
|
|
|
|
);
|
2021-09-25 08:51:32 +00:00
|
|
|
};
|
2019-04-25 12:23:14 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
return () => {
|
|
|
|
const { type, steps, strokeColor } = props;
|
|
|
|
const progressInfo = renderProcessInfo();
|
2018-04-03 06:14:38 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
let progress: VNodeChild;
|
|
|
|
// Render progress shape
|
|
|
|
if (type === 'line') {
|
|
|
|
progress = steps ? (
|
|
|
|
<Steps
|
|
|
|
{...props}
|
|
|
|
strokeColor={typeof strokeColor === 'string' ? strokeColor : undefined}
|
|
|
|
prefixCls={prefixCls.value}
|
|
|
|
steps={steps}
|
|
|
|
>
|
|
|
|
{progressInfo}
|
|
|
|
</Steps>
|
|
|
|
) : (
|
|
|
|
<Line {...props} prefixCls={prefixCls.value}>
|
|
|
|
{progressInfo}
|
|
|
|
</Line>
|
|
|
|
);
|
|
|
|
} else if (type === 'circle' || type === 'dashboard') {
|
|
|
|
progress = (
|
|
|
|
<Circle {...props} prefixCls={prefixCls.value}>
|
|
|
|
{progressInfo}
|
|
|
|
</Circle>
|
|
|
|
);
|
|
|
|
}
|
2018-04-03 06:14:38 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
const classNames = {
|
|
|
|
...classString.value,
|
|
|
|
[`${prefixCls.value}-status-${progressStatus.value}`]: true,
|
|
|
|
};
|
2018-04-03 06:14:38 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
return <div class={classNames}>{progress}</div>;
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-04-03 06:14:38 +00:00
|
|
|
},
|
2020-10-17 12:52:58 +00:00
|
|
|
});
|