|
@@ -0,0 +1,65 @@
|
|
1
|
+import React from 'react';
|
|
2
|
+import classNames from 'classnames';
|
|
3
|
+import { SyncOutlined, CheckCircleTwoTone, CloseCircleTwoTone } from '@ant-design/icons';
|
|
4
|
+import { Input } from 'antd';
|
|
5
|
+import { checkCaptch } from '@/services/login';
|
|
6
|
+import CaptchaImage from './CaptchaImage';
|
|
7
|
+
|
|
8
|
+export default (props) => {
|
|
9
|
+ const { style, className, onChange, onBlur, ...leftProps } = props;
|
|
10
|
+
|
|
11
|
+ const [captcha, setCaptcha] = React.useState();
|
|
12
|
+ const [value, setValue] = React.useState();
|
|
13
|
+ const [isOk, setIsOk] = React.useState(-1);
|
|
14
|
+
|
|
15
|
+ const handleChange = (e) => {
|
|
16
|
+ setValue(e.target.value);
|
|
17
|
+ };
|
|
18
|
+
|
|
19
|
+ const handleBlur = (e) => {
|
|
20
|
+ if (onBlur) {
|
|
21
|
+ onBlur(e);
|
|
22
|
+ }
|
|
23
|
+
|
|
24
|
+ checkCaptch({ id: captcha?.id, value }).then((res) => {
|
|
25
|
+ setIsOk(res);
|
|
26
|
+ });
|
|
27
|
+ };
|
|
28
|
+
|
|
29
|
+ const onCaptchaChange = (e) => {
|
|
30
|
+ setIsOk(-1);
|
|
31
|
+ setValue();
|
|
32
|
+ setCaptcha(e);
|
|
33
|
+ };
|
|
34
|
+
|
|
35
|
+ React.useEffect(() => {
|
|
36
|
+ if (onChange) {
|
|
37
|
+ onChange({
|
|
38
|
+ id: captcha?.id,
|
|
39
|
+ value,
|
|
40
|
+ });
|
|
41
|
+ }
|
|
42
|
+ }, [value, captcha]);
|
|
43
|
+
|
|
44
|
+ return (
|
|
45
|
+ <div className={classNames(className, 'flex', 'v-center')} style={style}>
|
|
46
|
+ <div className="flex-1">
|
|
47
|
+ <Input
|
|
48
|
+ allowClear
|
|
49
|
+ {...leftProps}
|
|
50
|
+ value={value}
|
|
51
|
+ onChange={handleChange}
|
|
52
|
+ onBlur={handleBlur}
|
|
53
|
+ />
|
|
54
|
+ </div>
|
|
55
|
+ <div className="flex-0" style={{ width: '130px', marginLeft: '8px' }}>
|
|
56
|
+ <CaptchaImage onChange={onCaptchaChange} />
|
|
57
|
+ </div>
|
|
58
|
+ <div className="flex-0" style={{ width: '24px', marginLeft: '8px' }}>
|
|
59
|
+ {isOk === -1 && <SyncOutlined style={{ fontSize: '16px', color: '#096dd9' }} />}
|
|
60
|
+ {isOk === 1 && <CheckCircleTwoTone twoToneColor="#00ff00" style={{ fontSize: '18px' }} />}
|
|
61
|
+ {isOk === 0 && <CloseCircleTwoTone twoToneColor="#ff0000" style={{ fontSize: '18px' }} />}
|
|
62
|
+ </div>
|
|
63
|
+ </div>
|
|
64
|
+ );
|
|
65
|
+};
|