From 8520e5567af1c2665660d9d3ce17b7c8592f7ec8 Mon Sep 17 00:00:00 2001 From: yi-ge Date: Thu, 23 Jul 2020 14:28:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BE=AE=E5=8D=9A=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/auth.vue | 25 ++++++++++++++++++++++++- pages/post/_id.vue | 2 ++ 2 files changed, 26 insertions(+), 1 deletion(-) 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',