parent
1dd43884d7
commit
6fb936d985
|
@ -1,6 +1,6 @@
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import interopDefault from '../_util/interopDefault';
|
import interopDefault from '../_util/interopDefault';
|
||||||
import { initDefaultProps, getListeners } from '../_util/props-util';
|
import { initDefaultProps } from '../_util/props-util';
|
||||||
import Statistic, { StatisticProps } from './Statistic';
|
import Statistic, { StatisticProps } from './Statistic';
|
||||||
import { formatCountdown } from './utils';
|
import { formatCountdown } from './utils';
|
||||||
|
|
||||||
|
@ -82,7 +82,6 @@ export default {
|
||||||
valueRender: this.valueRenderHtml,
|
valueRender: this.valueRenderHtml,
|
||||||
formatter: this.formatCountdown,
|
formatter: this.formatCountdown,
|
||||||
},
|
},
|
||||||
on: getListeners(this),
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,57 +1,50 @@
|
||||||
import padEnd from 'lodash/padEnd';
|
import padEnd from 'lodash/padEnd';
|
||||||
|
import { createVNode } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default (_, { attrs }) => {
|
||||||
name: 'AStatisticNumber',
|
const { value, formatter, precision, decimalSeparator, groupSeparator = '', prefixCls } = attrs;
|
||||||
functional: true,
|
let valueNode;
|
||||||
render(h, context) {
|
|
||||||
const {
|
|
||||||
value,
|
|
||||||
formatter,
|
|
||||||
precision,
|
|
||||||
decimalSeparator,
|
|
||||||
groupSeparator = '',
|
|
||||||
prefixCls,
|
|
||||||
} = context.props;
|
|
||||||
let valueNode;
|
|
||||||
|
|
||||||
if (typeof formatter === 'function') {
|
if (typeof formatter === 'function') {
|
||||||
// Customize formatter
|
// Customize formatter
|
||||||
valueNode = formatter({ value, h });
|
valueNode = formatter({ value, h: createVNode });
|
||||||
|
} else {
|
||||||
|
// Internal formatter
|
||||||
|
const val = String(value);
|
||||||
|
const cells = val.match(/^(-?)(\d*)(\.(\d+))?$/);
|
||||||
|
// Process if illegal number
|
||||||
|
if (!cells) {
|
||||||
|
valueNode = val;
|
||||||
} else {
|
} else {
|
||||||
// Internal formatter
|
const negative = cells[1];
|
||||||
const val = String(value);
|
let int = cells[2] || '0';
|
||||||
const cells = val.match(/^(-?)(\d*)(\.(\d+))?$/);
|
let decimal = cells[4] || '';
|
||||||
// Process if illegal number
|
|
||||||
if (!cells) {
|
|
||||||
valueNode = val;
|
|
||||||
} else {
|
|
||||||
const negative = cells[1];
|
|
||||||
let int = cells[2] || '0';
|
|
||||||
let decimal = cells[4] || '';
|
|
||||||
|
|
||||||
int = int.replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);
|
int = int.replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);
|
||||||
if (typeof precision === 'number') {
|
if (typeof precision === 'number') {
|
||||||
decimal = padEnd(decimal, precision, '0').slice(0, precision);
|
decimal = padEnd(decimal, precision, '0').slice(0, precision);
|
||||||
}
|
|
||||||
|
|
||||||
if (decimal) {
|
|
||||||
decimal = `${decimalSeparator}${decimal}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
valueNode = [
|
|
||||||
<span key="int" class={`${prefixCls}-content-value-int`}>
|
|
||||||
{negative}
|
|
||||||
{int}
|
|
||||||
</span>,
|
|
||||||
decimal && (
|
|
||||||
<span key="decimal" class={`${prefixCls}-content-value-decimal`}>
|
|
||||||
{decimal}
|
|
||||||
</span>
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return <span class={`${prefixCls}-content-value`}>{valueNode}</span>;
|
if (decimal) {
|
||||||
},
|
decimal = `${decimalSeparator}${decimal}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
valueNode = [
|
||||||
|
<span key="int" class={`${prefixCls}-content-value-int`}>
|
||||||
|
{negative}
|
||||||
|
{int}
|
||||||
|
</span>,
|
||||||
|
decimal && (
|
||||||
|
<span key="decimal" class={`${prefixCls}-content-value-decimal`}>
|
||||||
|
{decimal}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return <span class={`${prefixCls}-content-value`}>{valueNode}</span>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const name = 'AStatisticNumber';
|
||||||
|
export { name };
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
import { inject } from 'vue';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import { getComponentFromProp, initDefaultProps } from '../_util/props-util';
|
import { getComponent, initDefaultProps } from '../_util/props-util';
|
||||||
import { ConfigConsumerProps } from '../config-provider';
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
import StatisticNumber from './Number';
|
import StatisticNumber from './Number';
|
||||||
|
|
||||||
|
@ -28,15 +29,21 @@ export default {
|
||||||
configProvider: { default: () => ConfigConsumerProps },
|
configProvider: { default: () => ConfigConsumerProps },
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
return {
|
||||||
|
configProvider: inject('configProvider', ConfigConsumerProps),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { prefixCls: customizePrefixCls, value = 0, valueStyle, valueRender } = this.$props;
|
const { prefixCls: customizePrefixCls, value = 0, valueStyle, valueRender } = this.$props;
|
||||||
const getPrefixCls = this.configProvider.getPrefixCls;
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
||||||
const prefixCls = getPrefixCls('statistic', customizePrefixCls);
|
const prefixCls = getPrefixCls('statistic', customizePrefixCls);
|
||||||
|
|
||||||
const title = getComponentFromProp(this, 'title');
|
const title = getComponent(this, 'title');
|
||||||
let prefix = getComponentFromProp(this, 'prefix');
|
let prefix = getComponent(this, 'prefix');
|
||||||
let suffix = getComponentFromProp(this, 'suffix');
|
let suffix = getComponent(this, 'suffix');
|
||||||
const formatter = getComponentFromProp(this, 'formatter', {}, false);
|
const formatter = getComponent(this, 'formatter', {}, false);
|
||||||
let valueNode = (
|
let valueNode = (
|
||||||
<StatisticNumber {...{ props: { ...this.$props, prefixCls, value, formatter } }} />
|
<StatisticNumber {...{ props: { ...this.$props, prefixCls, value, formatter } }} />
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import Statistic from './Statistic';
|
import Statistic from './Statistic';
|
||||||
import Countdown from './Countdown';
|
import Countdown from './Countdown';
|
||||||
import Base from '../base';
|
|
||||||
|
|
||||||
Statistic.Countdown = Countdown;
|
Statistic.Countdown = Countdown;
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
Statistic.install = function(Vue) {
|
Statistic.install = function(app) {
|
||||||
Vue.use(Base);
|
app.component(Statistic.name, Statistic);
|
||||||
Vue.component(Statistic.name, Statistic);
|
app.component(Statistic.Countdown.name, Statistic.Countdown);
|
||||||
Vue.component(Statistic.Countdown.name, Statistic.Countdown);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Statistic;
|
export default Statistic;
|
||||||
|
|
|
@ -18,6 +18,7 @@ import PageHeader from 'ant-design-vue/page-header';
|
||||||
import Skeleton from 'ant-design-vue/skeleton';
|
import Skeleton from 'ant-design-vue/skeleton';
|
||||||
import Empty from 'ant-design-vue/empty';
|
import Empty from 'ant-design-vue/empty';
|
||||||
import Timeline from 'ant-design-vue/timeline';
|
import Timeline from 'ant-design-vue/timeline';
|
||||||
|
import Statistic from 'ant-design-vue/statistic';
|
||||||
import Checkbox from 'ant-design-vue/checkbox';
|
import Checkbox from 'ant-design-vue/checkbox';
|
||||||
import Col from 'ant-design-vue/col';
|
import Col from 'ant-design-vue/col';
|
||||||
import Row from 'ant-design-vue/row';
|
import Row from 'ant-design-vue/row';
|
||||||
|
@ -34,6 +35,7 @@ import Menu from 'ant-design-vue/menu';
|
||||||
import Mentions from 'ant-design-vue/mentions';
|
import Mentions from 'ant-design-vue/mentions';
|
||||||
import Dropdown from 'ant-design-vue/dropdown';
|
import Dropdown from 'ant-design-vue/dropdown';
|
||||||
import Steps from 'ant-design-vue/steps';
|
import Steps from 'ant-design-vue/steps';
|
||||||
|
|
||||||
import 'ant-design-vue/style.js';
|
import 'ant-design-vue/style.js';
|
||||||
|
|
||||||
const basic = {
|
const basic = {
|
||||||
|
@ -68,6 +70,7 @@ app
|
||||||
.use(Empty)
|
.use(Empty)
|
||||||
.use(Checkbox)
|
.use(Checkbox)
|
||||||
.use(Timeline)
|
.use(Timeline)
|
||||||
|
.use(Statistic)
|
||||||
.use(Col)
|
.use(Col)
|
||||||
.use(Row)
|
.use(Row)
|
||||||
.use(Tooltip)
|
.use(Tooltip)
|
||||||
|
|
Loading…
Reference in New Issue