You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.5 KiB

5 years ago
<template>
<div />
</template>
<script>
import {getCurrentDomain, getQueryString} from '@/utils'
export default {
name: 'Redirect',
data() {
return {}
},
created() {
// 重定向类型
let type = this.$route.params.type
if (type == 'qqlogin') {
this.qqLoginHandle()
} else if (type == 'bindqq') {
this.bindQqHandle()
}
},
methods: {
bindQqHandle() {
let code = getQueryString('code')
let state = getQueryString('state')
if (code && state) {
let reUrl = getCurrentDomain() + '/redirect/bindqq'
4 years ago
this.$api.post(`${process.env.VUE_APP_API_ROOT_TDUCK}/user/bind/qq`, {authorizeCode: code, redirectUri: reUrl}).then(res => {
if (res.data) {
this.msgSuccess('绑定成功')
window.close()
} else {
this.msgError('绑定失败,该qq已经绑定其他账号')
}
})
}
5 years ago
},
qqLoginHandle() {
// qq 登录重定向
let code = getQueryString('code')
let state = getQueryString('state')
if (code && state) {
let reUrl = getCurrentDomain() + '/redirect/qqlogin'
4 years ago
this.$api.post(`${process.env.VUE_APP_API_ROOT_TDUCK}/login/qq`, {authorizeCode: code, redirectUri: reUrl}).then(res => {
5 years ago
if (res.data) {
this.msgSuccess('登录成功')
this.$store.dispatch('user/login', res.data).then(() => {
// 重置状态
this.$store.dispatch('global/loginExpired', false).then(() => {
5 years ago
})
5 years ago
// 登录成功后路由跳回
if (this.$route.query.redirect) {
this.$router.replace({
path: this.$route.query.redirect
})
5 years ago
} else {
5 years ago
if (window.history.length <= 1) {
this.$router.push({path: '/home'})
} else {
this.$router.push({path: '/home'})
}
5 years ago
}
5 years ago
})
}
})
}
5 years ago
}
}
5 years ago
}
</script>