1、NumericInput.tsx
import React from 'react'
import { Input } from 'antd'
interface ParamsType {value?: string // 值都是string类型,判断大小时要注意先转为数字再进行判断onChange: (value: string) => voidonBlur?: (value: string) => voidplaceholder?: string // 默认值:请输入数字maxLength?: number // 默认值:5type?: string // 类型,默认值:number
}
const NumericInput: React.FC<ParamsType> = (props: any) => {const { value, onChange, onBlur, type = 'number', ...restProps } = propslet reg: RegExpswitch (type) {case 'naturalNumber': // 自然数:0 1 2 3 ...reg = /^\d+?$/breakcase 'nonnegative': // 非负数(零、正数、小数):0 0.1 1 1.5 2 ...reg = /^\d*(\.\d*)?$/breakcase 'money': // 大于0的数字,小