Commit 17482b6c by zhanghaozhe

账号登录

parent 48f9746a
import React, { PureComponent } from "react" import React, { PureComponent } from "react"
import './accountLogin.scss' import './accountLogin.scss'
import { Link } from "react-router-dom"; import { Link } from "react-router-dom"
import { withFormik, FastField, Form } from "formik"; import { withFormik, FastField, Form } from "formik"
import { compose } from 'redux'; import { compose } from 'redux'
import { accountLogin } from '@/store/userAction'; import { accountLogin } from '@/store/userAction'
import { connect } from "react-redux"; import { connect } from "react-redux"
import { isEmpty } from 'lodash' import { isEmpty } from 'lodash'
import { HeaderBar } from "@/common"; import { HeaderBar } from "@/common"
import Header from "../common/Header"; import Header from "../common/Header"
import Input from '../common/Input' import Input from '../common/Input'
import LoginButton from '../common/LoginButton' import LoginButton from '../common/LoginButton'
import PasswordInput from '../common/passwordInput' import PasswordInput from '../common/passwordInput'
import { Toast } from "antd-mobile"; import { Toast } from "antd-mobile"
class AccountLogin extends PureComponent { class AccountLogin extends PureComponent {
render() { render() {
const { const {
errors, errors,
values values
} = this.props } = this.props
return ( return (
<div className={'account-login'}> <div className={'account-login'}>
<HeaderBar arrow={true} title={'登录'}/> <HeaderBar arrow={true} title={'登录'}/>
<Header/> <Header/>
<Form className="login-info"> <Form className="login-info">
<FastField <FastField
name='account' name='account'
render={({field}) => ( render={({field}) => (
<Input <Input
{...field} {...field}
type={'text'} type={'text'}
placeholder={'手机/邮箱/昵称'} placeholder={'手机/邮箱/昵称'}
wrapperClass={'tel-input'} wrapperClass={'tel-input'}
icon={ icon={
<i className={'iconfont iconshouji'} <i className={'iconfont iconshouji'}
style={{fontSize: '22px', left: '10px'}} style={{fontSize: '22px', left: '10px'}}
/> />
} }
/> />
)} )}
/> />
<FastField <FastField
name='password' name='password'
render={({field}) => ( render={({field}) => (
<PasswordInput <PasswordInput
{...field} {...field}
autoComplete={'on'} autoComplete={'on'}
placeholder={'密码'} placeholder={'密码'}
icon={ icon={
<i className={'iconfont iconiconfront-74 lock-icon'}/> <i className={'iconfont iconiconfront-74 lock-icon'}/>
} }
/> />
)} )}
/> />
<LoginButton active={values.account && values.password && isEmpty(errors)}/> <LoginButton active={values.account && values.password && isEmpty(errors)}/>
<Link className={'forgot-password-btn'} to='/passport/forgot-password'>忘记密码</Link> <Link className={'forgot-password-btn'} to='/passport/forgot-password'>忘记密码</Link>
</Form> </Form>
</div> </div>
); )
} }
} }
const formikConfig = { const formikConfig = {
mapPropsToValues: () => ({ mapPropsToValues: () => ({
account: '', account: '',
password: '' password: ''
}), }),
handleSubmit(values, formikBag) { handleSubmit(values, formikBag) {
const {account: username, password} = values const {account: username, password} = values
const {props, props: {history}} = formikBag const {props, props: {history}} = formikBag
const from = props.location.state && props.location.state.from const from = props.location.state && props.location.state.from
props.accountLogin({ props.accountLogin({
username, password,redirect: from && window.location.origin + from.pathname + from.search + from.hash username, password, redirect: from && window.location.origin + from.pathname + from.search + from.hash
}).then(res => { }).then(res => {
if (res.hasError) { if (res.hasError) {
Toast.info(res.msg, 2, null, false) Toast.info(res.msg, 2, null, false)
} }
}) })
},
validate: values => {
const errors = {}
if (!values.account) {
errors.account = '账号不能为空'
} else if (!values.password) {
errors.password = '密码不能为空'
} }
return errors
}
} }
export default compose( export default compose(
connect( connect(
state => ({user: state.user}), state => ({user: state.user}),
{accountLogin} {accountLogin}
), ),
withFormik(formikConfig) withFormik(formikConfig)
)(AccountLogin) )(AccountLogin)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment