Commit 413a80c8 by zhanghaozhe

微信登录

parent 9b5207b6
......@@ -3,6 +3,8 @@ import Routes from './router'
import cookie from 'js-cookie'
import { connect } from "react-redux";
import { setCurrentUser } from "@/store/userAction";
import { withRouter } from 'react-router-dom'
import { compose } from 'redux'
//拦截ajax请求,返回mock数据
......@@ -15,12 +17,15 @@ import './assets/css/index.scss';
// iconfont
import './assets/font/iconfont.css';
import { api, http } from "@/utils";
import { api, getParam, http, isLogin } from "@/utils";
import { Toast } from "antd-mobile";
class App extends Component {
componentDidMount() {
console.log(this.props.history);
//平台信息
cookie.set('plat', '5')
......@@ -29,6 +34,43 @@ class App extends Component {
})
let code = getParam('code')
let {history, state, location} = this.props
if (code) {
http.get(`${api['base-api']}/m/wx_loginInfo/code/${code}`)
.then(res => {
let data = res.data
console.log(res)
if (data.errno == 200) {
if (data.data['is_bind_mobile']) {
window.location.assign(data.data.url)
} else {
console.log(this.props.location)
}
} else {
Toast.info(data.msg)
}
})
}
/*else {
if (isLogin) {
console.log(location.pathname);
// history.replace(location.pathname)
} else {
console.log(state);
history.replace('/passport', {...state})
}
}*/
}
transformUser = res => {
......@@ -71,7 +113,10 @@ class App extends Component {
}
}
export default connect(
null,
{setCurrentUser}
export default compose(
connect(
null,
{setCurrentUser}
),
withRouter
)(App)
\ No newline at end of file
......@@ -122,8 +122,14 @@ const formikConfig = {
if (data.errno == 200) {
if (data.data['is_set_pwd']) {
props.setCurrentUser({
hasError: false,
data: {
uid: data.data.uid
},
msg: data.data.msg
})
props.history.replace(`/passport/set-password`)
}else {
location.assign(data.data['jump_url'])
......
......@@ -128,7 +128,7 @@ const formikConfig = {
code: values.veriCode
}).then(res => {
if (res.data.errno == 0) {
props.history.push('/passport/set-password')
props.history.push('/passport/set-password', {from: props.location})
} else {
Toast.info(res.data.msg)
}
......
......@@ -23,11 +23,6 @@ class Passport extends Component {
redirect_url = location.protocol + '//' + location.hostname
componentDidMount() {
console.log(this.props.location);
}
constructor(props) {
super(props);
this.state = {
......
......@@ -15,12 +15,17 @@ import { Toast } from 'antd-mobile';
import { validateTel } from "@/utils";
class WechatLogin extends Component {
class Login extends Component {
state = {
validate: null,
captchaInstance: null
}
componentDidMount() {
console.log(this.props);
}
loginWaysClick = method => {
const {history, loginWays, location} = this.props
......@@ -34,6 +39,8 @@ class WechatLogin extends Component {
let {from} = location.state || {from: {pathname: '/'}}
const redirectURI = window.location.protocol + '//' + window.location.hostname + from.pathname
alert(redirectURI)
window.location.assign(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx23dac6775ac82877&redirect_uri=${encodeURIComponent(redirectURI)}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`)
break;
default:
......@@ -153,4 +160,4 @@ export default compose(
{quickLogin}
),
withFormik(FormikConfig),
)(WechatLogin)
\ No newline at end of file
)(Login)
\ No newline at end of file
......@@ -11,12 +11,19 @@ import { Toast } from "antd-mobile";
import { encrypt } from "@/components/passport/encryption";
import { Link } from "react-router-dom";
import { isEmpty } from "lodash";
import { connect } from "react-redux";
class SetPassword extends Component {
componentDidMount() {
console.log(this.props.location);
}
render() {
const {values, errors} = this.props
let {values, errors, location} = this.props
let {from} = location.state || {from: {pathname: '/'}}
return (
<>
<HeaderBar arrow={true} title={'设置密码'}/>
......@@ -49,7 +56,8 @@ class SetPassword extends Component {
同意<span>《七月在线用户使用协议》</span>
</label>
</Form>
<div className="skip">
<div className="skip"
style={{display: from && from.pathname.includes('forgot-password') ? 'none' : 'block'}}>
<Link replace to='/passport/account-login'>跳过</Link>
</div>
</div>
......@@ -67,24 +75,12 @@ const formikConfig = {
},
handleSubmit: (values, {props}) => {
let key = sessionStorage.getItem('r_type') === 'email' ? 'email' : 'tel'
let encrypted = encrypt(values.password)
http.post(`${api['passport-api']}/account/up_pass${key === 'tel' && '_by_phone' || ''}`, {
[key]: sessionStorage.getItem(key),
pass: encrypted,
re_pass: encrypted
})
.then(res => {
if (res.data.errno == 0) {
Toast.info('密码设置成功')
setTimeout(function () {
props.history.replace('/passport')
}, 1000)
} else {
Toast.info(res.data.msg, 2, null, false)
}
})
let {from} = props.location.state || {from: {pathname: '/'}}
if (from.pathname.includes('forgot-password')) {
forgotPasswordReset(values, props);
} else {
bindMobileSetPassword(values, props)
}
},
validateOnChange: false,
......@@ -103,6 +99,53 @@ const formikConfig = {
}
}
function forgotPasswordReset(values, props) {
let key = sessionStorage.getItem('r_type') === 'email' ? 'email' : 'tel'
http.post(`${api['passport-api']}/account/up_pass_by_${key === 'email' ? 'email' : 'phone'}`, {
[key]: sessionStorage.getItem(key),
password: encrypt(values.password)
})
.then(res => {
if (res.data.errno == 200) {
Toast.info('密码设置成功')
setTimeout(function () {
props.history.replace('/passport/account-login')
}, 1000)
} else {
Toast.info(res.data.msg, 2, null, false)
}
})
}
function bindMobileSetPassword(values, props) {
http.post(`${api['passport-api']}/bind_mobile/set_pwd_new`, {
uid: props.user.data.uid,
password: encrypt(values.password)
})
.then(res => {
if (res.data.errno == 200) {
Toast.info('密码设置成功')
let from = getFrom(props.location)
setTimeout(function () {
props.history.replace(from.pathname)
}, 1000)
} else {
Toast.info(res.data.msg, 2, null, false)
}
})
}
function getFrom(location) {
return {from} = location.state || {from: {pathname: '/'}}
}
export default compose(
connect(
state => ({user: state.user}),
null
),
withFormik(formikConfig)
)(SetPassword);
\ No newline at end of file
......@@ -2,6 +2,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, applyMiddleware, compose } from 'redux'
import { Provider } from 'react-redux'
import { BrowserRouter as Router } from 'react-router-dom'
import thunk from 'redux-thunk'
import logger from 'redux-logger'
import rootReducers from './store'
......@@ -20,6 +21,8 @@ const store = createStore(
ReactDOM.render(
<Provider store={store}>
<App/>
<Router>
<App/>
</Router>
</Provider>,
document.getElementById('root'));
\ No newline at end of file
import React from 'react'
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom'
import { Switch, Route } from 'react-router-dom'
import RouterConfig from './router-config'
import PrivateRoute from './privateRoute'
export default function () {
return (
<Router>
<Switch>
{RouterConfig.map((item, index) => {
let {isPrivate, ...rest} = item
if (isPrivate) {
return <PrivateRoute {...rest} key={index}/>
} else {
return (
<Route {...rest} key={index}/>
)
}
})}
</Switch>
</Router>
<Switch>
{RouterConfig.map((item, index) => {
let {isPrivate, ...rest} = item
if (isPrivate) {
return <PrivateRoute {...rest} key={index}/>
} else {
return (
<Route {...rest} key={index}/>
)
}
})}
</Switch>
)
}
\ No newline at end of file
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