vuecssuiant-designantdreactantantd-vueenterprisefrontendui-designvue-antdvue-antd-uivue3vuecomponent
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.7 KiB
111 lines
3.7 KiB
4 years ago
|
import { defineComponent, inject } from 'vue';
|
||
4 years ago
|
import classNames from '../_util/classNames';
|
||
4 years ago
|
import { getOptionProps } from '../_util/props-util';
|
||
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
||
4 years ago
|
import { defaultConfigProvider } from '../config-provider';
|
||
5 years ago
|
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';
|
||
6 years ago
|
import Line from './line';
|
||
|
import Circle from './circle';
|
||
|
import { validProgress } from './utils';
|
||
4 years ago
|
import { ProgressProps, ProgressStatuses } from './props';
|
||
7 years ago
|
|
||
4 years ago
|
export default defineComponent({
|
||
7 years ago
|
name: 'AProgress',
|
||
7 years ago
|
props: initDefaultProps(ProgressProps, {
|
||
|
type: 'line',
|
||
|
percent: 0,
|
||
|
showInfo: true,
|
||
|
trailColor: '#f3f3f3',
|
||
|
size: 'default',
|
||
6 years ago
|
gapDegree: 0,
|
||
|
strokeLinecap: 'round',
|
||
7 years ago
|
}),
|
||
4 years ago
|
setup() {
|
||
|
return {
|
||
4 years ago
|
configProvider: inject('configProvider', defaultConfigProvider),
|
||
4 years ago
|
};
|
||
6 years ago
|
},
|
||
|
methods: {
|
||
5 years ago
|
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';
|
||
|
},
|
||
4 years ago
|
renderProcessInfo(prefixCls: string, progressStatus: typeof ProgressStatuses[number]) {
|
||
6 years ago
|
const { showInfo, format, type, percent, successPercent } = this.$props;
|
||
|
if (!showInfo) return null;
|
||
7 years ago
|
|
||
6 years ago
|
let text;
|
||
4 years ago
|
const textFormatter = format || this.$slots.format || (percentNumber => `${percentNumber}%`);
|
||
5 years ago
|
const isLineType = type === 'line';
|
||
5 years ago
|
if (
|
||
|
format ||
|
||
4 years ago
|
this.$slots.format ||
|
||
5 years ago
|
(progressStatus !== 'exception' && progressStatus !== 'success')
|
||
|
) {
|
||
6 years ago
|
text = textFormatter(validProgress(percent), validProgress(successPercent));
|
||
|
} else if (progressStatus === 'exception') {
|
||
5 years ago
|
text = isLineType ? <CloseCircleFilled /> : <CloseOutlined />;
|
||
6 years ago
|
} else if (progressStatus === 'success') {
|
||
5 years ago
|
text = isLineType ? <CheckCircleFilled /> : <CheckOutlined />;
|
||
6 years ago
|
}
|
||
|
return (
|
||
|
<span class={`${prefixCls}-text`} title={typeof text === 'string' ? text : undefined}>
|
||
|
{text}
|
||
|
</span>
|
||
|
);
|
||
|
},
|
||
|
},
|
||
6 years ago
|
render() {
|
||
|
const props = getOptionProps(this);
|
||
5 years ago
|
const { prefixCls: customizePrefixCls, size, type, showInfo } = props;
|
||
4 years ago
|
const { getPrefixCls } = this.configProvider;
|
||
6 years ago
|
const prefixCls = getPrefixCls('progress', customizePrefixCls);
|
||
5 years ago
|
const progressStatus = this.getProgressStatus();
|
||
|
const progressInfo = this.renderProcessInfo(prefixCls, progressStatus);
|
||
6 years ago
|
|
||
6 years ago
|
let progress;
|
||
7 years ago
|
|
||
6 years ago
|
// Render progress shape
|
||
7 years ago
|
if (type === 'line') {
|
||
6 years ago
|
const lineProps = {
|
||
4 years ago
|
...props,
|
||
|
prefixCls,
|
||
6 years ago
|
};
|
||
6 years ago
|
progress = <Line {...lineProps}>{progressInfo}</Line>;
|
||
7 years ago
|
} else if (type === 'circle' || type === 'dashboard') {
|
||
6 years ago
|
const circleProps = {
|
||
4 years ago
|
...props,
|
||
|
prefixCls,
|
||
|
progressStatus,
|
||
6 years ago
|
};
|
||
6 years ago
|
progress = <Circle {...circleProps}>{progressInfo}</Circle>;
|
||
7 years ago
|
}
|
||
|
|
||
|
const classString = classNames(prefixCls, {
|
||
6 years ago
|
[`${prefixCls}-${(type === 'dashboard' && 'circle') || type}`]: true,
|
||
7 years ago
|
[`${prefixCls}-status-${progressStatus}`]: true,
|
||
|
[`${prefixCls}-show-info`]: showInfo,
|
||
|
[`${prefixCls}-${size}`]: size,
|
||
6 years ago
|
});
|
||
7 years ago
|
|
||
|
const progressProps = {
|
||
|
class: classString,
|
||
6 years ago
|
};
|
||
|
return <div {...progressProps}>{progress}</div>;
|
||
7 years ago
|
},
|
||
4 years ago
|
});
|