import { useControllableValue } from 'ahooks'; import { Col, Input, Row } from 'antd'; import Link from 'antd/lib/typography/Link'; import _ from 'lodash'; import { useCallback, useState } from 'react'; import { useIntl } from 'umi'; export interface RegularInputProps { value?: string; onChange?: (val: string) => void; disabled?: boolean; request: (val: { text: string; regular: string }) => Promise<{ match_info: string[]; }>; } const RegularInput = (props: RegularInputProps) => { const { request, disabled } = props; const [value, onChange] = useControllableValue(props); const { formatMessage } = useIntl(); const [checkText, setCheckText] = useState(''); const [resText, setResText] = useState(''); const [loading, setLoading] = useState(false); const checkHandler = useCallback(async () => { try { setLoading(true); const { match_info } = await request?.({ regular: value?.trim(), text: checkText?.trim(), }); setResText(match_info?.join('\n') ?? ''); } catch (e) { console.error('regularInput check err', e); } finally { setLoading(false); } }, [checkText, request, value]); return ( <> { onChange(e.target.value); setResText(''); }} allowClear addonAfter={ {formatMessage({ id: '校验' })} } placeholder={formatMessage({ id: '正则表达式' })} /> { setCheckText(e.target.value); setResText(''); }} rows={4} allowClear placeholder={formatMessage({ id: '校验文本' })} /> ); }; export default RegularInput;