发送验证码,间隔 60s
发送验证码
import React, { useState } from 'react'import { Input, Button } from 'antd'interface IVerifyCodeProps {value?: stringonChange?: (value: string) => voidreadyPost?: booleanphone?: numberstyle?: React.CSSProperties}export const VerifyCode: React.FC<React.PropsWithChildren<IVerifyCodeProps>> =({ value, onChange, readyPost, phone, ...props }) => {const [lastTime, setLastTime] = useState(0)const counting = (time = 60) => {if (time < 0) returnsetLastTime(time)setTimeout(() => {counting(time - 1)}, 1000)}return (<divstyle={{ display: 'inline-flex', width: '100%', alignItems: 'center' }}><Input{...props}style={{ marginRight: 5, ...props.style }}value={value}onChange={onChange}/><divstyle={{flexShrink: 0,color: '#999',width: 100,height: 35,display: 'flex',alignItems: 'center',justifyContent: 'center',}}>{lastTime === 0 && (<Buttondisabled={!readyPost}blockonClick={counting}>发送验证码</Button>)}{lastTime > 0 && <span>剩余{lastTime}秒</span>}</div></div>)}
手机号验证
<Itemlabel='手机号'name='phone'rules={[{ required: true, message: '请输入手机号!' },{ pattern: /^1[3-9]\d{9}$/, message: '手机号格式错误' },]}><InputinputMode='numeric'placeholder='请输入手机号'/></Item>
