chen.lin
1 天以前 79edfec1f6e6789d3f6cc57db3cb0cfdffd64c32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import React from 'react';
import { NumberInput } from 'react-admin';
import { maxDecimalPlaces } from '@/utils/common';
 
const MAX_DECIMALS = 6;
const QUANTITY_VALIDATE = [maxDecimalPlaces(MAX_DECIMALS, '最多6位小数')];
 
/**
 * 数量输入框:支持最多 6 位小数,超过时提示并阻止提交
 */
const QuantityInput = (props) => {
    const { validate = [], helperText, ...rest } = props;
    const mergedValidate = Array.isArray(validate) ? [...QUANTITY_VALIDATE, ...validate] : [...QUANTITY_VALIDATE, validate];
    return (
        <NumberInput
            validate={mergedValidate}
            helperText={helperText ?? '最多6位小数'}
            {...rest}
        />
    );
};
 
export default QuantityInput;