Commit 8c92b384 by zhanghaozhe

formik

parent 18cc7edd
import React, { Component } from 'react'; import React, { Component } from 'react';
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { LocaleProvider } from 'antd-mobile' import { LocaleProvider } from 'antd-mobile'
import { HashRouter } from 'react-router-dom' import { BrowserRouter as Router } from 'react-router-dom'
import Routes from './router' import Routes from './router'
class App extends Component { class App extends Component {
render() { render() {
return ( return (
<LocaleProvider> <LocaleProvider>
<HashRouter> <Router>
<Routes></Routes> <Routes></Routes>
</HashRouter> </Router>
</LocaleProvider> </LocaleProvider>
); );
} }
......
import React, { Component } from 'react';
export default function (WrappedComponent) {
return class extends Component {
componentDidMount() {
const height = window.innerHeight
document.body.style.height = `${height}px`
document.getElementById('root').style.height = `${height}px`
}
componentWillUnmount() {
document.body.style.height = `auto`
document.getElementById('root').style.height = `auto`
}
render() {
return (
<WrappedComponent {...this.props}/>
);
}
}
}
export {default as WithTab} from './WithTab' export {default as WithTab} from './WithTab'
\ No newline at end of file export {default as WithFullSize} from './WithFullSize'
\ No newline at end of file
...@@ -3,12 +3,12 @@ import './header.scss' ...@@ -3,12 +3,12 @@ import './header.scss'
import logo from './logo.png' import logo from './logo.png'
const Header = () => { const Header = React.memo(() => {
return ( return (
<div className="header"> <div className="header">
<img src={logo} alt=""/> <img src={logo} alt=""/>
</div> </div>
); );
}; });
export default Header; export default Header;
\ No newline at end of file
import React, { Component } from 'react'; import React from 'react';
import './input.scss' import './input.scss'
import classnames from "classnames"; import classnames from "classnames";
function Input({
class Index extends Component { icon,
constructor(props) { wrapperClass,
super(props) children,
this.state = { ...rest
value: '' }) {
} return (
} <div className={classnames('input-wrapper', wrapperClass)}>
<input
handleChange = (e) => { className='input'
let val = e.target.value {...rest}
let {onChange} = this.props />
this.setState({value: val}) {icon}
onChange && onChange(val) {children}
} </div>
)
render() {
let {type, icon, placeholder, wrapperClass, children} = this.props
return (
<div className={classnames('input-wrapper', wrapperClass)}>
<input
type={type}
className='input'
placeholder={placeholder}
value={this.state.value}
onChange={this.handleChange}
/>
{/*<i className={classnames('iconfont', iconClass)}/>*/}
{icon}
{children}
</div>
)
}
} }
export default Index;
\ No newline at end of file export default Input;
\ No newline at end of file
...@@ -2,12 +2,12 @@ import React from 'react' ...@@ -2,12 +2,12 @@ import React from 'react'
import './loginButton.scss' import './loginButton.scss'
const LoginButton = ({onClick}) => { const LoginButton = React.memo(({onClick}) => {
return ( return (
<button onClick={onClick} className={'login-button'}> <button type={'submit'} onClick={onClick} className={'login-button'}>
登录 登录
</button> </button>
); );
}; });
export default LoginButton; export default LoginButton;
\ No newline at end of file
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import './loginWays.scss' import './loginWays.scss'
class LoginWays extends Component { class LoginWays extends PureComponent {
handleClick = (index) => { handleClick = (index) => {
this.props.onClick(index) this.props.onClick(index)
} }
......
...@@ -6,25 +6,21 @@ import classnames from 'classnames' ...@@ -6,25 +6,21 @@ import classnames from 'classnames'
import Input from '../Input' import Input from '../Input'
class VeriCodeInput extends Component { class VeriCodeInput extends Component {
constructor(props) { count = 10
super(props); state = {
this.state = { counting: false,
veriCode: '', count: this.count
counting: false,
count: 20
}
this.timer = null
} }
timer = null
countDown = () => { countDown = () => {
let {count} = this.state let {count} = this.state
if (!this.state.counting) { if (!this.state.counting) {
this.sendCode() this.sendCode()
this.setState({count: count--}) this.setState({count: count--, counting: true})
this.setState({counting: true})
this.timer = setInterval(() => { this.timer = setInterval(() => {
if (count <= 0) { if (count <= 0) {
this.setState({counting: false}) this.setState({counting: false, count: this.count})
clearInterval(this.timer) clearInterval(this.timer)
return return
} }
...@@ -37,23 +33,16 @@ class VeriCodeInput extends Component { ...@@ -37,23 +33,16 @@ class VeriCodeInput extends Component {
} }
handleChange = (val) => {
let {onChange} = this.props
this.setState({veriCode: val})
onChange && onChange(val)
}
render() { render() {
let {onChange, type = 'number', placeholder = '', className, ...rest} = this.props let {type = 'number', className, ...rest} = this.props
return ( return (
<Input <Input
type={type} type={type}
placeholder={placeholder}
onChange={this.handleChange}
wrapperClass={className} wrapperClass={className}
{...rest} {...rest}
> >
<button className={classnames('verify', {active: !this.state.counting})} onClick={this.countDown}> <button type='button' className={classnames('verify', {active: !this.state.counting})}
onClick={this.countDown}>
{ {
this.state.counting ? this.state.counting ?
(`重新发送${this.state.count}s`) (`重新发送${this.state.count}s`)
......
import React, {Component} from 'react' import React, { Component } from 'react'
import {Route, Switch} from 'react-router-dom' import { Route, Switch } from 'react-router-dom'
import './passport.scss' import './passport.scss'
import {WithFullSize} from '@/HOCs'
import WechatLogin from './wechatLogin' import WechatLogin from './wechatLogin'
import AccountLogin from './accountLogin' import AccountLogin from './accountLogin'
import ForgotPassword from './forgotPassword' import ForgotPassword from './forgotPassword'
...@@ -16,6 +16,7 @@ import wechat from './wechat.png' ...@@ -16,6 +16,7 @@ import wechat from './wechat.png'
class Passport extends Component { class Passport extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
...@@ -40,10 +41,6 @@ class Passport extends Component { ...@@ -40,10 +41,6 @@ class Passport extends Component {
} }
} }
componentDidMount() {
document.getElementsByClassName('tabbar')[0].style.display = 'none'
}
render() { render() {
let {match} = this.props let {match} = this.props
return ( return (
...@@ -62,4 +59,4 @@ class Passport extends Component { ...@@ -62,4 +59,4 @@ class Passport extends Component {
} }
export default Passport export default WithFullSize(Passport)
\ No newline at end of file \ No newline at end of file
.passport { .passport {
height: 100%; height: 100%;
display: flex;
} }
\ No newline at end of file
export const login = (userInfo) => ({
type: 'LOGIN',
userInfo
})
export const requestLogin = payload => dispatch => {
}
\ No newline at end of file
const initialState = {
userName: '',
avatar: '',
uid: '',
isVIP: false
}
const userInfo = (state = initialState, action) => {
switch (action.type) {
case 'LOGIN':
return {
...state,
...action.userInfo
}
default:
return state
}
}
export default userInfo
\ No newline at end of file
import React, { Component } from 'react' import React, { PureComponent } from 'react'
import './wechatLogin.scss' import './wechatLogin.scss'
import Input from "../common/Input"; import Input from "../common/Input"
import LoginButton from '../common/LoginButton'; import LoginButton from '../common/LoginButton'
import LoginWays from '../common/LoginWays' import LoginWays from '../common/LoginWays'
import Header from '../common/Header' import Header from '../common/Header'
import VeriCodeInput from '../common/veriCodeInput' import VeriCodeInput from '../common/veriCodeInput'
import { Form, FastField, withFormik } from "formik"
class WechatLogin extends Component {
constructor(props) {
super(props)
this.state = {
veriCode: ''
}
}
selectLoginWays = (i) => { class WechatLogin extends PureComponent {
console.log(i)
}
handleChange = (val) => {
this.setState({veriCode: val})
}
render() { render() {
const {loginWays} = this.props const {
loginWays,
} = this.props
return ( return (
<div className='login'> <div className='login'>
<Header/> <Header/>
<Form className="login-info">
<div className="login-info"> <FastField
<Input name='tel'
inputType={'number'} /*render={({field}) => (
placeholder={'手机号快捷登录(免注册)'} <Input
wrapperClass={'tel-input'} {...field}
icon={<i className={'iconfont iconshouji'} type={'tel'}
style={{fontSize: '22px', left: '10px'}} placeholder={'手机号快捷登录(免注册)'}
/>} wrapperClass={'tel-input'}
/> icon={<i className={'iconfont iconshouji'}
<VeriCodeInput style={{fontSize: '22px', left: '10px'}}
className={'verification'} />}
onChange={this.handleChange} />
icon={<i className={'iconfont iconduanxin'} )}*/
style={{fontSize: '20px', left: '12px'}} >
/>} {
({field}) => (
<Input
{...field}
type={'tel'}
placeholder={'手机号快捷登录(免注册)'}
wrapperClass={'tel-input'}
icon={<i className={'iconfont iconshouji'}
style={{fontSize: '22px', left: '10px'}}
/>}
/>
)
}
</FastField>
<FastField
type='number'
name='veriCode'
render={({field}) => (
<VeriCodeInput
{...field}
className={'verification'}
icon={<i className={'iconfont iconduanxin'}
style={{fontSize: '20px', left: '12px'}}
/>}
placeholder={'请输入验证码'}
/>
)}
/> />
<LoginButton/> <LoginButton/>
</div> </Form>
<LoginWays onClick={this.selectLoginWays} loginWays={loginWays}/> <LoginWays onClick={this.selectLoginWays} loginWays={loginWays}/>
</div> </div>
...@@ -53,5 +69,22 @@ class WechatLogin extends Component { ...@@ -53,5 +69,22 @@ class WechatLogin extends Component {
} }
} }
const FormikConfig = {
mapPropsToValues: () => ({
tel: '',
veriCode: ''
}),
handleSubmit(values, {setError}) {
console.log(values)
},
validateOnChange: false,
validate: (values) => {
let errors = {}
if (!/^1[3-9](\d{9})$/.test(values.tel)) {
errors.tel = '手机号不正确'
}
return errors
}
}
export default WechatLogin export default withFormik(FormikConfig)(WechatLogin)
\ No newline at end of file \ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
height: 100%; height: 100%;
display: flex; display: flex;
flex-flow: column; flex-flow: column;
flex: 1 1 auto;
.login-info { .login-info {
padding: 0 38px; padding: 0 38px;
......
import React from 'react'; import React from 'react';
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom'; import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import Menu from './menu';
import Index from './components/Index'; import Index from './components/Index';
import Classify from './components/classify'; import Classify from './components/classify';
import Study from './components/study'; import Study from './components/study';
...@@ -14,12 +13,13 @@ import Detail from './components/detail/index' ...@@ -14,12 +13,13 @@ import Detail from './components/detail/index'
import Examination from './components/examination' import Examination from './components/examination'
import ExchangeCoupons from './components/coupons/exchange-coupons' import ExchangeCoupons from './components/coupons/exchange-coupons'
import UseCoupon from './components/coupons/use-coupons' import UseCoupon from './components/coupons/use-coupons'
import OrderInfo from './components/order/orderinfo'; // import OrderInfo from './components/order/orderinfo';
import ShopCard from './components/shopCard/index'; import ShopCard from './components/shopCard/index';
import BargainMiddlePage from './components/bargainMiddlePage'; import BargainMiddlePage from './components/bargainMiddlePage';
import Passport from './components/passport'
const router = (props) => ( const router = () => (
<Router> <Router>
<Switch> <Switch>
<Route exact path="/" component={Index}></Route> <Route exact path="/" component={Index}></Route>
...@@ -35,11 +35,11 @@ const router = (props) => ( ...@@ -35,11 +35,11 @@ const router = (props) => (
<Route path='/examination' component={Examination}></Route> <Route path='/examination' component={Examination}></Route>
<Route path='/exchange-coupons' component={ExchangeCoupons}></Route> <Route path='/exchange-coupons' component={ExchangeCoupons}></Route>
<Route path='/use-coupon' component={UseCoupon}></Route> <Route path='/use-coupon' component={UseCoupon}></Route>
<Route path='/orderinfo' component={OrderInfo}></Route> {/*<Route path='/orderinfo' component={OrderInfo}></Route>*/}
<Route path='/shopcard' component={ShopCard}></Route> <Route path='/shopcard' component={ShopCard}></Route>
<Route path='/bargain-middle-page' component={BargainMiddlePage}></Route> <Route path='/bargain-middle-page' component={BargainMiddlePage}></Route>
<Route path='/passport' component={Passport}></Route>
</Switch> </Switch>
{/*<Menu/>*/}
</Router> </Router>
) )
......
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