张延森 4 年之前
父節點
當前提交
a504a6c06d

+ 26
- 0
src/pages/user/login/components/Login/CaptchaImg.jsx 查看文件

@@ -0,0 +1,26 @@
1
+import React, { useEffect, useState } from 'react'
2
+import { fetch, apis } from '@/utils/request'
3
+
4
+const getCaptcha = fetch(apis.image.captcha)
5
+
6
+export default props => {
7
+  const [ver, setVer] = useState(0)
8
+  const [captcha, setCaptcha] = useState({image: '验证码'})
9
+
10
+  const handleClick = () => {
11
+    setVer(ver + 1)
12
+  }
13
+
14
+  useEffect(() => {
15
+    getCaptcha().then(res => {
16
+      setCaptcha(res)
17
+      if (props.onChange) {
18
+        props.onChange(res.key)
19
+      }
20
+    })
21
+  }, [ver])
22
+
23
+  return (
24
+    <img src={captcha.image} width="100%" height="40" onClick={handleClick} style={{cursor: 'pointer'}} />
25
+  )
26
+}

+ 5
- 2
src/pages/user/login/components/Login/LoginItem.jsx 查看文件

@@ -4,6 +4,8 @@ import omit from 'omit.js';
4 4
 import ItemMap from './map';
5 5
 import LoginContext from './LoginContext';
6 6
 import styles from './index.less';
7
+import CaptchaImg from './CaptchaImg'
8
+
7 9
 const FormItem = Form.Item;
8 10
 
9 11
 class WrapFormItem extends Component {
@@ -119,14 +121,15 @@ class WrapFormItem extends Component {
119 121
               {getFieldDecorator(name, options)(<Input {...customProps} {...inputProps} />)}
120 122
             </Col>
121 123
             <Col span={8}>
122
-              <Button
124
+              {/* <Button
123 125
                 disabled={!!count}
124 126
                 className={styles.getCaptcha}
125 127
                 size="large"
126 128
                 onClick={this.onGetCaptcha}
127 129
               >
128 130
                 {count ? `${count} ${getCaptchaSecondText}` : getCaptchaButtonText}
129
-              </Button>
131
+              </Button> */}
132
+              {getFieldDecorator('captchaKey')(<CaptchaImg />)}
130 133
             </Col>
131 134
           </Row>
132 135
         </FormItem>

+ 1
- 1
src/pages/user/login/components/Login/index.jsx 查看文件

@@ -88,7 +88,7 @@ class Login extends Component {
88 88
 
89 89
     if (form) {
90 90
       form.validateFields(
91
-        activeFields,
91
+        activeFields.concat('captchaKey'),
92 92
         {
93 93
           force: true,
94 94
         },

+ 13
- 0
src/pages/user/login/components/Login/map.jsx 查看文件

@@ -31,4 +31,17 @@ export default {
31 31
       },
32 32
     ],
33 33
   },
34
+  Captcha: {
35
+    props: {
36
+      size: 'large',
37
+      id: 'captcha',
38
+      placeholder: '888888',
39
+    },
40
+    rules: [
41
+      {
42
+        required: true,
43
+        message: '请输入验证码!',
44
+      },
45
+    ],
46
+  },
34 47
 };

+ 1
- 0
src/pages/user/login/index.jsx 查看文件

@@ -120,6 +120,7 @@ class Login extends Component {
120 120
               }
121 121
             }}
122 122
           />
123
+          <Captcha name="captcha" placeholder="请填写验证码" />
123 124
           <Submit loading={submitting}>
124 125
             <FormattedMessage id="user-login.login.login" />
125 126
           </Submit>

+ 5
- 0
src/services/apis.js 查看文件

@@ -75,6 +75,11 @@ export default {
75 75
       url: `${prefix}/qrcode`,
76 76
       method: 'POST',
77 77
       action: 'upload',
78
+    },
79
+    captcha: {
80
+      url: `${prefix}/image-captcha`,
81
+      method: 'GET',
82
+      action: 'upload',
78 83
     }
79 84
   },
80 85
   user: {