From f22bb55c4ff50a8a63c795487b057c0cebdae649 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 12 十二月 2019 09:19:58 +0800 Subject: [PATCH] 2019-12-12 --- src/views/login/loginform.jsx | 38 ++++++++++++++++++++++++++++++++------ 1 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/views/login/loginform.jsx b/src/views/login/loginform.jsx index 968b863..617b1c2 100644 --- a/src/views/login/loginform.jsx +++ b/src/views/login/loginform.jsx @@ -16,7 +16,10 @@ platName: PropTypes.string } - state = {} + state = { + username: '', + password: '' + } handleConfirm = () => { // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭� @@ -52,9 +55,32 @@ } componentDidMount () { - const input = document.getElementById('username') - if (input) { - input.focus() + let _url = window.location.href.split('#')[0] + let _user = localStorage.getItem(_url) + + if (_user) { + try { + _user = JSON.parse(window.decodeURIComponent(window.atob(_user))) + } catch { + _user = '' + } + } + + if (_user) { + this.setState({ + username: _user.username, + password: _user.password + }, () => { + const input = document.getElementById('username') + if (input) { + input.focus() + } + }) + } else { + const input = document.getElementById('username') + if (input) { + input.focus() + } } } @@ -67,7 +93,7 @@ <Form.Item> {getFieldDecorator('username', { rules: [{ required: true, message: this.props.dict['login.username.empty'] }], - initialValue: localStorage.getItem('username') || '', + initialValue: this.state.username || '', })( <Input prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} @@ -77,7 +103,7 @@ </Form.Item> <Form.Item> {getFieldDecorator('password', { - initialValue: localStorage.getItem('password') || '', + initialValue: this.state.password || '', rules: [ { required: true, -- Gitblit v1.8.0