diff --git a/pages/auth.vue b/pages/auth.vue index afdcb60..876cf3e 100644 --- a/pages/auth.vue +++ b/pages/auth.vue @@ -13,6 +13,7 @@ export default { async mounted () { const code = this.$route.query.code const type = this.$route.query.type + const state = this.$route.query.state.split('-') if (!code) { this.notice = '
非法访问,缺少授权参数"code"。
返回首页'; this.$finishLoad(); return }
@@ -32,7 +33,29 @@ export default {
try {
window.localStorage.visitorToken = data.result.token
window.localStorage.visitorInfo = JSON.stringify(data.result.visitorInfo)
- window.location.href = 'https://www.wyr.me/post/' + this.$route.query.state.split('-')[1] + '?hash=comment'
+ window.location.href = 'https://www.wyr.me/post/' + state[1] + '?hash=comment'
+ } catch (_) { }
+ }
+
+ return
+ }
+
+ if (state[0] === 'weibo') {
+ const { data } = await this.$axios.post(`${process.env.baseURL}/visitor/user/weibo`, {
+ code
+ })
+
+ if (data.status !== 1) {
+ this.$toasted.show('微博登录失败,请重试或换用其它登录方式。', {
+ position: 'top-center',
+ duration: 5000
+ })
+ return
+ } else {
+ try {
+ window.localStorage.visitorToken = data.result.token
+ window.localStorage.visitorInfo = JSON.stringify(data.result.visitorInfo)
+ window.location.href = 'https://www.wyr.me/post/' + state[1] + '?hash=comment'
} catch (_) { }
}
diff --git a/pages/post/_id.vue b/pages/post/_id.vue
index b340650..4854d3a 100644
--- a/pages/post/_id.vue
+++ b/pages/post/_id.vue
@@ -702,6 +702,8 @@ export default {
duration: 5000
})
}
+ } else if (type === 'weibo') {
+ window.location.href = 'https://api.weibo.com/oauth2/authorize?client_id=4159322735&redirect_uri=https://wyr.me/auth&response_type=code&state=weibo-' + this.postID
} else {
this.$toasted.show('敬请期待', {
position: 'top-center',