index.js 2.95 KB
Newer Older
zhanghaozhe committed
1
import React, { Component } from 'react'
zhanghaozhe committed
2
import { Route, Switch, Redirect } from 'react-router-dom'
zhanghaozhe committed
3 4

import './passport.scss'
zhanghaozhe committed
5
import { WithFullSize } from '@/HOCs'
zhanghaozhe committed
6
import Login from './login'
zhanghaozhe committed
7
import AccountLogin from './accountLogin'
zhanghaozhe committed
8 9 10
import ForgotPassword from './forgotPassword'
import SetPassword from './setPassword'
import BindingTel from './bindingTel'
zhanghaozhe committed
11 12
import { connect } from "react-redux";
import { compose } from "redux";
zhanghaozhe committed
13 14 15 16 17 18 19 20

import account from './account.png'
import qq from './qq.png'
import sina from './sina.png'
import wechat from './wechat.png'


class Passport extends Component {
zhanghaozhe committed
21

zhanghaozhe committed
22
    redirect_url = location.protocol + '//' + location.hostname
zhanghaozhe committed
23

zhanghaozhe committed
24 25 26 27 28 29 30 31 32 33
    constructor(props) {
        super(props);
        this.state = {
            loginWays: [
                {
                    logo: account,
                    text: '账号登录'
                },
                {
                    logo: wechat,
zhanghaozhe committed
34 35
                    text: '微信',
                    url: 'https://www.baidu.com'
zhanghaozhe committed
36 37 38
                },
                {
                    logo: qq,
zhanghaozhe committed
39
                    text: 'QQ',
zhanghaozhe committed
40
                    url: `${API["passport-api"]}/mob/qqlogin?redirect_url=${location.href}`
zhanghaozhe committed
41 42 43
                },
                {
                    logo: sina,
zhanghaozhe committed
44
                    text: '新浪',
zhanghaozhe committed
45
                    url: `${API['passport-api']}/mob/sinalogin?redirect_url=${this.redirect_url}`
zhanghaozhe committed
46 47 48 49 50
                },
            ]
        }
    }

zhanghaozhe committed
51 52 53 54 55 56 57 58 59 60 61 62 63

    componentDidMount() {
        this.routeWhenUserLoggedIn()

    }

    componentDidUpdate() {
        this.routeWhenUserLoggedIn()
    }


    routeWhenUserLoggedIn = () => {
        let {history} = this.props
64 65
        let {data} = this.props.user
        if (data && Object.values(data).filter(item => !!item).length) {
zhanghaozhe committed
66
            history.action === 'POP' && history.length <= 3 ? history.push('/') : history.go(-1)
zhanghaozhe committed
67 68 69 70
        }
    }


zhanghaozhe committed
71
    render() {
FE committed
72
        console.log(this.props);
zhanghaozhe committed
73
        let {match, location} = this.props
zhanghaozhe committed
74 75 76
        return (
            <div className="passport">
                <Switch>
zhanghaozhe committed
77 78
                    <Redirect exact
                              from={'/passport'}
zhanghaozhe committed
79
                              to={{...location, ...{pathname: '/passport/login'}}}
zhanghaozhe committed
80
                    />
zhanghaozhe committed
81
                    <Route path={match.url + '/login'}
82 83 84
                           render={props => {
                               return <Login {...props} loginWays={this.state.loginWays}/>
                           }}/>
zhanghaozhe committed
85
                    <Route path={match.url + '/account-login'} component={AccountLogin}/>
zhanghaozhe committed
86 87 88
                    <Route path={match.url + '/forgot-password'} component={ForgotPassword}/>
                    <Route path={match.url + '/set-password'} component={SetPassword}/>
                    <Route path={match.url + '/binding-tel'} component={BindingTel}/>
zhanghaozhe committed
89 90 91 92 93 94 95
                </Switch>
            </div>
        )
    }
}


96 97 98 99 100 101 102
export default compose(
    connect(
        state => ({user: state.user}),
        null
    ),
    WithFullSize
)(Passport)