From 53b9fb93d0376eb02bb996935f1720b4e95cd897 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 12 十月 2022 14:41:06 +0800 Subject: [PATCH] 2022-10-12 --- src/components/header/loginform.jsx | 87 ++++++++++++++++++++++++++++++++++++------- 1 files changed, 72 insertions(+), 15 deletions(-) diff --git a/src/components/header/loginform.jsx b/src/components/header/loginform.jsx index 680c392..899741a 100644 --- a/src/components/header/loginform.jsx +++ b/src/components/header/loginform.jsx @@ -1,6 +1,8 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import { Form, Icon, Input } from 'antd' +import { Form, Input, Checkbox } from 'antd' +import { UserOutlined, LockOutlined } from '@ant-design/icons' + import zhCN from '@/locales/zh-CN/login.js' import enUS from '@/locales/en-US/login.js' import './index.scss' @@ -11,7 +13,36 @@ } state = { - dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS + dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, + remember: false, + username: '', + password: '', + delay: +sessionStorage.getItem('mkDelay') + } + + UNSAFE_componentWillMount () { + let _url = window.location.href.split('#')[0] + 'cloud' + let _user = localStorage.getItem(_url) + + 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(_url) + } + + this.setState({ + remember: _user ? true : false, + username: _user ? _user.username : '', + password: _user ? _user.password : '' + }) } handleConfirm = () => { @@ -27,48 +58,74 @@ }) } - 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 + let _url = window.location.href.split('#')[0] + 'cloud' + + if (!val) { + localStorage.removeItem(_url) + } } componentDidMount () { const input = document.getElementById('username') - if (input) { - input.focus() - } + input && input.focus() } render() { const { getFieldDecorator } = this.props.form + const { remember, username, password, delay } = 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: '', + initialValue: username, })( <Input - prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} + prefix={<UserOutlined 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> - <Form.Item> + <Form.Item style={{marginBottom: '0px', height: '55px'}}> {getFieldDecorator('password', { - initialValue: '', + initialValue: password, rules: [ { required: true, 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={<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