Commit 7b808cbe by zhanghaozhe

微信登录redirect_url

parent cbe294db
......@@ -23,6 +23,7 @@ import './assets/font/iconfont.css';
class App extends Component {
previousLocation = this.props.location
componentDidMount() {
//平台信息
......@@ -34,6 +35,13 @@ class App extends Component {
this.props.setCurrentUser(this.transformUser(res))
})
const {history} = this.props
history.listen(location => {
if (location.pathname.startsWith('/passport')) {
location.state = {from: this.previousLocation};
}
})
//微信
let code = getParam('code')
......@@ -46,7 +54,6 @@ class App extends Component {
if (data.errno == 200) {
if (data.data['is_bind_mobile']) {
window.location.assign(data.data.url)
} else {
let user = this.transformWxUser(res)
let {role, uid, token} = data.data
......@@ -67,6 +74,13 @@ class App extends Component {
}
componentDidUpdate() {
const {location} = this.props
this.previousLocation = location.pathname.startsWith('/passport') ?
this.previousLocation.pathname === '/' ? location : this.previousLocation : location
}
transformUser = res => {
let payload
if (res.data.code === 200) {
......
......@@ -77,7 +77,7 @@ const formikConfig = {
}).then(res => {
if (!res.hasError) {
let {from} = props.location.state || {from: {pathname: '/', search: ''}}
history.replace({pathname: from.pathname, search: from.search})
history.replace({pathname: from.pathname, search: from.search || ''})
} else {
Toast.info(res.msg, 2, null, false)
}
......
......@@ -19,10 +19,13 @@ import wechat from './wechat.png'
class Passport extends Component {
redirect_url = location.protocol + '//' + location.hostname
redirectURL = '/'
constructor(props) {
super(props);
const {location: {state: {from}}} = props
this.redirectURL = window.location.origin + from.pathname + from.search + from.hash
// console.log(props.location);
this.state = {
loginWays: [
{
......@@ -32,17 +35,17 @@ class Passport extends Component {
{
logo: wechat,
text: '微信',
url: 'https://www.baidu.com'
url: ''
},
{
logo: qq,
text: 'QQ',
url: `${API["passport-api"]}/mob/qqlogin?redirect_url=https://m.julyedu.com`
url: `${API["passport-api"]}/mob/qqlogin?redirect_url=${this.redirectURL}`
},
{
logo: sina,
text: '新浪',
url: `${API['passport-api']}/mob/sinalogin?redirect_url=${this.redirect_url}`
url: `${API['passport-api']}/mob/sinalogin?redirect_url=${this.redirectURL}`
},
]
}
......@@ -51,11 +54,12 @@ class Passport extends Component {
componentDidMount() {
this.routeWhenUserLoggedIn()
}
componentDidUpdate() {
this.routeWhenUserLoggedIn()
// console.log(this.props.location);
}
......
......@@ -32,9 +32,9 @@ class Login extends Component {
history.push('/passport/account-login', location.state)
break;
case '微信':
let {from} = location.state || {from: {pathname: '/'}}
let {from} = location.state || {from: {pathname: '/', search: '', hash: ''}}
const redirectURI = window.location.origin + from.pathname
const redirectURI = window.location.origin + from.pathname + from.search + from.hash
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;
......
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