From a02fc6a77fa1b35c6516b2d37108d80e260c6c85 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 07 十一月 2024 22:05:08 +0800 Subject: [PATCH] 2024-11-07 --- src/components/header/loginform.jsx | 65 +++++++++++++++++++++----------- 1 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/components/header/loginform.jsx b/src/components/header/loginform.jsx index be94096..cca3f3d 100644 --- a/src/components/header/loginform.jsx +++ b/src/components/header/loginform.jsx @@ -3,8 +3,6 @@ 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' class HeaderLoginForm extends Component { @@ -13,15 +11,15 @@ } state = { - dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, remember: false, + lock: false, username: '', - password: '' + password: '', + delay: +sessionStorage.getItem('mkDelay') } UNSAFE_componentWillMount () { - let _url = window.location.href.split('#')[0] + 'cloud' - let _user = localStorage.getItem(_url) + let _user = localStorage.getItem(window.GLOB.sysSign + 'cloud') if (_user) { try { @@ -34,14 +32,17 @@ if (_user && new Date().getTime() - _user.time > 1000 * 7 * 24 * 60 * 60) { _user = '' - localStorage.removeItem(_url) + localStorage.removeItem(window.GLOB.sysSign + 'cloud') } - this.setState({ - remember: _user ? true : false, - username: _user ? _user.username : '', - password: _user ? _user.password : '' - }) + if (_user) { + this.setState({ + remember: true, + username: _user.username, + password: _user.password, + lock: true + }) + } } handleConfirm = () => { @@ -49,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) @@ -73,32 +77,47 @@ rememberChange = (e) => { let val = e.target.checked - let _url = window.location.href.split('#')[0] + 'cloud' if (!val) { - localStorage.removeItem(_url) + localStorage.removeItem(window.GLOB.sysSign + 'cloud') } } + unLock = (e) => { + if (e.target.value) return + + this.setState({ lock: false }) + } + componentDidMount () { - const input = document.getElementById('username') - 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 } = this.state + const { remember, username, password, delay, lock } = this.state return ( <Form style={{margin: '0px 10px'}}> + {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'] }], + rules: [{ required: true, message: '璇疯緭鍏ョ敤鎴峰悕' }], initialValue: username, })( <Input prefix={<UserOutlined style={{ color: 'rgba(0,0,0,.25)' }}/>} - placeholder={this.state.dict['login.username']} + placeholder="鐢ㄦ埛鍚�" autoComplete="off" onPressEnter={(e) => {this.handleSubmit(e, 'password')}} /> @@ -110,18 +129,18 @@ rules: [ { required: true, - message: this.state.dict['login.password.empty'], + message: '璇疯緭鍏ュ瘑鐮�', } ] - })(<Input.Password onPressEnter={(e) => {this.handleSubmit(e, 'username')}} placeholder={this.state.dict['login.password']} prefix={<LockOutlined 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> - <Form.Item style={{marginBottom: '10px'}}> + {window.GLOB.keepKey ? <Form.Item style={{marginBottom: '10px'}}> {getFieldDecorator('remember', { valuePropName: 'checked', initialValue: remember, })( <Checkbox onChange={this.rememberChange}>璁颁綇瀵嗙爜</Checkbox>)} - </Form.Item> + </Form.Item> : <div style={{height: '20px'}}></div>} </Form> ) } -- Gitblit v1.8.0