2021-06-10 15:04:57 +00:00
|
|
|
import { defineComponent, PropType } from 'vue';
|
2020-10-17 03:23:31 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2020-10-17 03:51:17 +00:00
|
|
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
2020-10-17 03:23:31 +00:00
|
|
|
import StatisticNumber from './Number';
|
2020-10-17 03:51:17 +00:00
|
|
|
import { countdownValueType } from './utils';
|
2021-06-10 15:04:57 +00:00
|
|
|
import Skeleton from '../skeleton/Skeleton';
|
|
|
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
2020-10-17 03:23:31 +00:00
|
|
|
|
|
|
|
export const StatisticProps = {
|
2020-10-17 03:51:17 +00:00
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
decimalSeparator: PropTypes.string,
|
|
|
|
groupSeparator: PropTypes.string,
|
|
|
|
format: PropTypes.string,
|
|
|
|
value: {
|
|
|
|
type: [String, Number, Object] as PropType<countdownValueType>,
|
|
|
|
},
|
|
|
|
valueStyle: PropTypes.style,
|
|
|
|
valueRender: PropTypes.any,
|
|
|
|
formatter: PropTypes.any,
|
2020-10-17 03:23:31 +00:00
|
|
|
precision: PropTypes.number,
|
|
|
|
prefix: PropTypes.VNodeChild,
|
|
|
|
suffix: PropTypes.VNodeChild,
|
|
|
|
title: PropTypes.VNodeChild,
|
2020-10-17 03:51:17 +00:00
|
|
|
onFinish: PropTypes.func,
|
2021-06-10 15:04:57 +00:00
|
|
|
loading: PropTypes.looseBool,
|
2020-10-17 03:23:31 +00:00
|
|
|
};
|
|
|
|
|
2020-10-17 03:51:17 +00:00
|
|
|
export default defineComponent({
|
2020-10-17 03:23:31 +00:00
|
|
|
name: 'AStatistic',
|
2020-10-17 03:51:17 +00:00
|
|
|
props: initDefaultProps(StatisticProps, {
|
|
|
|
decimalSeparator: '.',
|
|
|
|
groupSeparator: ',',
|
2021-06-10 15:04:57 +00:00
|
|
|
loading: false,
|
2020-10-17 03:51:17 +00:00
|
|
|
}),
|
2021-06-10 15:04:57 +00:00
|
|
|
slots: ['title', 'prefix', 'suffix', 'formatter'],
|
|
|
|
setup(props, { slots }) {
|
|
|
|
const { prefixCls, direction } = useConfigInject('statistic', props);
|
|
|
|
return () => {
|
|
|
|
const { value = 0, valueStyle, valueRender } = props;
|
|
|
|
const pre = prefixCls.value;
|
|
|
|
const title = props.title ?? slots.title?.();
|
|
|
|
const prefix = props.prefix ?? slots.prefix?.();
|
|
|
|
const suffix = props.suffix ?? slots.suffix?.();
|
|
|
|
const formatter = props.formatter ?? slots.formatter;
|
|
|
|
// data-for-update just for update component
|
|
|
|
// https://github.com/vueComponent/ant-design-vue/pull/3170
|
|
|
|
let valueNode = (
|
|
|
|
<StatisticNumber
|
|
|
|
data-for-update={Date.now()}
|
|
|
|
{...{ ...props, prefixCls: pre, value, formatter }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
if (valueRender) {
|
|
|
|
valueNode = valueRender(valueNode);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div class={[pre, { [`${pre}-rtl`]: direction.value === 'rtl' }]}>
|
|
|
|
{title && <div class={`${pre}-title`}>{title}</div>}
|
|
|
|
<Skeleton paragraph={false} loading={props.loading}>
|
|
|
|
<div style={valueStyle} class={`${pre}-content`}>
|
|
|
|
{prefix && <span class={`${pre}-content-prefix`}>{prefix}</span>}
|
|
|
|
{valueNode}
|
|
|
|
{suffix && <span class={`${pre}-content-suffix`}>{suffix}</span>}
|
|
|
|
</div>
|
|
|
|
</Skeleton>
|
2020-10-17 03:23:31 +00:00
|
|
|
</div>
|
2021-06-10 15:04:57 +00:00
|
|
|
);
|
|
|
|
};
|
2020-10-17 03:23:31 +00:00
|
|
|
},
|
|
|
|
});
|