返回 AiToEarn
GetCode.tsx
1 import styles from '@/views/login/login.module.scss';
2 import { useRef, useState } from 'react';
3 import { Statistic } from 'antd';
4 const { Countdown } = Statistic;
5
6 /**
7 * 播放视频
8 * 验证码倒计时触发组件
9 * @param onGetCode
10 */
11 function GetCode({ onGetCode }: { onGetCode: (unlock: () => void) => void }) {
12 const [isCode, setIsCode] = useState(false);
13 const currTime = useRef(0);
14
15 const lockCode = () => {
16 setIsCode(true);
17 currTime.current = 60 * 1000;
18 };
19
20 return (
21 <label
22 className={
23 styles['loginForm-getCode'] +
24 ` ${isCode ? styles['loginForm-getCode--disable'] : ''}`
25 }
26 style={{
27 display: 'flex',
28 justifyContent: 'center',
29 alignItems: 'center',
30 }}
31 onClick={() => {
32 if (isCode) return;
33 lockCode();
34 onGetCode(() => {
35 setIsCode(false);
36 });
37 }}
38 >
39 获取验证码
40 {isCode ? (
41 <>
42
43 <Countdown
44 style={{ fontSize: '12px' }}
45 format="ss"
46 value={Date.now() + currTime.current}
47 precision={1}
48 onFinish={() => {
49 setIsCode(false);
50 }}
51 onChange={(e) => {
52 if (typeof e === 'number') {
53 currTime.current = e;
54 }
55 }}
56 />
57 s)
58 </>
59 ) : (
60 ''
61 )}
62 </label>
63 );
64 }
65
66 export default GetCode;
67
67 lines Plain Text