From d59f518f466274b2caeb2e01c10c92deafe7c93b Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 09 二月 2022 11:48:29 +0800 Subject: [PATCH] 2022-02-09 --- src/components/header/resetpwd/index.jsx | 75 ++++++++++++++++++++++++++++--------- 1 files changed, 56 insertions(+), 19 deletions(-) diff --git a/src/components/header/resetpwd/index.jsx b/src/components/header/resetpwd/index.jsx index c9b8567..5db93ce 100644 --- a/src/components/header/resetpwd/index.jsx +++ b/src/components/header/resetpwd/index.jsx @@ -1,21 +1,39 @@ import React, {Component} from 'react' -import PropTypes from 'prop-types' import { Form, Input } from 'antd' class Resetpwd extends Component { - static propTpyes = { - dict: PropTypes.object - } - state = { confirmDirty: false, - autoCompleteResult: [] + autoCompleteResult: [], + level: localStorage.getItem(window.location.href.split('#')[0] + 'pwdlevel') || '' } onEnterSubmit = (e) => { // 琛ㄥ崟鍥炶溅鎻愪氦 if (e.key !== 'Enter') return - this.props.resetPwdSubmit() + + if (!this.props.form.getFieldValue('originpwd')) { + this.focusInput('originpwd') + } else if (!this.props.form.getFieldValue('password')) { + this.focusInput('password') + } else if (!this.props.form.getFieldValue('confirm')) { + this.focusInput('confirm') + } else { + this.props.resetPwdSubmit() + } + } + + focusInput = (selectId) => { + let _form = document.getElementById('reset-password-form') + let _inputs = _form.getElementsByTagName('input') + _inputs = [..._inputs] + _inputs.forEach(input => { + if (!input || input.id !== selectId) return + + if (input.focus) { + input.focus() + } + }) } handleConfirm = () => { @@ -39,7 +57,7 @@ compareToFirstPassword = (rule, value, callback) => { const { form } = this.props if (value && value !== form.getFieldValue('password')) { - callback(this.props.dict['header.password.diff']) + callback('涓ゆ杈撳叆瀵嗙爜涓嶄竴鑷达紒') } else { callback() } @@ -47,14 +65,24 @@ validateToNextPassword = (rule, value, callback) => { const { form } = this.props + const { level } = this.state + if (value && this.state.confirmDirty) { form.validateFields(['confirm'], { force: true }) } - callback() + + if (level === 'letter_num' && value && /^[0-9a-zA-Z!@#$%^&*()_]*$/.test(value) && /^([^0-9]*|[^a-zA-Z]*)$/.test(value)) { + callback('瀵嗙爜涓繀椤诲惈鏈夋暟瀛楀拰瀛楁瘝銆�') + } else if ((level === 'char_num' || level === 'char_num_90') && value && /^[0-9a-zA-Z!@#$%^&*()_]*$/.test(value) && /^([^0-9]*|[^a-zA-Z]*|[^!@#$%^&*()_]*)$/.test(value)) { + callback('瀵嗙爜涓繀椤诲惈鏈夋暟瀛椼�佸瓧姣嶅拰鐗规畩瀛楃銆�') + } else { + callback() + } } render() { const { getFieldDecorator } = this.props.form + const { level } = this.state const formItemLayout = { labelCol: { @@ -63,36 +91,45 @@ }, wrapperCol: { xs: { span: 24 }, - sm: { span: 16 } + sm: { span: 14 } } } + let rules = [] + if (level) { + rules.push({ + min: 8, + message: '瀵嗙爜闀垮害涓嶅彲灏忎簬8浣嶏紒' + }) + } + return ( - <Form {...formItemLayout} onKeyDown={this.onEnterSubmit}> - <Form.Item label={this.props.dict['header.password.origin']}> + <Form {...formItemLayout} onKeyDown={this.onEnterSubmit} id="reset-password-form"> + <Form.Item label="鍘熷瘑鐮�"> {getFieldDecorator('originpwd', { rules: [ { required: true, - message: this.props.dict['header.password.origin.required'] + message: '璇疯緭鍏ュ師瀵嗙爜锛�' } ] - })(<Input.Password />)} + })(<Input.Password autoFocus/>)} </Form.Item> - <Form.Item label={this.props.dict['header.password.new']} hasFeedback> + <Form.Item label="鏂板瘑鐮�" hasFeedback> {getFieldDecorator('password', { rules: [ { required: true, - message: this.props.dict['header.password.new.required'] + message: '璇疯緭鍏ユ柊瀵嗙爜锛�' }, { pattern: /^[0-9a-zA-Z!@#$%^&*()_]*$/ig, message: '瀵嗙爜鍙厑璁稿寘鍚暟瀛椼�佸瓧姣嶄互鍙�!@#$%&*()_銆�' }, + ...rules, { max: 50, - message: this.props.dict['header.password.maxlen'] + message: '鏈�澶у瘑鐮侀暱搴︿负50浣嶏紒' }, { validator: this.validateToNextPassword @@ -100,12 +137,12 @@ ] })(<Input.Password />)} </Form.Item> - <Form.Item label={this.props.dict['header.password.confirm']} hasFeedback> + <Form.Item label="纭瀵嗙爜" hasFeedback> {getFieldDecorator('confirm', { rules: [ { required: true, - message: this.props.dict['header.password.confirm.required'] + message: '璇风‘璁ゅ瘑鐮侊紒' }, { validator: this.compareToFirstPassword -- Gitblit v1.8.0