From 29c226e980b9a8281545da261beed36100d4bcdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E9=87=91=E8=BE=BE?= Date: Thu, 29 Jun 2017 11:57:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=BE=AE=E4=BF=A1=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E3=80=81=E5=AF=BC=E5=85=A5=E5=AE=A2=E6=88=B7=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/webpack.base.conf.js | 2 +- src/index.js | 2 +- src/wechat-auth.js | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/build/webpack.base.conf.js b/build/webpack.base.conf.js index e85fcf9..15ea5fc 100644 --- a/build/webpack.base.conf.js +++ b/build/webpack.base.conf.js @@ -9,7 +9,7 @@ function resolve (dir) { module.exports = { entry: { - 'vue-wechat-auth': './src/index.js' + 'vue-wechat-auth': './src/common.js' }, output: { path: config.build.assetsRoot, diff --git a/src/index.js b/src/index.js index c728316..8a4c01a 100644 --- a/src/index.js +++ b/src/index.js @@ -27,7 +27,7 @@ export default { let authCode = weChatAuth.getAuthCode() if ((!to.meta || !to.meta.auth) && !authCode) return true if (!authCode && !weChatAuth.getAccessToken()) { - weChatAuth.openAuthPage(encodeURIComponent(window.location.href)) + weChatAuth.openAuthPage(window.location.href) return false } else if (authCode && !weChatAuth.getAccessToken()) { weChatAuth.getCodeCallback(next) diff --git a/src/wechat-auth.js b/src/wechat-auth.js index 4c4e4ae..2a5ca24 100644 --- a/src/wechat-auth.js +++ b/src/wechat-auth.js @@ -17,7 +17,10 @@ class WeChatAuth { this.config = Object.assign(defaultConfig, config) } - openAuthPage (redirectUri = encodeURIComponent(window.location.href)) { + openAuthPage (redirectUri = window.location.href) { + let redirectUriArr = redirectUri.split('#') + window.sessionStorage.setItem('redirect_path', redirectUriArr[1]) + redirectUri = encodeURIComponent(redirectUriArr[0]) this.removeAccessToken() this.removeAuthCode() let authPageBaseUri = 'https://open.weixin.qq.com/connect/oauth2/authorize' @@ -102,7 +105,7 @@ class WeChatAuth { } getCodeCallback (next) { - return this.config.getCodeCallback(this.getAuthCode(), this.next(next)) + return this.config.getCodeCallback(this.getAuthCode(), this.next(next), window.sessionStorage.getItem('redirect_path')) } }