Commit 413a80c8 by zhanghaozhe

微信登录

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