123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import padEnd from 'lodash/padEnd';
- export default {
- name: 'AStatisticNumber',
- functional: true,
- render: function render(h, context) {
- var _context$props = context.props,
- value = _context$props.value,
- formatter = _context$props.formatter,
- precision = _context$props.precision,
- decimalSeparator = _context$props.decimalSeparator,
- _context$props$groupS = _context$props.groupSeparator,
- groupSeparator = _context$props$groupS === undefined ? '' : _context$props$groupS,
- prefixCls = _context$props.prefixCls;
- var valueNode = void 0;
- if (typeof formatter === 'function') {
- // Customize formatter
- valueNode = formatter({ value: value, h: h });
- } else {
- // Internal formatter
- var val = String(value);
- var cells = val.match(/^(-?)(\d*)(\.(\d+))?$/);
- // Process if illegal number
- if (!cells) {
- valueNode = val;
- } else {
- var negative = cells[1];
- var int = cells[2] || '0';
- var decimal = cells[4] || '';
- int = int.replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);
- if (typeof precision === 'number') {
- decimal = padEnd(decimal, precision, '0').slice(0, precision);
- }
- if (decimal) {
- decimal = '' + decimalSeparator + decimal;
- }
- valueNode = [h(
- 'span',
- { key: 'int', 'class': prefixCls + '-content-value-int' },
- [negative, int]
- ), decimal && h(
- 'span',
- { key: 'decimal', 'class': prefixCls + '-content-value-decimal' },
- [decimal]
- )];
- }
- }
- return h(
- 'span',
- { 'class': prefixCls + '-content-value' },
- [valueNode]
- );
- }
- };
|