|
|
@@ -36,6 +36,7 @@
|
|
|
<script>
|
|
|
import { mapActions } from 'vuex'
|
|
|
import { wechatAuth, wechatRegister } from '@/api/wechat'
|
|
|
+import Cookies from 'js-cookie'
|
|
|
|
|
|
export default {
|
|
|
name: 'WechatAuth',
|
|
|
@@ -51,11 +52,17 @@ export default {
|
|
|
computed: {
|
|
|
// 微信授权配置
|
|
|
wechatConfig() {
|
|
|
+ // 直接返回对象,不需要再返回函数
|
|
|
+ const redirectUri = this.$route.query.url ? decodeURIComponent(this.$route.query.url) : null
|
|
|
+ console.log('redirectUri from query:', redirectUri)
|
|
|
+ if (redirectUri && redirectUri !== 'undefined') {
|
|
|
+ Cookies.set('redirectUri', redirectUri)
|
|
|
+ }
|
|
|
return {
|
|
|
appId: 'wx2d69589899b7ecd6',
|
|
|
// appId: 'wx3a8dd28881c2c41f',
|
|
|
scope: 'snsapi_userinfo', // snsapi_base 或 snsapi_userinfo
|
|
|
- redirectUri: encodeURIComponent(window.location.origin + '/wechat-auth'),
|
|
|
+ redirectUri: encodeURIComponent(window.location.origin + '/login'),
|
|
|
state: 'wechat_auth'
|
|
|
}
|
|
|
}
|
|
|
@@ -121,13 +128,14 @@ export default {
|
|
|
this.authStatus = 'success'
|
|
|
const res = await wechatRegister({
|
|
|
username: result.userInfo.nickname,
|
|
|
- mail: result.openid + '@wechat.com'
|
|
|
+ mail: result.openid + '@wechat.com',
|
|
|
+ openid: result.openid + '-wechat'
|
|
|
})
|
|
|
console.log(res)
|
|
|
|
|
|
// console.log(res)
|
|
|
const loginData = JSON.stringify({
|
|
|
- openid: result.openid,
|
|
|
+ openid: result.openid + '-wechat',
|
|
|
edu: true
|
|
|
})
|
|
|
const myHeaders = new Headers()
|
|
|
@@ -142,13 +150,25 @@ export default {
|
|
|
|
|
|
fetch('https://beta.api.cocorobo.cn/api/user', requestOptionsLogin)
|
|
|
.then(response => response.text())
|
|
|
- .then(() => {
|
|
|
- this.$router.replace('/login')
|
|
|
+ .then(async() => {
|
|
|
+ // this.$router.replace('/login')
|
|
|
+ await this.login()
|
|
|
+ let redirect_uri = Cookies.get('redirectUri')
|
|
|
+ if (!redirect_uri || redirect_uri === 'undefined') {
|
|
|
+ redirect_uri = ''
|
|
|
+ }
|
|
|
+ console.log(redirect_uri)
|
|
|
+ if (redirect_uri) {
|
|
|
+ Cookies.remove('redirectUri')
|
|
|
+ window.location.href = redirect_uri
|
|
|
+ } else {
|
|
|
+ this.$router.replace('/appStoreCopy')
|
|
|
+ }
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.log('error', error)
|
|
|
setTimeout(() => {
|
|
|
- this.$router.replace('/login')
|
|
|
+ this.$router.replace('/login2')
|
|
|
}, 2000)
|
|
|
})
|
|
|
} else {
|
|
|
@@ -161,7 +181,7 @@ export default {
|
|
|
|
|
|
// 如果授权失败,跳转到登录页面
|
|
|
setTimeout(() => {
|
|
|
- this.$router.replace('/login')
|
|
|
+ this.$router.replace('/login2')
|
|
|
}, 2000)
|
|
|
}
|
|
|
},
|
|
|
@@ -237,8 +257,9 @@ export default {
|
|
|
mounted() {
|
|
|
// 检查是否在微信浏览器中
|
|
|
if (!this.isWechatBrowser()) {
|
|
|
- this.authStatus = 'error'
|
|
|
- this.errorMessage = '请在微信中打开此页面'
|
|
|
+ // this.authStatus = 'error'
|
|
|
+ // this.errorMessage = '请在微信中打开此页面'
|
|
|
+ this.$router.replace('/login2')
|
|
|
return
|
|
|
}
|
|
|
|