From 5cfe6db94c1449810a44660b299dba8e7e98e5c5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 10 六月 2021 14:43:39 +0800
Subject: [PATCH] 2021-06-10

---
 src/components/header/loginform.jsx |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/components/header/loginform.jsx b/src/components/header/loginform.jsx
index 680c392..3ed68e7 100644
--- a/src/components/header/loginform.jsx
+++ b/src/components/header/loginform.jsx
@@ -11,7 +11,7 @@
   }
 
   state = {
-    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS
+    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS
   }
 
   handleConfirm = () => {
@@ -27,17 +27,23 @@
     })
   }
 
-  handleSubmit = e => {
-    // 鐧诲綍鍙傛暟妫�楠�
+  handleSubmit = (e, key) => {
     e.preventDefault()
-    this.props.handleSubmit()
+    if (e.target.value) {
+      if (!this.props.form.getFieldValue(key)) {
+        const input = document.getElementById(key)
+        input && input.focus()
+        return
+      }
+      this.props.handleSubmit()
+    } else {
+      this.handleConfirm()
+    }
   }
 
   componentDidMount () {
     const input = document.getElementById('username')
-    if (input) {
-      input.focus()
-    }
+    input && input.focus()
   }
 
   render() {
@@ -54,7 +60,7 @@
               prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />}
               placeholder={this.state.dict['login.username']}
               autoComplete="off"
-              onPressEnter={this.handleSubmit}
+              onPressEnter={(e) => {this.handleSubmit(e, 'password')}}
             />
           )}
         </Form.Item>
@@ -67,7 +73,7 @@
                 message: this.state.dict['login.password.empty'],
               }
             ]
-          })(<Input.Password onPressEnter={this.handleSubmit} placeholder={this.state.dict['login.password']} prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} />)}
+          })(<Input.Password onPressEnter={(e) => {this.handleSubmit(e, 'username')}} placeholder={this.state.dict['login.password']} prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} />)}
         </Form.Item>
       </Form>
     )

--
Gitblit v1.8.0