From aa15f061ba185b05f22c98a0a979c72d08bcd974 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 11 二月 2025 09:42:38 +0800
Subject: [PATCH] 2025-02-11

---
 src/components/header/loginform.jsx |  112 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 92 insertions(+), 20 deletions(-)

diff --git a/src/components/header/loginform.jsx b/src/components/header/loginform.jsx
index 680c392..cca3f3d 100644
--- a/src/components/header/loginform.jsx
+++ b/src/components/header/loginform.jsx
@@ -1,8 +1,8 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { Form, Icon, Input } from 'antd'
-import zhCN from '@/locales/zh-CN/login.js'
-import enUS from '@/locales/en-US/login.js'
+import { Form, Input, Checkbox } from 'antd'
+import { UserOutlined, LockOutlined } from '@ant-design/icons'
+
 import './index.scss'
 
 class HeaderLoginForm extends Component {
@@ -11,7 +11,38 @@
   }
 
   state = {
-    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS
+    remember: false,
+    lock: false,
+    username: '',
+    password: '',
+    delay: +sessionStorage.getItem('mkDelay')
+  }
+
+  UNSAFE_componentWillMount () {
+    let _user = localStorage.getItem(window.GLOB.sysSign + 'cloud')
+    
+    if (_user) {
+      try {
+        _user = JSON.parse(window.decodeURIComponent(window.atob(_user)))
+      } catch (e) {
+        console.warn('Parse Failure')
+        _user = ''
+      }
+    }
+
+    if (_user && new Date().getTime() - _user.time > 1000 * 7 * 24 * 60 * 60) {
+      _user = ''
+      localStorage.removeItem(window.GLOB.sysSign + 'cloud')
+    }
+
+    if (_user) {
+      this.setState({
+        remember: true,
+        username: _user.username,
+        password: _user.password,
+        lock: true
+      })
+    }
   }
 
   handleConfirm = () => {
@@ -19,6 +50,9 @@
     return new Promise((resolve, reject) => {
       this.props.form.validateFieldsAndScroll((err, values) => {
         if (!err) {
+          values.username = values.username.replace(/\t+|\v+|\s+/g, '')
+          values.password = values.password.replace(/\t+|\v+|\s+/g, '')
+
           resolve(values)
         } else {
           reject(err)
@@ -27,48 +61,86 @@
     })
   }
 
-  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()
+    }
+  }
+
+  rememberChange = (e) => {
+    let val = e.target.checked
+
+    if (!val) {
+      localStorage.removeItem(window.GLOB.sysSign + 'cloud')
+    }
+  }
+
+  unLock = (e) => {
+    if (e.target.value) return
+    
+    this.setState({ lock: false })
   }
 
   componentDidMount () {
-    const input = document.getElementById('username')
-    if (input) {
-      input.focus()
+    const { username, password } = this.state
+
+    if (username && !password) {
+      const input = document.getElementById('password')
+      input && input.focus()
+    } else {
+      const input = document.getElementById('username')
+      input && input.focus()
     }
   }
 
   render() {
     const { getFieldDecorator } = this.props.form
+    const { remember, username, password, delay, lock } = this.state
 
     return (
       <Form style={{margin: '0px 10px'}}>
-        <Form.Item>
+        {delay > 1000 ? <Form.Item style={{marginBottom: '0px', marginTop: '-10px'}}>
+          鍗囩骇鍒�<a target="_blank" rel="noopener noreferrer" href="https://cloud.mk9h.cn/admin/index.html">浼佷笟鐗�</a>锛岃幏寰楁洿楂樻晥鐨勫紑鍙戜綋楠屻��
+        </Form.Item> : null}
+        <Form.Item style={{marginBottom: '0px', height: '60px'}}>
           {getFieldDecorator('username', {
-            rules: [{ required: true, message: this.state.dict['login.username.empty'] }],
-            initialValue: '',
+            rules: [{ required: true, message: '璇疯緭鍏ョ敤鎴峰悕' }],
+            initialValue: username,
           })(
             <Input
-              prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />}
-              placeholder={this.state.dict['login.username']}
+              prefix={<UserOutlined style={{ color: 'rgba(0,0,0,.25)' }}/>}
+              placeholder="鐢ㄦ埛鍚�"
               autoComplete="off"
-              onPressEnter={this.handleSubmit}
+              onPressEnter={(e) => {this.handleSubmit(e, 'password')}}
             />
           )}
         </Form.Item>
-        <Form.Item>
+        <Form.Item style={{marginBottom: '0px', height: '55px'}}>
           {getFieldDecorator('password', {
-            initialValue: '',
+            initialValue: password,
             rules: [
               {
                 required: true,
-                message: this.state.dict['login.password.empty'],
+                message: '璇疯緭鍏ュ瘑鐮�',
               }
             ]
-          })(<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="瀵嗙爜" visibilityToggle={!lock} onChange={this.unLock} prefix={<LockOutlined style={{ color: 'rgba(0,0,0,.25)' }} />} />)}
         </Form.Item>
+        {window.GLOB.keepKey ? <Form.Item style={{marginBottom: '10px'}}>
+          {getFieldDecorator('remember', {
+            valuePropName: 'checked',
+            initialValue: remember,
+          })(
+          <Checkbox onChange={this.rememberChange}>璁颁綇瀵嗙爜</Checkbox>)}
+        </Form.Item> : <div style={{height: '20px'}}></div>}
       </Form>
     )
   }

--
Gitblit v1.8.0