2020-10-17 03:51:17 +00:00
|
|
|
import { defineComponent, inject, 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 { getComponent } from '../_util/props-util';
|
|
|
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
|
|
|
import { defaultConfigProvider } from '../config-provider';
|
2020-10-17 03:23:31 +00:00
|
|
|
import StatisticNumber from './Number';
|
2020-10-17 03:51:17 +00:00
|
|
|
import { countdownValueType } from './utils';
|
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,
|
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: ',',
|
|
|
|
}),
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
return {
|
|
|
|
configProvider: inject('configProvider', defaultConfigProvider),
|
|
|
|
};
|
2020-10-17 03:23:31 +00:00
|
|
|
},
|
|
|
|
|
2020-10-17 03:51:17 +00:00
|
|
|
render() {
|
|
|
|
const { prefixCls: customizePrefixCls, value = 0, valueStyle, valueRender } = this.$props;
|
|
|
|
const { getPrefixCls } = this.configProvider;
|
|
|
|
const prefixCls = getPrefixCls('statistic', customizePrefixCls);
|
2020-10-17 03:23:31 +00:00
|
|
|
|
|
|
|
const title = getComponent(this, 'title');
|
2020-10-19 08:43:10 +00:00
|
|
|
const prefix = getComponent(this, 'prefix');
|
|
|
|
const suffix = getComponent(this, 'suffix');
|
2020-10-17 03:51:17 +00:00
|
|
|
const formatter = getComponent(this, 'formatter', {}, false);
|
|
|
|
const props = {
|
|
|
|
...this.$props,
|
|
|
|
prefixCls,
|
|
|
|
value,
|
|
|
|
formatter,
|
|
|
|
};
|
|
|
|
let valueNode = <StatisticNumber {...props} />;
|
|
|
|
if (valueRender) {
|
|
|
|
valueNode = valueRender(valueNode);
|
|
|
|
}
|
2020-10-17 03:23:31 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div class={prefixCls}>
|
|
|
|
{title && <div class={`${prefixCls}-title`}>{title}</div>}
|
|
|
|
<div style={valueStyle} class={`${prefixCls}-content`}>
|
|
|
|
{prefix && <span class={`${prefixCls}-content-prefix`}>{prefix}</span>}
|
2020-10-17 03:51:17 +00:00
|
|
|
{valueNode}
|
2020-10-17 03:23:31 +00:00
|
|
|
{suffix && <span class={`${prefixCls}-content-suffix`}>{suffix}</span>}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|